moves rules by mirror
This commit is contained in:
parent
4b3bae7caf
commit
152d2673f7
3 changed files with 271 additions and 309 deletions
|
|
@ -28,6 +28,12 @@ fn transpose(matrix: Vec<Vec<String>>) -> Vec<Vec<String>> {
|
|||
out
|
||||
}
|
||||
|
||||
impl Default for CheckerMove {
|
||||
fn default() -> Self {
|
||||
EMPTY_MOVE
|
||||
}
|
||||
}
|
||||
|
||||
impl CheckerMove {
|
||||
pub fn new(from: Field, to: Field) -> Result<Self, Error> {
|
||||
// println!("from {} to {}", from, to);
|
||||
|
|
@ -46,6 +52,13 @@ impl CheckerMove {
|
|||
Ok(Self { from, to })
|
||||
}
|
||||
|
||||
/// Get the mirrord CheckerMove (ie change colors)
|
||||
pub fn mirror(&self) -> Self {
|
||||
let from = if self.from == 0 { 0 } else { 25 - self.from };
|
||||
let to = if self.to == 0 { 0 } else { 25 - self.to };
|
||||
Self { from, to }
|
||||
}
|
||||
|
||||
// Construct the move resulting of two successive moves
|
||||
pub fn chain(self, cmove: Self) -> Result<Self, Error> {
|
||||
if self.to != cmove.from {
|
||||
|
|
@ -101,6 +114,13 @@ impl Board {
|
|||
Board::default()
|
||||
}
|
||||
|
||||
/// Get the mirrord board (ie change colors)
|
||||
pub fn mirror(&self) -> Self {
|
||||
let mut positions = self.positions.map(|c| 0 - c);
|
||||
positions.reverse();
|
||||
Board { positions }
|
||||
}
|
||||
|
||||
/// Globally set pieces on board ( for tests )
|
||||
pub fn set_positions(&mut self, positions: [i8; 24]) {
|
||||
self.positions = positions;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue