Skip to content

Commit

Permalink
Fix ending_bot crash (#411)
Browse files Browse the repository at this point in the history
Closes #410
  • Loading branch information
raylu authored Oct 30, 2023
1 parent 7b063ee commit 58310d2
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,17 @@ export class Game extends EventEmitter<Events> {
decodeMoves(move.move, this.state.width, this.state.height)[0],
this.state.width,
this.state.height,
this.my_color === "black" ? "white" : "black",
"black", // we are white so we are recording black's moves
),
);
}
if (this.ending_bot) {
ignore_promise(
this.ending_bot?.sendMove(
this.ending_bot.sendMove(
decodeMoves(move.move, this.state.width, this.state.height)[0],
this.state.width,
this.state.height,
this.my_color === "black" ? "white" : "black",
"black",
),
);
}
Expand All @@ -301,6 +303,7 @@ export class Game extends EventEmitter<Events> {
}
}
} else {
const opponent_color = this.my_color === "black" ? "white" : "black";
if (move.move_number % 2 === this.opponent_evenodd) {
// We just got a move from the opponent, so we can move immediately.
//
Expand All @@ -310,15 +313,17 @@ export class Game extends EventEmitter<Events> {
decodeMoves(move.move, this.state.width, this.state.height)[0],
this.state.width,
this.state.height,
this.my_color === "black" ? "white" : "black",
opponent_color,
),
);
}
if (this.ending_bot) {
ignore_promise(
this.ending_bot?.sendMove(
this.ending_bot.sendMove(
decodeMoves(move.move, this.state.width, this.state.height)[0],
this.state.width,
this.state.height,
this.my_color === "black" ? "white" : "black",
opponent_color,
),
);
}
Expand Down

0 comments on commit 58310d2

Please sign in to comment.