Draft generation of valid AI movements
This commit is contained in:
@@ -14,6 +14,10 @@ pub struct Hand {
|
||||
}
|
||||
|
||||
impl Hand {
|
||||
pub fn new(tiles: Vec<Tile>) -> Self {
|
||||
Self { tiles }
|
||||
}
|
||||
|
||||
pub fn count_missing_operators(&self) -> usize {
|
||||
4usize.saturating_sub(
|
||||
self.tiles
|
||||
@@ -38,8 +42,9 @@ impl Hand {
|
||||
.push(Tile::Operator(deck.rand_operator().ok_or(EmptyDeckError)?));
|
||||
}
|
||||
for _ in 0..self.count_missing_numbers() {
|
||||
self.tiles
|
||||
.push(Tile::Digit(Digit::new(deck.rand_digit().ok_or(EmptyDeckError)?)));
|
||||
self.tiles.push(Tile::Digit(Digit::new(
|
||||
deck.rand_digit().ok_or(EmptyDeckError)?,
|
||||
)));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -51,4 +56,8 @@ impl Hand {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = &Tile> {
|
||||
self.tiles.iter()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user