Prevent promotion without pmoves.

This commit is contained in:
yukirij 2024-08-18 19:42:19 -07:00
parent 0ae1c5874c
commit 9660303e59
3 changed files with 14 additions and 5 deletions

View File

@ -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;
}

View File

@ -143,4 +143,9 @@ impl Piece {
tile,
}
}
pub fn has_promotion(&self) -> bool
{
PIECES[self.class as usize].pmoves.direction != 0
}
}

View File

@ -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;
}
}