From 3a78c2d42ef3285fb65ad7fd29814eebc0d1a267 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 25 Oct 2021 19:37:41 +0200 Subject: [PATCH] Add player to tile struct --- src/models/board.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/models/board.rs b/src/models/board.rs index 07997e4..353b7ad 100644 --- a/src/models/board.rs +++ b/src/models/board.rs @@ -1,8 +1,11 @@ use std::fmt; use super::piece::Piece; +use super::player::Player; -pub struct Board(Vec>>); +#[derive(Clone)] +pub struct Tile(Option, Option); +pub struct Board(Vec>); 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::>() }) .collect::>(); + + for row in board.iter().skip(1) { + assert!(row.len() == board[0].len()); + } + Board(board) }