> For the complete documentation index, see [llms.txt](https://trident-cas.sabn.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trident-cas.sabn.xyz/games/dice.md).

# Dice

### Events

#### Client -> Server

**`dice:roll`**

Places a bet and rolls the dice instantly.

* **Payload**:

  ```json
  {
      "amount": 10.5, // Bet amount (USD)
      "percentage": 50, // Target percentage (1 to 99)
      "way": "over", // "over" or "under"
      "clientSeed": "user-provided-seed"
  }
  ```
* **Response**: `dice:roll` (Result)

#### Server -> Client

**`dice:roll` (Response)**

* **Payload (Success)**:

  ```json
  {
      "status": true,
      "won": true, // true if the player won, false if lost
      "rolled": 65.42, // The actual percentage rolled (0.00 to 99.99)
      "pf": {
          "serverSeed": "original-secret-hex", // Full server seed revealed immediately
          "serverSeedCommitment": "hash", // Hash of server seed
          "clientSeed": "user-provided-seed",
          "nonce": 1, // Deterministic random nonce
          "publicSeed": "block-id" // External EOS block hash
      }
  }
  ```
* **Payload (Error)**:

  ```json
  {
      "status": false,
      "message": "Insufficient balance" // Or "Invalid bet parameters", etc.
  }
  ```

***

### Game Logic Details

1. **Provably Fair**:
   * Uses `serverSeed`, `clientSeed`, `nonce`, and `publicSeed` (EOS block hash).
   * Derives a deterministic `Uint32` value using HMAC-SHA256.
   * Converts the integer to a float percentage between `0.00` and `99.99`.
   * Because Dice is resolved instantly in a single action, the `serverSeed` is revealed immediately in the `dice:roll` payload (no need for a separate `dice:proof` event).
2. **Concurrency Protection**:
   * Rolls are protected with a per-user `withQueue` sequential lock. This ensures that rapid-fire requests do not bypass balance deduction checks, preventing negative balances.
   * Rate limits are natively applied.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://trident-cas.sabn.xyz/games/dice.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
