-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
π Feature Request: Implement start() Function in IAction Interface
π§© Description
Implement the start() function within the IAction interface to serve as the entry point for starting a game.
This function is responsible for:
- Performing all necessary validation checks before starting the game.
- Updating the game status to reflect that it has started.
- Evenly distributing the initial game balance among all players in the game.
β Acceptance Criteria
-
Validation Checks:
- Ensure the game exists and is initialized.
- Verify that the number of players who joined equals the expected
number_of_players. - Check that the game is marked as
ready_to_start = true. - Confirm that the game status is currently
Pending.
-
Status Update:
- Update the game status from
PendingtoOngoing.
- Update the game status from
-
Balance Distribution:
- Retrieve all players registered in the game.
- Allocate an equal amount of balance to each player by writing to the
GameBalancemodel.
π οΈ Related Models & Contracts
Game: Core game model with status, players, and game type.GameBalance: Tracks balance per player per game.GameStatus: Enum used to identify current game lifecycle state.GameType: Enum for public/private game mode.IAction: Contract interface wherestart()will be implemented.
π§ͺ Testing Notes
-
Attempt to start a game before all players have joined β should fail.
-
Attempt to start a game thatβs already
OngoingorEndedβ should fail. -
Attempt to start a game where
ready_to_start = falseβ should fail. -
On success, verify:
- All players received equal balance.
- Game status is updated to
Ongoing.
π¦ Example Artifacts
// Inside IAction impl
fn start_game(ref self: ContractState, game_id: u256) -> bool {
// Check game exists
// Ensure all players have joined
// Ensure ready_to_start is true
// Ensure game status is Pending
// Update status to Ongoing
// Distribute balance evenly among players
true
}π Status
Stat: β
Done
Build: β
Builds Successfully
Validation: β
All Checks Handled
Logic: β
Players Credited Evenly
π Additional Notes
- Use
GameTraitand existing models effectively to avoid duplicating logic. - May require creating a helper to fetch all players associated with a game (if not already available).
- Consider emitting an event,
GameStarted.
Reactions are currently unavailable