2019-03-01 09:04:11 -05:00
|
|
|
use std::fmt;
|
|
|
|
|
|
|
|
pub enum Piece {
|
|
|
|
LightPawn,
|
2019-02-28 09:06:24 -05:00
|
|
|
LightKing,
|
2019-03-01 09:04:11 -05:00
|
|
|
DarkPawn,
|
2019-02-28 09:06:24 -05:00
|
|
|
DarkKing,
|
|
|
|
}
|
|
|
|
|
2019-03-01 09:04:11 -05:00
|
|
|
pub enum BoardTile {
|
2019-02-28 09:06:24 -05:00
|
|
|
Empty,
|
2019-03-01 09:04:11 -05:00
|
|
|
Piece(Piece),
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum BoardSize {
|
|
|
|
American,
|
|
|
|
International,
|
|
|
|
Canadian,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl BoardSize {
|
|
|
|
fn get_size(&self) -> u32 {
|
|
|
|
match &self {
|
|
|
|
BoardSize::American => 8,
|
|
|
|
BoardSize::International => 10,
|
|
|
|
BoardSize::Canadian => 12,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Board {
|
|
|
|
dimensions: BoardSize,
|
|
|
|
tiles: Vec<BoardTile>,
|
2019-02-28 09:06:24 -05:00
|
|
|
}
|
|
|
|
|
2019-03-01 09:04:11 -05:00
|
|
|
impl Board {
|
|
|
|
pub fn new(size: BoardSize) -> Board {
|
|
|
|
|
|
|
|
let board_size = size.get_size();
|
|
|
|
let width = board_size / 2;
|
|
|
|
let height = board_size / 2;
|
|
|
|
let starting_rows = board_size / 2 - 1;
|
|
|
|
|
|
|
|
let playing_tiles = (0..width * height)
|
|
|
|
.map(|tile|{
|
|
|
|
let row = tile / width;
|
|
|
|
match row {
|
|
|
|
r if r < starting_rows => BoardTile::Piece(
|
|
|
|
Piece::LightPawn),
|
|
|
|
r if r > height - starting_rows => BoardTile::Piece(
|
|
|
|
Piece::DarkPawn),
|
|
|
|
_ => BoardTile::Empty,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
Board {
|
|
|
|
dimensions: size,
|
|
|
|
tiles: playing_tiles,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Display for Board {
|
|
|
|
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
|
|
|
|
// TODO: Add a A-Z and 1-12 border around the game.
|
|
|
|
let width = self.dimensions.get_size();
|
|
|
|
let height= self.dimensions.get_size();
|
|
|
|
|
|
|
|
// TODO: Implement a looping setup for the checkerboard.
|
|
|
|
// for {}
|
|
|
|
//
|
|
|
|
// let square = match tile {
|
|
|
|
// Piece::LightPawn => "♙",
|
|
|
|
// Piece::LightKing => "♔",
|
|
|
|
// Piece::DarkPawn => "♟",
|
|
|
|
// Piece::DarkKing => "♚",
|
|
|
|
// };
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
2019-02-28 09:06:24 -05:00
|
|
|
|
|
|
|
|
2019-02-28 08:39:27 -05:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
#[test]
|
|
|
|
fn it_works() {
|
|
|
|
assert_eq!(2 + 2, 4);
|
|
|
|
}
|
|
|
|
}
|