From 0135f08c939ebb4da957e3f2bf03cdeb68e76b3b Mon Sep 17 00:00:00 2001 From: MostlyK <135974627+MostlyKIGuess@users.noreply.github.com> Date: Thu, 19 Dec 2024 14:23:05 +0530 Subject: [PATCH 1/7] [+]Chess Game Fix --- activities/Chess.activity/js/chessGame.js | 39 ++++++++++++++--------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/activities/Chess.activity/js/chessGame.js b/activities/Chess.activity/js/chessGame.js index 181ab2690..ae6214055 100644 --- a/activities/Chess.activity/js/chessGame.js +++ b/activities/Chess.activity/js/chessGame.js @@ -391,18 +391,24 @@ var ChessGame = { var start_time = Date.now(); var possibleMove = this.state.findmove(this.level); var delta = Date.now() - start_time; + + // console.log(`Random Move: ${possibleMove}, Delta: ${delta}`); + // game over - if (possibleMove.length === 0) { + if (possibleMove.length === 0 && (move.flags === 7 || move.flags === 15 || move.flags === 23 || move.flags === 39)) { + // console.log("Game won by computer"); this.game_won = true; return; } - if (1 / possibleMove[2] == 1 / this.state.stalemate_scores[this.state.to_play]) { + + if (possibleMove.length === 0 && (move.flags === 5 || move.flags === 13 || move.flags === 21 || move.flags === 37 || move.flags === 64)) { + // console.log("Match draw due to stalemate"); this.game_draw = true; return; } var move = this.state.move(possibleMove[0], possibleMove[1]); - if (!(move.flags & (1 << 0))) { + if (!(move.flags & (1))) { var depth = this.level; depth++; //find at higher depths until it runs out of time @@ -414,27 +420,28 @@ var ChessGame = { delta = Date.now() - start_time; } } - if (possibleMove.length === 0) { + if (possibleMove.length === 0 && flags & 2) { this.game_won = true; return; } - if (possibleMove[2] == this.state.stalemate_scores[this.state.to_play]) { - this.game_draw = true; - return; - } + // if (possibleMove[2] === this.state.stalemate_scores[this.state.to_play]) { + // console.log("Match draw due to stalemate proper"); + // this.game_draw = true; + // return; + // } move = this.state.move(possibleMove[0], possibleMove[1]); - if (!(move.flags & (1 << 0))) { + if (!(move.flags & (1))) { this.game_won = true; return; } } - if (move.flags & (1 << 1) && move.flags & (1 << 2)) { + if (move.flags & (2) && move.flags & (4)) { this.game_lost = true; - } else if (move.flags & (1 << 1) && !(move.flags & (1 << 2))) { + } else if (move.flags & (2) && !(move.flags & (4))) { this.game_check = true; - } else if ((!(move.flags & (1 << 1)) && move.flags & (1 << 2)) || move.flags & (1 << 6)) { + } else if ((!(move.flags & (2)) && move.flags & (4)) || move.flags & (64)) { this.game_draw = true; } else { this.game_check = false; @@ -458,18 +465,20 @@ var ChessGame = { var move = this.state.move(source, target); + // console.log(`Move: ${source}-${target}, Flags: ${move.flags}`); // illegal move if (move.flags === 0) return 'snapback'; - if (move.flags === 7) { + if (move.flags === 7 || move.flags === 15 || move.flags === 23 || move.flags === 39) { + // console.log("Game won by player"); this.game_won = true; - } else if ((!(move.flags & (1 << 1)) && move.flags & (1 << 2)) || move.flags & (1 << 6)) { + } else if ( (!(move.flags & 2 )) && (move.flags & 4 ) || move.flags & (64)) { this.game_draw = true; } else { this.game_check = false; } - if (move.flags & (1 << 1) && !(move.flags & (1 << 2))) { + if (move.flags & (2) && !(move.flags & (4))) { this.other_check = true; } else { this.other_check = false; From f25cd8d9c997a48464845e73e5b04f8836990101 Mon Sep 17 00:00:00 2001 From: MostlyK <135974627+MostlyKIGuess@users.noreply.github.com> Date: Thu, 19 Dec 2024 23:43:37 +0530 Subject: [PATCH 2/7] [+]Chess Game Fix --- activities/Chess.activity/js/chessGame.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/activities/Chess.activity/js/chessGame.js b/activities/Chess.activity/js/chessGame.js index ae6214055..3ba2cf8e2 100644 --- a/activities/Chess.activity/js/chessGame.js +++ b/activities/Chess.activity/js/chessGame.js @@ -425,13 +425,14 @@ var ChessGame = { return; } // if (possibleMove[2] === this.state.stalemate_scores[this.state.to_play]) { - // console.log("Match draw due to stalemate proper"); + // console.log("Match draw due to stalemate proper"); // this.game_draw = true; // return; // } move = this.state.move(possibleMove[0], possibleMove[1]); - if (!(move.flags & (1))) { - this.game_won = true; + if (!(move.flags & (1)) && (move.flags & 2)) { + // console.log("Draws"); + this.game_draw = true; return; } } @@ -465,14 +466,15 @@ var ChessGame = { var move = this.state.move(source, target); - // console.log(`Move: ${source}-${target}, Flags: ${move.flags}`); + console.log(`Move: ${source}-${target}, Flags: ${move.flags}`); // illegal move if (move.flags === 0) return 'snapback'; if (move.flags === 7 || move.flags === 15 || move.flags === 23 || move.flags === 39) { - // console.log("Game won by player"); + console.log("Game won by player"); this.game_won = true; - } else if ( (!(move.flags & 2 )) && (move.flags & 4 ) || move.flags & (64)) { + } else if ( (!(move.flags & 2 )) && ((move.flags & 4 ) || move.flags & (64))) { + // console.log("Match draw due to stalemate by player"); this.game_draw = true; } else { this.game_check = false; From 6d4567c2c79217427116f6449f2d4830dad02bc0 Mon Sep 17 00:00:00 2001 From: MostlyK <135974627+MostlyKIGuess@users.noreply.github.com> Date: Thu, 19 Dec 2024 23:47:14 +0530 Subject: [PATCH 3/7] [+]Chess Game Fix --- activities/Chess.activity/js/chessGame.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/activities/Chess.activity/js/chessGame.js b/activities/Chess.activity/js/chessGame.js index 3ba2cf8e2..d9770b92b 100644 --- a/activities/Chess.activity/js/chessGame.js +++ b/activities/Chess.activity/js/chessGame.js @@ -433,6 +433,7 @@ var ChessGame = { if (!(move.flags & (1)) && (move.flags & 2)) { // console.log("Draws"); this.game_draw = true; + return; } } @@ -466,7 +467,7 @@ var ChessGame = { var move = this.state.move(source, target); - console.log(`Move: ${source}-${target}, Flags: ${move.flags}`); + // console.log(`Move: ${source}-${target}, Flags: ${move.flags}`); // illegal move if (move.flags === 0) return 'snapback'; From e39284510625971094305dfe3bf99f2e4ea8e41d Mon Sep 17 00:00:00 2001 From: MostlyK <135974627+MostlyKIGuess@users.noreply.github.com> Date: Thu, 19 Dec 2024 23:58:04 +0530 Subject: [PATCH 4/7] [+]Chess Game Fix --- activities/Chess.activity/js/chessGame.js | 1 + 1 file changed, 1 insertion(+) diff --git a/activities/Chess.activity/js/chessGame.js b/activities/Chess.activity/js/chessGame.js index d9770b92b..7202c934a 100644 --- a/activities/Chess.activity/js/chessGame.js +++ b/activities/Chess.activity/js/chessGame.js @@ -432,6 +432,7 @@ var ChessGame = { move = this.state.move(possibleMove[0], possibleMove[1]); if (!(move.flags & (1)) && (move.flags & 2)) { // console.log("Draws"); + // critical situation which cause the error this.game_draw = true; return; From 2fee11bfc82de95fee7acc0eb031e1225dbf7462 Mon Sep 17 00:00:00 2001 From: MostlyK <135974627+MostlyKIGuess@users.noreply.github.com> Date: Fri, 20 Dec 2024 10:52:30 +0530 Subject: [PATCH 5/7] [+]chess Logic Fix --- activities/Chess.activity/js/chessGame.js | 49 +++++++---------------- 1 file changed, 14 insertions(+), 35 deletions(-) diff --git a/activities/Chess.activity/js/chessGame.js b/activities/Chess.activity/js/chessGame.js index 7202c934a..8e6058648 100644 --- a/activities/Chess.activity/js/chessGame.js +++ b/activities/Chess.activity/js/chessGame.js @@ -391,24 +391,10 @@ var ChessGame = { var start_time = Date.now(); var possibleMove = this.state.findmove(this.level); var delta = Date.now() - start_time; - - // console.log(`Random Move: ${possibleMove}, Delta: ${delta}`); - - // game over - if (possibleMove.length === 0 && (move.flags === 7 || move.flags === 15 || move.flags === 23 || move.flags === 39)) { - // console.log("Game won by computer"); - this.game_won = true; - return; - } - - if (possibleMove.length === 0 && (move.flags === 5 || move.flags === 13 || move.flags === 21 || move.flags === 37 || move.flags === 64)) { - // console.log("Match draw due to stalemate"); - this.game_draw = true; - return; - } var move = this.state.move(possibleMove[0], possibleMove[1]); if (!(move.flags & (1))) { + // this is where the king can't move or any valid move aren't available, usually happens on stalemate and checkmate var depth = this.level; depth++; //find at higher depths until it runs out of time @@ -424,28 +410,22 @@ var ChessGame = { this.game_won = true; return; } - // if (possibleMove[2] === this.state.stalemate_scores[this.state.to_play]) { - // console.log("Match draw due to stalemate proper"); - // this.game_draw = true; - // return; - // } - move = this.state.move(possibleMove[0], possibleMove[1]); - if (!(move.flags & (1)) && (move.flags & 2)) { - // console.log("Draws"); - // critical situation which cause the error - this.game_draw = true; - - return; - } + move = this.state.move(possibleMove[0], possibleMove[1]); } - if (move.flags & (2) && move.flags & (4)) { - this.game_lost = true; + if (move.flags & 1 && move.flags & 2 && move.flags & 4) { + this.board.position(p4_state2fen(this.state, true)); + this.updateMoves(); + this.game_lost = true; + return; } else if (move.flags & (2) && !(move.flags & (4))) { this.game_check = true; - } else if ((!(move.flags & (2)) && move.flags & (4)) || move.flags & (64)) { + } else if (!(move.flags&2) && ( ((move.flags & 1) && move.flags & 4) || move.flags & (64))) { + this.board.position(p4_state2fen(this.state, true)); + this.updateMoves(); this.game_draw = true; + return; } else { this.game_check = false; } @@ -468,16 +448,15 @@ var ChessGame = { var move = this.state.move(source, target); - // console.log(`Move: ${source}-${target}, Flags: ${move.flags}`); // illegal move if (move.flags === 0) return 'snapback'; if (move.flags === 7 || move.flags === 15 || move.flags === 23 || move.flags === 39) { - console.log("Game won by player"); this.game_won = true; - } else if ( (!(move.flags & 2 )) && ((move.flags & 4 ) || move.flags & (64))) { - // console.log("Match draw due to stalemate by player"); + return; + } else if ( (!(move.flags & 2 )) && (((move.flags & 1) && (move.flags & 4) ) || move.flags & (64))) { this.game_draw = true; + return; } else { this.game_check = false; } From 9d61f52bdf4eb25035366e4c39514c4542c4f5ca Mon Sep 17 00:00:00 2001 From: MostlyK <135974627+MostlyKIGuess@users.noreply.github.com> Date: Sun, 22 Dec 2024 17:09:44 +0530 Subject: [PATCH 6/7] [+]Chess logic --- activities/Chess.activity/js/chessGame.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/activities/Chess.activity/js/chessGame.js b/activities/Chess.activity/js/chessGame.js index 8e6058648..3edf2c21a 100644 --- a/activities/Chess.activity/js/chessGame.js +++ b/activities/Chess.activity/js/chessGame.js @@ -414,14 +414,14 @@ var ChessGame = { } - if (move.flags & 1 && move.flags & 2 && move.flags & 4) { + if ( (move.flags & 1<<0 ) && (move.flags & 1<<1) && (move.flags & 1<<2) ) { this.board.position(p4_state2fen(this.state, true)); this.updateMoves(); this.game_lost = true; return; - } else if (move.flags & (2) && !(move.flags & (4))) { + } else if (move.flags & (1<<1) && !(move.flags & (1<<2))) { this.game_check = true; - } else if (!(move.flags&2) && ( ((move.flags & 1) && move.flags & 4) || move.flags & (64))) { + } else if (!(move.flags& 1<<1) && ( ((move.flags & 1<<0) && move.flags & 1<<2) || move.flags & (1<<6))) { this.board.position(p4_state2fen(this.state, true)); this.updateMoves(); this.game_draw = true; @@ -454,14 +454,14 @@ var ChessGame = { if (move.flags === 7 || move.flags === 15 || move.flags === 23 || move.flags === 39) { this.game_won = true; return; - } else if ( (!(move.flags & 2 )) && (((move.flags & 1) && (move.flags & 4) ) || move.flags & (64))) { + } else if ( (!(move.flags & 1<<1 )) && (((move.flags & 1<<0) && (move.flags & 1<<2) ) || move.flags & (1<<6))) { this.game_draw = true; return; } else { this.game_check = false; } - if (move.flags & (2) && !(move.flags & (4))) { + if (move.flags & (1<<1) && !(move.flags & (1<<2))) { this.other_check = true; } else { this.other_check = false; From 312f31dd3c18528e3107afe6e3fc8f5a8a2772cc Mon Sep 17 00:00:00 2001 From: MostlyK <135974627+MostlyKIGuess@users.noreply.github.com> Date: Sun, 22 Dec 2024 17:12:36 +0530 Subject: [PATCH 7/7] [+]Chess logic --- activities/Chess.activity/js/chessGame.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activities/Chess.activity/js/chessGame.js b/activities/Chess.activity/js/chessGame.js index 3edf2c21a..6781850de 100644 --- a/activities/Chess.activity/js/chessGame.js +++ b/activities/Chess.activity/js/chessGame.js @@ -393,7 +393,7 @@ var ChessGame = { var delta = Date.now() - start_time; var move = this.state.move(possibleMove[0], possibleMove[1]); - if (!(move.flags & (1))) { + if (!(move.flags & (1 << 0))) { // this is where the king can't move or any valid move aren't available, usually happens on stalemate and checkmate var depth = this.level; depth++; @@ -461,7 +461,7 @@ var ChessGame = { this.game_check = false; } - if (move.flags & (1<<1) && !(move.flags & (1<<2))) { + if (move.flags & (1 << 1) && !(move.flags & (1 << 2))) { this.other_check = true; } else { this.other_check = false;