game:playerbuilder: First stage of game complete.

The first stage of the game is collecting the relevant players who
want to play.  We can't deal out any cards, nor do an election, till
this is done.

The way I've codified this is by having an opaque PlayerBuilder struct
with some helpers to add "new players" - essentially just empty decks
of cards.  Once we're done, we "freeze" or "fix" this set of players
by returning a Boxed array representing the contents.

Ridiculously simple API.
This commit is contained in:
2026-04-16 21:06:56 +01:00
parent 6d1653bb4e
commit 955e37cfb3
2 changed files with 32 additions and 0 deletions

View File

@@ -1 +1,2 @@
pub mod deck;
pub mod playerbuilder;

31
src/game/playerbuilder.rs Normal file
View File

@@ -0,0 +1,31 @@
use crate::game::deck::Deck;
/// Player Builder, which allows the adding of new players.
pub struct PlayerBuilder {
players: Vec<Deck>,
}
/// A fixed set of players that cannot grow - occurs once players have been
/// picked.
pub type FixedPlayers = Box<[Deck]>;
impl PlayerBuilder {
/// Construct a new player builder.
pub fn new() -> Self {
Self {
players: Vec::new(),
}
}
/// Add a new player with an empty deck to the builder, returning its ID.
pub fn add(&mut self) -> usize {
let id = self.players.len();
self.players.push(Deck::new_empty());
id
}
/// Fix the current number of players for later game stages.
pub fn into_fixed(self) -> FixedPlayers {
self.players.into_boxed_slice()
}
}