Prevent promotion without pmoves.
This commit is contained in:
parent
0ae1c5874c
commit
9660303e59
@ -73,7 +73,7 @@ impl Game {
|
|||||||
|
|
||||||
// Check for target promotion.
|
// Check for target promotion.
|
||||||
let hex = Hex::from_tile(play.from);
|
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;
|
target.promoted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ impl Game {
|
|||||||
|
|
||||||
// Check for piece promotion.
|
// Check for piece promotion.
|
||||||
let hex = Hex::from_tile(play.to);
|
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] {
|
if let Some(piece) = &mut self.board.pieces[pid as usize] {
|
||||||
piece.promoted = true;
|
piece.promoted = true;
|
||||||
}
|
}
|
||||||
|
@ -143,4 +143,9 @@ impl Piece {
|
|||||||
tile,
|
tile,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn has_promotion(&self) -> bool
|
||||||
|
{
|
||||||
|
PIECES[self.class as usize].pmoves.direction != 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,12 +178,16 @@ GAME.Piece = class {
|
|||||||
moves() {
|
moves() {
|
||||||
let def = GAME.Const.Piece[this.piece];
|
let def = GAME.Const.Piece[this.piece];
|
||||||
let moves = null;
|
let moves = null;
|
||||||
if(this.promoted && def.pmoves !== null) { moves = def.pmoves; }
|
if(this.promoted) { moves = def.pmoves; }
|
||||||
else { moves = def.moves; }
|
else { moves = def.moves; }
|
||||||
if(this.player == GAME.Const.Player.Dusk) { moves = moves.rotate(); }
|
if(this.player == GAME.Const.Player.Dusk) { moves = moves.rotate(); }
|
||||||
return moves;
|
return moves;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
has_promotion() {
|
||||||
|
return !this.promoted && GAME.Const.Piece[this.piece].pmoves !== null;
|
||||||
|
}
|
||||||
|
|
||||||
reset() {
|
reset() {
|
||||||
this.blocking = 0;
|
this.blocking = 0;
|
||||||
}
|
}
|
||||||
@ -302,7 +306,7 @@ GAME.Game = class {
|
|||||||
// Check if swap is promoted.
|
// Check if swap is promoted.
|
||||||
let hex = HEX.tile_to_hex(target.tile);
|
let hex = HEX.tile_to_hex(target.tile);
|
||||||
hex.y -= MATH.sign_branch(target.player);
|
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;
|
target.promoted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -319,7 +323,7 @@ GAME.Game = class {
|
|||||||
// Check if piece is promoted.
|
// Check if piece is promoted.
|
||||||
let hex = HEX.tile_to_hex(piece.tile);
|
let hex = HEX.tile_to_hex(piece.tile);
|
||||||
hex.y -= MATH.sign_branch(piece.player);
|
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;
|
piece.promoted = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user