Add working layout and setup code for the game engine.
This commit is contained in:
parent
3af3ede5a7
commit
c1608bacd1
|
@ -61,8 +61,8 @@ impl Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_index(&self, row: u32, column: u32) -> usize {
|
fn get_index(&self, row: u32, column: u32) -> usize {
|
||||||
let width = self.dimensions.get_size() / 2;
|
let width = self.dimensions.get_size();
|
||||||
(row * width + (column / 2)) as usize
|
(row * (width / 2) + column) as usize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ impl fmt::Display for Board {
|
||||||
|
|
||||||
for col in 0..(width / 2) {
|
for col in 0..(width / 2) {
|
||||||
|
|
||||||
let idx = (row * (width / 2) + col) as usize;
|
let idx = self.get_index(row, col);
|
||||||
|
|
||||||
let token = match self.tiles[idx] {
|
let token = match self.tiles[idx] {
|
||||||
BoardTile::Piece(Piece::LightPawn) => "○",
|
BoardTile::Piece(Piece::LightPawn) => "○",
|
||||||
|
@ -122,7 +122,7 @@ mod tests {
|
||||||
use crate::BoardSize;
|
use crate::BoardSize;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn setup_international_board() {
|
fn initial_international_board_setup() {
|
||||||
|
|
||||||
let expected =
|
let expected =
|
||||||
" \
|
" \
|
||||||
|
@ -140,4 +140,44 @@ mod tests {
|
||||||
";
|
";
|
||||||
assert_eq!(Board::new(BoardSize::International).to_string(), expected);
|
assert_eq!(Board::new(BoardSize::International).to_string(), expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn initial_american_board_setup() {
|
||||||
|
|
||||||
|
let expected =
|
||||||
|
" \
|
||||||
|
ABCDEFGH\n\
|
||||||
|
1 ○ ○ ○ ○\n\
|
||||||
|
2○ ○ ○ ○ \n\
|
||||||
|
3 ○ ○ ○ ○\n\
|
||||||
|
4◰ ◰ ◰ ◰ \n\
|
||||||
|
5 ◰ ◰ ◰ ◰\n\
|
||||||
|
6● ● ● ● \n\
|
||||||
|
7 ● ● ● ●\n\
|
||||||
|
8● ● ● ● \n\
|
||||||
|
";
|
||||||
|
assert_eq!(Board::new(BoardSize::American).to_string(), expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn initial_canadian_board_setup() {
|
||||||
|
|
||||||
|
let expected =
|
||||||
|
" \
|
||||||
|
ABCDEFGHIJKL\n\
|
||||||
|
1 ○ ○ ○ ○ ○ ○\n\
|
||||||
|
2○ ○ ○ ○ ○ ○ \n\
|
||||||
|
3 ○ ○ ○ ○ ○ ○\n\
|
||||||
|
4○ ○ ○ ○ ○ ○ \n\
|
||||||
|
5 ○ ○ ○ ○ ○ ○\n\
|
||||||
|
6◰ ◰ ◰ ◰ ◰ ◰ \n\
|
||||||
|
7 ◰ ◰ ◰ ◰ ◰ ◰\n\
|
||||||
|
8● ● ● ● ● ● \n\
|
||||||
|
9 ● ● ● ● ● ●\n\
|
||||||
|
10● ● ● ● ● ● \n\
|
||||||
|
11 ● ● ● ● ● ●\n\
|
||||||
|
12● ● ● ● ● ● \n\
|
||||||
|
";
|
||||||
|
assert_eq!(Board::new(BoardSize::Canadian).to_string(), expected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue