chore: add board initialization logic

This commit is contained in:
2026-08-11 20:19:33 +02:00
parent b460c7a62b
commit f25cb47eae
7 changed files with 589 additions and 47 deletions

View File

@@ -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
}
}