Add player to tile struct
This commit is contained in:
parent
e1cacce3b0
commit
3a78c2d42e
|
@ -1,8 +1,11 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use super::piece::Piece;
|
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 {
|
impl fmt::Display for Board {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
@ -13,7 +16,7 @@ impl fmt::Display for Board {
|
||||||
.map(|row| {
|
.map(|row| {
|
||||||
row
|
row
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|op| match op {
|
.map(|op| match op.0 {
|
||||||
Some(p) => p.to_string(),
|
Some(p) => p.to_string(),
|
||||||
None => ".".to_string(),
|
None => ".".to_string(),
|
||||||
})
|
})
|
||||||
|
@ -35,10 +38,15 @@ impl Board {
|
||||||
.map(|row| {
|
.map(|row| {
|
||||||
row
|
row
|
||||||
.chars()
|
.chars()
|
||||||
.map(|l| Piece::from_string(&l).ok())
|
.map(|l| Tile(Piece::from_string(&l).ok(), None))
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
|
||||||
|
for row in board.iter().skip(1) {
|
||||||
|
assert!(row.len() == board[0].len());
|
||||||
|
}
|
||||||
|
|
||||||
Board(board)
|
Board(board)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue