Fix up setup of an initial game.

This commit is contained in:
Dorian 2019-03-02 00:16:50 -05:00
parent 6b9027bdd8
commit 3af3ede5a7
2 changed files with 13 additions and 8 deletions

2
Cargo.lock generated
View File

@ -1,3 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "justcheckers-engine"
version = "0.6.0"

View File

@ -38,7 +38,7 @@ impl Board {
let board_size = size.get_size();
let width = board_size / 2;
let height = board_size / 2;
let height = board_size;
let starting_rows = board_size / 2 - 1;
let playing_tiles = (0..width * height)
@ -47,7 +47,7 @@ impl Board {
match row {
r if r < starting_rows => BoardTile::Piece(
Piece::LightPawn),
r if r > height - starting_rows => BoardTile::Piece(
r if r > height - starting_rows - 1 => BoardTile::Piece(
Piece::DarkPawn),
_ => BoardTile::Empty,
}
@ -61,8 +61,8 @@ impl Board {
}
fn get_index(&self, row: u32, column: u32) -> usize {
let width = self.dimensions.get_size();
(row * width + column) as usize
let width = self.dimensions.get_size() / 2;
(row * width + (column / 2)) as usize
}
}
@ -88,15 +88,18 @@ impl fmt::Display for Board {
}
for col in 0..(width / 2) {
let token = match self.tiles[self.get_index(row, col)] {
let idx = (row * (width / 2) + col) as usize;
let token = match self.tiles[idx] {
BoardTile::Piece(Piece::LightPawn) => "",
BoardTile::Piece(Piece::LightKing) => "",
BoardTile::Piece(Piece::DarkPawn) => "",
BoardTile::Piece(Piece::DarkKing) => "",
BoardTile::Empty => "",
BoardTile::Empty => "",
};
let adjacent = if row % 2 == 1 && col == width - 1 {
let adjacent = if row % 2 == 0 && col == (width / 2) - 1 {
""
} else {
" "