-
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.