Implement board setup

This commit is contained in:
2021-11-23 22:47:56 +01:00
parent 72a691de90
commit e45fd3981a

View File

@@ -25,6 +25,7 @@ impl Color {
} }
} }
#[derive(Clone)]
struct Position { struct Position {
row: Row, row: Row,
column: Column, column: Column,
@@ -203,4 +204,26 @@ impl Piece {
} }
} }
struct Board {
state: [[Option<Piece>; Column::ALL_VALUES.len()]; Row::ALL_VALUES.len()],
}
impl Board {
fn set_at(&mut self, position: &Position, piece: Piece) {
self.state[position.row.get_index() as usize]
[position.column.get_index() as usize] = Some(piece);
}
fn new() -> Board {
let mut board = Board {
state: Default::default(),
};
for piece_type in &[PieceType::Pawn] {
for piece in piece_type.initial_setup() {
board.set_at(&piece.position.clone(), piece);
}
}
board
}
}
fn main() {} fn main() {}