mirror of
https://github.com/szymon-jozef/checkers.git
synced 2026-10-27 19:20:44 +01:00
chore: implement is_movable for dame
This commit is contained in:
@@ -128,13 +128,44 @@ impl Board {
|
||||
false
|
||||
}
|
||||
PawnState::Dame => {
|
||||
todo!();
|
||||
let left_down: DeltaPosition = DeltaPosition { row: 0, column: -1 } - direction;
|
||||
let right_down: DeltaPosition = DeltaPosition { row: 0, column: 1 } - direction;
|
||||
|
||||
if let Some(left_up_pos) = pos.checked_add(&(left_up))
|
||||
&& left_up_pos.is_in_range(self.size)
|
||||
&& self[left_up_pos].pawn.is_none()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if let Some(right_up_pos) = pos.checked_add(&right_up)
|
||||
&& right_up_pos.is_in_range(self.size)
|
||||
&& self[right_up_pos].pawn.is_none()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if let Some(left_down_pos) = pos.checked_add(&left_down)
|
||||
&& left_down_pos.is_in_range(self.size)
|
||||
&& self[left_down_pos].pawn.is_none()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if let Some(right_down_pos) = pos.checked_add(&right_down)
|
||||
&& right_down_pos.is_in_range(self.size)
|
||||
&& self[right_down_pos].pawn.is_none()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
PawnState::Captured => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn get_player_pawns_positions(&self, player: &Player) -> Vec<Position> {
|
||||
pub fn get_player_pawns_positions(&self, player: &Player) -> Vec<Position> {
|
||||
self.board
|
||||
.iter()
|
||||
.filter_map(|field| {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use core::fmt;
|
||||
use std::ops::Add;
|
||||
use std::ops::{Add, Mul, Sub};
|
||||
|
||||
use log::debug;
|
||||
|
||||
@@ -60,6 +60,28 @@ impl Add for DeltaPosition {
|
||||
}
|
||||
}
|
||||
|
||||
impl Sub for DeltaPosition {
|
||||
type Output = DeltaPosition;
|
||||
|
||||
fn sub(self, rhs: DeltaPosition) -> Self::Output {
|
||||
DeltaPosition {
|
||||
row: self.row - rhs.row,
|
||||
column: self.column - rhs.column,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Mul<usize> for DeltaPosition {
|
||||
type Output = DeltaPosition;
|
||||
|
||||
fn mul(self, rhs: usize) -> Self::Output {
|
||||
DeltaPosition {
|
||||
row: self.row * rhs as i8,
|
||||
column: self.column * rhs as i8,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user