Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[+]Chess Game Fix #1679

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 24 additions & 15 deletions activities/Chess.activity/js/chessGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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;
Expand Down