Skip to content

Latest commit

 

History

History
111 lines (73 loc) · 4.74 KB

File metadata and controls

111 lines (73 loc) · 4.74 KB

SpawnSystem Smart Contract

The SpawnSystem contract allows players in a match to strategically position their pieces on the game board using a commit-reveal mechanism.

  1. Commit: Players first commit to the pieces they plan to deploy on the board by encoding this information. This encoding ensures that other players cannot determine which pieces are being positioned.
  2. Reveal: Players then reveal their encoded hashes to confirm the placement and positions of their pieces on the game board.

Contract Functionalities

  • Commit and Reveal Spawn: Enables players to securely commit to and reveal the intended positions of their pieces on the game board.
  • Generate Encoded Hashes: Offers functionality to create encoded hashes for the commit phase, ensuring secure and private commitments.
  • Abort Match: Provides the option to terminate a match if necessary.

commitSpawn

function commitSpawn(bytes32 _commitHash, bytes32 _matchEntity) public;
  • Allows a player to commit to spawning pieces on the board by providing a commit hash and match entity ID. This function ensures that a player can securely register their intention to spawn pieces as part of the game mechanics.

  • The function checks if the time control for the match has not passed and verifies that the player's current spawn status is CommitSpawning. If these conditions are not met, the operation is halted with an error. If successful, it updates the spawn status to LockCommitSpawning and proceeds with further game logic.

  • Parameters:

    • commitHash: The hash representing the player's commitment to the pieces.
    • matchEntity: The identifier for the match entity involved.
  • Sample Code:

bytes32 commitHash = 0xabc...;  // Example generated hash
bytes32 matchEntity = 0x000000000000000000000000000000000000000000000000000000000000beef;

world.tacticsWar__commitSpawn(commitHash, matchEntity);

Note:

  • The player must be in the CommitSpawning phase to commit the pieces.
  • The commit phase must be within the allowed time frame, or the commitment will not be processed.

revealSpawn

function revealSpawn(
    bytes32 _matchEntity,
    PositionData[] calldata _coordinates,
    bytes32[] calldata _pieceEntities,
    bytes32 _secret
) public
  • Allows a player to reveal the positions of their committed pieces on the board. This function validates the provided secret and updates the game state by placing the pieces in their specified positions.

  • The function checks if the time control for the match has not passed and validates the secret against the committed data. If successful, it places each piece at its respective coordinate and updates the spawn status to LockRevealSpawning.

  • Parameters:

    • matchEntity: The identifier for the match entity involved.
    • coordinates: An array of PositionData structures representing the coordinates for the pieces.
    • pieceEntities: An array of bytes32 values representing the piece entity IDs.
    • secret: A single bytes32 value representing the secret associated with the committed pieces.
  • Sample Code:

bytes32 matchEntity = 0x0000000000000000000000000000000000000000000000000000000000000001;

PositionData[] coordinates = new PositionData[](2);
coordinates[0] = PositionData(1, 1);  // Piece 1 position
coordinates[1] = PositionData(2, 2);  // Piece 2 position

bytes32[] pieceEntities = new bytes[](2);
pieceEntities[0] = 0x000000000000000000000000000000000000000000000000000000000000beef;  // Example piece entity
pieceEntities[1] = 0x000000000000000000000000000000000000000000000000000000000000cafe;  // Example piece entity

bytes32 secret = 0xabc123abc123abc123abc123abc123abc123abc123abc123abc123abc123abc1;


world.tacticsWar__revealSpawn(matchEntity, coordinates, pieceEntities, secret);

Note: The coordinates and pieceEntities arrays must match in length, as each piece corresponds to a specific position.


abortSpawn

function abortSpawn(bytes32 _matchEntity) public;
  • Aborts the game if the preparation time control for the specified match has passed. This function is used to ensure that games do not proceed if players are not ready within the designated preparation time.

  • The function checks whether the preparation time control has passed for the given match entity. If it has, the game is aborted.

  • Parameters:

    • matchEntity: The identifier for the match entity involved.
  • Sample Code:

bytes32 matchEntity = 0x000000000000000000000000000000000000000000000000000000000000beef;

world.tacticsWar__abortSpawn(matchEntity);

Note: The match can only be aborted if the preparation time control has passed. If the preparation time is still active, the function will not proceed.