case class GameState(currentPlayers: Int, maxAllowedPlayers: Int, playersId: List[String])
Represents the current state of player occupancy for a game.
Tracks the number of players currently engaged with a game, enforces capacity limits, and maintains a list of player identifiers. This immutable data structure ensures thread-safe state management and provides methods for adding and removing players with proper validation.
Value parameters
currentPlayers
the number of players currently in the game
maxAllowedPlayers
the maximum capacity of players for this game
playersId
the list of unique identifiers for all current players
Validates that the game has available capacity before adding the player. If successful, returns a new GameState with incremented player count and the player's ID added to the list. If the game is full, returns the current state as a failure.
Value parameters
id
the unique identifier of the player to add
Attributes
Returns
Success with updated GameState if space available, Failure with current state if full
Validates that there are players to remove before proceeding. If successful, returns a new GameState with decremented player count and the player's ID removed from the list. If no players are present, returns the current state as a failure.
Value parameters
id
the unique identifier of the player to remove
Attributes
Returns
Success with updated GameState if players exist, Failure with current state if empty