Skip to content

implement start fn #13

@blurbeast

Description

@blurbeast

📌 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 Pending to Ongoing.
  • Balance Distribution:

    • Retrieve all players registered in the game.
    • Allocate an equal amount of balance to each player by writing to the GameBalance model.

🛠️ 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 where start() 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 Ongoing or Ended → 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 GameTrait and 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions