Skip to content

Commit d483143

Browse files
author
Lionel Laské
committed
Merge branch 'pr/1680' into dev
2 parents 6445b2c + c243aea commit d483143

File tree

2 files changed

+19
-26
lines changed

2 files changed

+19
-26
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## [Unreleased]
88
### Added
99
- 3D Volume activity
10-
- Launch activity directly from url of CLI
10+
- Launch activity directly from url or CLI
1111

1212
### Changed
1313
- Upgrade to Cordova 12
@@ -36,6 +36,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3636
- Listview Popup increasing page length and opening downwards for lower icons #1674
3737
- Vertical bar are broken in Chart/Gears activities on Windows #1646
3838
- In the activity of food chain, the picture of frog shows incomplete #1191
39+
- Unusual Draw in Chess Activity #1678
3940

4041
## [1.8.0] - 2024-04-10
4142
### Added

activities/Chess.activity/js/chessGame.js

+17-25
Original file line numberDiff line numberDiff line change
@@ -391,18 +391,10 @@ var ChessGame = {
391391
var start_time = Date.now();
392392
var possibleMove = this.state.findmove(this.level);
393393
var delta = Date.now() - start_time;
394-
// game over
395-
if (possibleMove.length === 0) {
396-
this.game_won = true;
397-
return;
398-
}
399-
if (1 / possibleMove[2] == 1 / this.state.stalemate_scores[this.state.to_play]) {
400-
this.game_draw = true;
401-
return;
402-
}
403394
var move = this.state.move(possibleMove[0], possibleMove[1]);
404395

405396
if (!(move.flags & (1 << 0))) {
397+
// this is where the king can't move or any valid move aren't available, usually happens on stalemate and checkmate
406398
var depth = this.level;
407399
depth++;
408400
//find at higher depths until it runs out of time
@@ -414,28 +406,26 @@ var ChessGame = {
414406
delta = Date.now() - start_time;
415407
}
416408
}
417-
if (possibleMove.length === 0) {
418-
this.game_won = true;
419-
return;
420-
}
421-
if (possibleMove[2] == this.state.stalemate_scores[this.state.to_play]) {
422-
this.game_draw = true;
423-
return;
424-
}
425-
move = this.state.move(possibleMove[0], possibleMove[1]);
426-
if (!(move.flags & (1 << 0))) {
409+
if (possibleMove.length === 0 && flags & 2) {
427410
this.game_won = true;
428411
return;
429412
}
413+
move = this.state.move(possibleMove[0], possibleMove[1]);
430414
}
431415

432-
if (move.flags & (1 << 1) && move.flags & (1 << 2)) {
433-
this.game_lost = true;
434416

435-
} else if (move.flags & (1 << 1) && !(move.flags & (1 << 2))) {
417+
if ( (move.flags & 1<<0 ) && (move.flags & 1<<1) && (move.flags & 1<<2) ) {
418+
this.board.position(p4_state2fen(this.state, true));
419+
this.updateMoves();
420+
this.game_lost = true;
421+
return;
422+
} else if (move.flags & (1<<1) && !(move.flags & (1<<2))) {
436423
this.game_check = true;
437-
} else if ((!(move.flags & (1 << 1)) && move.flags & (1 << 2)) || move.flags & (1 << 6)) {
424+
} else if (!(move.flags& 1<<1) && ( ((move.flags & 1<<0) && move.flags & 1<<2) || move.flags & (1<<6))) {
425+
this.board.position(p4_state2fen(this.state, true));
426+
this.updateMoves();
438427
this.game_draw = true;
428+
return;
439429
} else {
440430
this.game_check = false;
441431
}
@@ -461,10 +451,12 @@ var ChessGame = {
461451
// illegal move
462452
if (move.flags === 0) return 'snapback';
463453

464-
if (move.flags === 7) {
454+
if (move.flags === 7 || move.flags === 15 || move.flags === 23 || move.flags === 39) {
465455
this.game_won = true;
466-
} else if ((!(move.flags & (1 << 1)) && move.flags & (1 << 2)) || move.flags & (1 << 6)) {
456+
return;
457+
} else if ( (!(move.flags & 1<<1 )) && (((move.flags & 1<<0) && (move.flags & 1<<2) ) || move.flags & (1<<6))) {
467458
this.game_draw = true;
459+
return;
468460
} else {
469461
this.game_check = false;
470462
}

0 commit comments

Comments
 (0)