parent
c1608bacd1
commit
04d6837b5e
|
@ -19,7 +19,7 @@ pub enum BoardSize {
|
|||
}
|
||||
|
||||
impl BoardSize {
|
||||
fn get_size(&self) -> u32 {
|
||||
fn get_size(&self) -> usize {
|
||||
match &self {
|
||||
BoardSize::American => 8,
|
||||
BoardSize::International => 10,
|
||||
|
@ -60,7 +60,7 @@ impl Board {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_index(&self, row: u32, column: u32) -> usize {
|
||||
fn get_index(&self, row: usize, column: usize) -> usize {
|
||||
let width = self.dimensions.get_size();
|
||||
(row * (width / 2) + column) as usize
|
||||
}
|
||||
|
@ -74,15 +74,12 @@ impl fmt::Display for Board {
|
|||
let width = self.dimensions.get_size();
|
||||
|
||||
// Create the top level border.
|
||||
let mut column_border_chars = COLUMN_COORDINATE_BORDER.chars();
|
||||
for _ in 0..width + 1 {
|
||||
write!(formatter, "{}", column_border_chars.next().unwrap())?;
|
||||
}
|
||||
write!(formatter, "\n")?;
|
||||
let (column_border_chars, _) = COLUMN_COORDINATE_BORDER.split_at(width + 1);
|
||||
writeln!(formatter, "{}", column_border_chars)?;
|
||||
|
||||
for row in 0..width {
|
||||
|
||||
write!(formatter, "{ }", (row + 1).to_string())?;
|
||||
write!(formatter, "{}", (row + 1).to_string())?;
|
||||
if row % 2 == 0 {
|
||||
write!(formatter, " ")?;
|
||||
}
|
||||
|
@ -115,6 +112,25 @@ impl fmt::Display for Board {
|
|||
}
|
||||
}
|
||||
|
||||
pub enum GameState {
|
||||
LightPlayerTurn,
|
||||
DarkPlayerTurn,
|
||||
LightPlayerWin,
|
||||
DarkPlayerWin,
|
||||
DrawGame,
|
||||
}
|
||||
|
||||
pub struct Player {
|
||||
name: String,
|
||||
}
|
||||
|
||||
pub struct Game {
|
||||
board: Board,
|
||||
light_player: Player,
|
||||
dark_player: Player,
|
||||
state: GameState,
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
|
Loading…
Reference in New Issue