tidy up user prompts

This commit is contained in:
Dmitry Fedotov
2025-05-03 13:24:44 +03:00
parent b4b4166566
commit c3bcf44048
2 changed files with 46 additions and 6 deletions

View File

@@ -43,12 +43,11 @@ impl Board {
}
pub fn apply(&mut self, m: Move) -> Result<(), &str> {
let i = m.x * 1 + m.y * 3;
if !self.is_valid_move(&m) {
return Err("invalid move");
}
let i = m.x * 1 + m.y * 3;
self.cells[i] = m.piece;
match self.next {
@@ -68,14 +67,13 @@ impl Board {
pub fn valid_moves_available(&self) -> bool {
// check for draw condition
let mut empty: usize = 0;
for i in 0..self.cells.len() {
if self.cells[i] == Cell::Empty {
empty += 1;
return true;
}
}
empty > 0
return false;
}
pub fn has_winner(&self) -> Option<Cell> {