Fix handling of drops when checking moves.

This commit is contained in:
yukirij 2024-10-14 14:27:45 -07:00
parent d47bef97f0
commit 923a47cf69
3 changed files with 24 additions and 13 deletions

View File

@ -189,7 +189,9 @@ impl Game {
** Add drops to player moves.
*/
for i in 0..6 {
plays.append(&mut self.get_drops(&Piece::new(i, current_player)));
if self.pool[current_player as usize][i] > 0 {
plays.append(&mut self.get_drops(&Piece::new(i as u8, current_player)));
}
}
plays

View File

@ -315,7 +315,7 @@ GAME.Game = class {
// Search for valid board moves.
for(let piece of this.board.pieces) {
if(piece !== null && piece.player == (this.turn & 1)) {
if(piece !== null && piece.player == player) {
for(let move of this.movement_tiles(piece, piece.tile)) {
if(move.valid) { moves += 1; }
}
@ -328,14 +328,18 @@ GAME.Game = class {
// Search for valid pool placements.
for(let i = 0; i < this.pools[player].pieces.length; ++i) {
if(this.pools[player].pieces[i] > 0) {
for(let move of this.placement_tiles(i, player)) {
if(move.valid) { moves += 1; }
}
}
}
if(moves == 0) {
this.state.code = GAME.Const.State.Checkmate;
}
console.log(moves);
}
process(play) {

View File

@ -549,7 +549,7 @@ const INTERFACE = {
let background_scale = 0.94;
// Get background color
if(is_check) {
if(is_check || GAME_DATA.state.code == GAME.Const.State.Checkmate) {
background_color = INTERFACE.Color.HintCheck;
}
switch(hover_state) {
@ -765,17 +765,22 @@ const INTERFACE = {
}
}
if(GAME_DATA.state.code == GAME.Const.State.Resign) {
switch(GAME_DATA.state.code) {
case GAME.Const.State.Resign: {
ctx.fillStyle = INTERFACE.Color.HintCheck;
message = LANG("resign");
} else if(GAME_DATA.state.check != 0 || GAME_DATA.state.code == GAME.Const.State.Checkmate) {
} break;
case GAME.Const.State.Checkmate: {
ctx.fillStyle = INTERFACE.Color.HintCheck;
if(GAME_DATA.state.code == GAME.Const.State.Checkmate) {
message = LANG("checkmate");
} else {
} break;
default: {
if(GAME_DATA.state.check != 0) {
ctx.fillStyle = INTERFACE.Color.HintCheck;
message = LANG("check");
}
}
}
if(message !== null) {
ctx.textBaseline = "bottom";