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. ** Add drops to player moves.
*/ */
for i in 0..6 { 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 plays

View File

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

View File

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