fill game when all players are ready
Co-authored-by: Eirik Witterso <eirikwit@pvv.ntnu.no>
This commit is contained in:
17
src/azul.rs
17
src/azul.rs
@@ -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,
|
||||
|
Reference in New Issue
Block a user