mirror of
https://github.com/szymon-jozef/checkers.git
synced 2026-10-28 11:10:44 +01:00
chore: add board initialization logic
This commit is contained in:
@@ -1,54 +1,25 @@
|
||||
use crate::logic::utils::Field;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::logic::{player::Player, utils::Position};
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
pub enum PawnState {
|
||||
Man(Field),
|
||||
Dame(Field),
|
||||
Man(Position),
|
||||
Dame(Position),
|
||||
Captured,
|
||||
}
|
||||
|
||||
/// Basic pawn
|
||||
pub struct Pawn {
|
||||
state: PawnState,
|
||||
// TODO! Change this to Player when Player is implemented
|
||||
owner: String,
|
||||
pub state: PawnState,
|
||||
pub owner: Uuid,
|
||||
}
|
||||
|
||||
impl Pawn {
|
||||
// TODO! Look at line 16
|
||||
/// Every new Pawn is of type Man
|
||||
pub fn new(start_pos: Field, owner: String) -> Self {
|
||||
pub fn new(start_pos: Position, owner: &Player) -> Self {
|
||||
Self {
|
||||
state: PawnState::Man(start_pos),
|
||||
owner,
|
||||
owner: owner.id,
|
||||
}
|
||||
}
|
||||
|
||||
/// Return true if a pawn on given position is owned by the same player that this is
|
||||
// TODO! Implement
|
||||
fn is_mine(pos: Field) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
pub fn can_capture(&self) -> bool {
|
||||
match &self.state {
|
||||
PawnState::Man(pos) => {
|
||||
// Man can capture only on diagonal axis going one up, left or right
|
||||
let left_pos: Field = Field {
|
||||
row: (pos.row + 1),
|
||||
column: (pos.column - 1),
|
||||
};
|
||||
let left_right: Field = Field {
|
||||
row: (pos.row + 1),
|
||||
column: (pos.column + 1),
|
||||
};
|
||||
}
|
||||
PawnState::Dame(pos) => {}
|
||||
PawnState::Captured => {
|
||||
// Captured pawns cannot capture
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user