diff --git a/game/src/game/mod.rs b/game/src/game/mod.rs index e8f5069..7dd818f 100644 --- a/game/src/game/mod.rs +++ b/game/src/game/mod.rs @@ -73,7 +73,7 @@ impl Game { // Check for target promotion. let hex = Hex::from_tile(play.from); - if !target.promoted && Hex::is_back(hex.x, hex.y, target.player) { + if !target.promoted && target.has_promotion() && Hex::is_back(hex.x, hex.y, target.player) { target.promoted = true; } } @@ -101,7 +101,7 @@ impl Game { // Check for piece promotion. let hex = Hex::from_tile(play.to); - if !piece.promoted && Hex::is_back(hex.x, hex.y, piece.player) { + if !piece.promoted && piece.has_promotion() && Hex::is_back(hex.x, hex.y, piece.player) { if let Some(piece) = &mut self.board.pieces[pid as usize] { piece.promoted = true; } diff --git a/game/src/piece/mod.rs b/game/src/piece/mod.rs index eb7959b..33e152a 100644 --- a/game/src/piece/mod.rs +++ b/game/src/piece/mod.rs @@ -143,4 +143,9 @@ impl Piece { tile, } } + + pub fn has_promotion(&self) -> bool + { + PIECES[self.class as usize].pmoves.direction != 0 + } } diff --git a/www/js/game.js b/www/js/game.js index e2e1174..e2a866f 100644 --- a/www/js/game.js +++ b/www/js/game.js @@ -178,12 +178,16 @@ GAME.Piece = class { moves() { let def = GAME.Const.Piece[this.piece]; let moves = null; - if(this.promoted && def.pmoves !== null) { moves = def.pmoves; } + if(this.promoted) { moves = def.pmoves; } else { moves = def.moves; } if(this.player == GAME.Const.Player.Dusk) { moves = moves.rotate(); } return moves; } + has_promotion() { + return !this.promoted && GAME.Const.Piece[this.piece].pmoves !== null; + } + reset() { this.blocking = 0; } @@ -302,7 +306,7 @@ GAME.Game = class { // Check if swap is promoted. let hex = HEX.tile_to_hex(target.tile); hex.y -= MATH.sign_branch(target.player); - if(!target.promoted && !HEX.is_valid(hex)) { + if(!target.promoted && target.has_promotion() && !HEX.is_valid(hex)) { target.promoted = true; } } @@ -319,7 +323,7 @@ GAME.Game = class { // Check if piece is promoted. let hex = HEX.tile_to_hex(piece.tile); hex.y -= MATH.sign_branch(piece.player); - if(!piece.promoted && !HEX.is_valid(hex)) { + if(!piece.promoted && piece.has_promotion() && !HEX.is_valid(hex)) { piece.promoted = true; } }