Potential fix for promotion detection.
This commit is contained in:
parent
ffa5d45d31
commit
5d5892c66f
@ -70,6 +70,12 @@ impl Game {
|
||||
if piece.player == target.player {
|
||||
swap = true;
|
||||
target.tile = play.from;
|
||||
|
||||
// Check for target promotion.
|
||||
let hex = Hex::from_tile(play.to);
|
||||
if !target.promoted && !Hex::is_back(hex.x(), hex.y(), target.player) {
|
||||
target.promoted = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Add captured piece to pool.
|
||||
@ -82,6 +88,7 @@ impl Game {
|
||||
if !swap { self.board.pieces[tid as usize] = None; }
|
||||
}
|
||||
|
||||
// Set tile/piece associations.
|
||||
if swap {
|
||||
self.board.tiles[play.from as usize].piece = self.board.tiles[play.to as usize].piece;
|
||||
} else {
|
||||
@ -92,10 +99,9 @@ impl Game {
|
||||
|
||||
self.board.pieces[pid as usize] = Some(piece);
|
||||
|
||||
// Check if piece is promoted.
|
||||
// Check for piece promotion.
|
||||
let hex = Hex::from_tile(play.from);
|
||||
let offset = -(piece.player as i8 * 2) + 1;
|
||||
if !piece.promoted && !Hex::is_valid(hex.x() as i8, hex.y() as i8 + offset) {
|
||||
if !piece.promoted && !Hex::is_back(hex.x(), hex.y(), piece.player) {
|
||||
if let Some(piece) = &mut self.board.pieces[pid as usize] {
|
||||
piece.promoted = true;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ impl Hex {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_valid(x:i8, y:i8) -> bool
|
||||
/*pub fn is_valid(x:i8, y:i8) -> bool
|
||||
{
|
||||
const COLUMNS :[(i8, i8); 9] = [
|
||||
(0, 4),
|
||||
@ -60,6 +60,24 @@ impl Hex {
|
||||
let (min, max) = COLUMNS[x as usize];
|
||||
y >= min && y <= max
|
||||
} else { false }
|
||||
}*/
|
||||
|
||||
pub fn is_back(x:u8, y:u8, player:u8) -> bool
|
||||
{
|
||||
const COLUMNS :[[u8; 2]; 9] = [
|
||||
[0, 4],
|
||||
[0, 5],
|
||||
[0, 6],
|
||||
[0, 7],
|
||||
[0, 8],
|
||||
[1, 8],
|
||||
[2, 8],
|
||||
[3, 8],
|
||||
[4, 8],
|
||||
];
|
||||
if x > 0 && x < 9 {
|
||||
y == COLUMNS[x as usize][1 ^ player as usize]
|
||||
} else { false }
|
||||
}
|
||||
|
||||
pub fn x(&self) -> u8 { self.x }
|
||||
|
@ -771,6 +771,8 @@ const INTERFACE = {
|
||||
},
|
||||
|
||||
message(code, data) {
|
||||
if(data === null) { return; }
|
||||
|
||||
switch(code) {
|
||||
case OpCode.GameState: {
|
||||
INTERFACE_DATA.player = data.player;
|
||||
|
Loading…
x
Reference in New Issue
Block a user