Fix server-side promotion handling.
This commit is contained in:
parent
fd1d99dd77
commit
d53e8e272e
@ -2,7 +2,7 @@ use crate::{
|
||||
//consts::*,
|
||||
board::Board,
|
||||
history::Play,
|
||||
piece::Piece,
|
||||
piece::Piece, util::Hex,
|
||||
};
|
||||
|
||||
pub type Pool = [u8; 7];
|
||||
@ -91,6 +91,13 @@ impl Game {
|
||||
piece.tile = play.to;
|
||||
|
||||
self.board.pieces[pid as usize] = Some(piece);
|
||||
|
||||
// Check if piece is promoted.
|
||||
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) {
|
||||
piece.promoted = true;
|
||||
}
|
||||
true
|
||||
} else { false }
|
||||
} else { false }
|
||||
|
@ -41,6 +41,27 @@ impl Hex {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_valid(x:i8, y:i8) -> bool
|
||||
{
|
||||
const COLUMNS :[(i8, i8); 9] = [
|
||||
(0, 4),
|
||||
(0, 5),
|
||||
(0, 6),
|
||||
(0, 7),
|
||||
(0, 8),
|
||||
(1, 8),
|
||||
(2, 8),
|
||||
(3, 8),
|
||||
(4, 8),
|
||||
];
|
||||
|
||||
let valid = x >= 0 && x < 9;
|
||||
if valid {
|
||||
let (min, max) = COLUMNS[x as usize];
|
||||
y >= min && y <= max
|
||||
} else { false }
|
||||
}
|
||||
|
||||
pub fn x(&self) -> u8 { self.x }
|
||||
pub fn y(&self) -> u8 { self.y }
|
||||
pub fn tile(&self) -> u8 { self.tile }
|
||||
|
@ -15,6 +15,9 @@ const SCENES = {
|
||||
], []);
|
||||
return true;
|
||||
},
|
||||
reconnect() {
|
||||
LOAD(CONTEXT.Scene);
|
||||
}
|
||||
},
|
||||
|
||||
Register:{
|
||||
|
@ -35,7 +35,7 @@ function RESUME() {
|
||||
CONTEXT.Auth.secret,
|
||||
]);
|
||||
} else {
|
||||
LOAD(CONTEXT.Scene);
|
||||
if(SCENE.reconnect !== undefined) { SCENE.reconnect(); }
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user