Implement basic setup of the checkerboard.
This commit is contained in:
parent
f20aa6989c
commit
5e24c02cfb
|
@ -1,15 +1,86 @@
|
|||
enum Token {
|
||||
LightMan,
|
||||
use std::fmt;
|
||||
|
||||
pub enum Piece {
|
||||
LightPawn,
|
||||
LightKing,
|
||||
DarkPawn,
|
||||
DarkKing,
|
||||
DarkMan,
|
||||
}
|
||||
|
||||
enum Space {
|
||||
pub enum BoardTile {
|
||||
Empty,
|
||||
Token,
|
||||
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>,
|
||||
}
|
||||
|
||||
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(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Reference in New Issue