Add player to tile struct

This commit is contained in:
Oystein Kristoffer Tveit 2021-10-25 19:37:41 +02:00
parent e1cacce3b0
commit 3a78c2d42e
1 changed files with 11 additions and 3 deletions

View File

@ -1,8 +1,11 @@
use std::fmt;
use super::piece::Piece;
use super::player::Player;
pub struct Board(Vec<Vec<Option<Piece>>>);
#[derive(Clone)]
pub struct Tile(Option<Piece>, Option<Player>);
pub struct Board(Vec<Vec<Tile>>);
impl fmt::Display for Board {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@ -13,7 +16,7 @@ impl fmt::Display for Board {
.map(|row| {
row
.into_iter()
.map(|op| match op {
.map(|op| match op.0 {
Some(p) => p.to_string(),
None => ".".to_string(),
})
@ -35,10 +38,15 @@ impl Board {
.map(|row| {
row
.chars()
.map(|l| Piece::from_string(&l).ok())
.map(|l| Tile(Piece::from_string(&l).ok(), None))
.collect::<Vec<_>>()
})
.collect::<Vec<_>>();
for row in board.iter().skip(1) {
assert!(row.len() == board[0].len());
}
Board(board)
}