fill game when all players are ready

Co-authored-by: Eirik Witterso <eirikwit@pvv.ntnu.no>
This commit is contained in:
2024-02-11 01:09:31 +01:00
parent 20c3108389
commit bc8572caaa
2 changed files with 30 additions and 7 deletions

View File

@@ -129,10 +129,20 @@ impl GameState {
Ok(game)
}
pub fn set_ready(&mut self, player_name: &PlayerName) -> Result<(), &str> {
self.players.get_mut(player_name).ok_or("That player is not part of this game")?.ready = true;
Ok(())
}
pub fn all_ready(&self) -> bool {
self.players.values().all(|x| x.ready)
}
/// Fills the factories from the bag
/// Will replenish the bag from the lid when empty
/// Will return with partially filled factories if out of tiles
fn fill(&mut self) -> Result<(), &'static str> {
pub fn fill(&mut self) -> Result<(), &'static str> {
if !self.only_start() {
return Err("Cannot fill, there are still tiles left to be picked");
}
@@ -162,9 +172,7 @@ impl GameState {
let dist = WeightedIndex::new(&weights).unwrap();
let picked = choices[dist.sample(&mut self.rng)];
eprintln!("picked {:?}", picked);
self.bag.add_color(picked, -1)?;
factory.add_color(picked, 1)?;
}
@@ -610,6 +618,7 @@ impl From<TileSet> for TileSetWithStart {
#[derive(Debug, Serialize, Deserialize, Clone, Default)]
struct Player {
ready: bool,
points: usize,
pattern_lines: [PatternLine; 5],
wall: Wall,