mirror of
https://github.com/szymon-jozef/checkers.git
synced 2026-10-27 19:20:44 +01:00
refactor: make Board::new cleaner
This commit is contained in:
@@ -32,22 +32,23 @@ impl Board {
|
|||||||
let is_valid_place_for_a_pawn: bool = is_row_even ^ is_column_even;
|
let is_valid_place_for_a_pawn: bool = is_row_even ^ is_column_even;
|
||||||
let position: Position = Position { row, column };
|
let position: Position = Position { row, column };
|
||||||
|
|
||||||
// first player's pawns
|
let current_player: Option<&Player> = if row < 3 {
|
||||||
if row < 3 && is_valid_place_for_a_pawn {
|
Some(p1_ref)
|
||||||
debug!("Placing new pawn at: {}, owned by: {}", position, &p1_ref);
|
} else if row >= size - 3 {
|
||||||
|
Some(p2_ref)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Some(player) = current_player
|
||||||
|
&& is_valid_place_for_a_pawn
|
||||||
|
{
|
||||||
|
debug!("Placing new pawn at: {}, owned by: {}", position, player);
|
||||||
Field {
|
Field {
|
||||||
position,
|
position,
|
||||||
pawn: Some(Pawn::new(position, &p1_ref)),
|
pawn: Some(Pawn::new(position, player)),
|
||||||
}
|
|
||||||
} else if row >= size - 3 && is_valid_place_for_a_pawn {
|
|
||||||
debug!("Placing new pawn at: {}, owned by: {}", position, &p2_ref);
|
|
||||||
Field {
|
|
||||||
position,
|
|
||||||
pawn: Some(Pawn::new(position, &p2_ref)),
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// no pawn
|
|
||||||
debug!("Not placing any pawn at: {}", position);
|
debug!("Not placing any pawn at: {}", position);
|
||||||
Field {
|
Field {
|
||||||
position,
|
position,
|
||||||
|
|||||||
Reference in New Issue
Block a user