> ## Documentation Index
> Fetch the complete documentation index at: https://hedgeem-api.qeetoto.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Advance game

> Advances the game to the next stage:
- **Setup → Hole** — shuffles deck, deals two cards to each hand
- **Hole → Flop** — deals three community cards
- **Flop → Turn** — deals the turn card
- **Turn → River** — deals the river card, resolves winning hand, pays out bets
- **River → Setup** — clears the table for the next game

Odds are recalculated at each stage. Dead hands (cannot win) are marked.
Equivalent to `get_next_game_state_object` in the legacy C# server.




## OpenAPI

````yaml /openapi.yaml post /api/tables/{tableId}/advance
openapi: 3.0.0
info:
  title: Texas Hedge'Em API
  version: 0.4.0
  description: >
    REST API for Texas Hedge'Em v5 — a player-vs-house poker odds game.


    Players place bets on the odds of multiple simultaneous poker hands

    at three betting stages: **Hole**, **Flop**, and **Turn**.

    The River card determines the winning hand and pays out winners.


    **Base URL:** `https://hedgeem-server.qeetoto.com`


    **Authentication:** All endpoints except `/api/health` and `GET /api/tables`

    require a Supabase JWT passed as a Bearer token in the `Authorization`
    header.

    See [Authentication](/authentication) for details.


    **Two-balance wallet model:** Every player has two separate balances:

    `accountBalance` (funds in their lobby wallet) and `seatBalance` (chips on
    the

    felt at a specific table). Sit deducts from account; Leave credits seat back
    to

    account; Top-up transfers account → seat during a session.
  contact:
    url: https://github.com/texashedgeem/hedgeem-v5
  license:
    name: MIT
servers:
  - url: https://hedgeem-server.qeetoto.com
    description: Production (Vercel)
  - url: http://localhost:3000
    description: Local development
security:
  - bearerAuth: []
paths:
  /api/tables/{tableId}/advance:
    post:
      tags:
        - Tables
      summary: Advance game
      description: >
        Advances the game to the next stage:

        - **Setup → Hole** — shuffles deck, deals two cards to each hand

        - **Hole → Flop** — deals three community cards

        - **Flop → Turn** — deals the turn card

        - **Turn → River** — deals the river card, resolves winning hand, pays
        out bets

        - **River → Setup** — clears the table for the next game


        Odds are recalculated at each stage. Dead hands (cannot win) are marked.

        Equivalent to `get_next_game_state_object` in the legacy C# server.
      operationId: advanceGame
      parameters:
        - $ref: '#/components/parameters/tableId'
      responses:
        '200':
          description: Updated game state after advancing
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HedgeEmGameState'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
components:
  parameters:
    tableId:
      name: tableId
      in: path
      required: true
      description: Unique numeric table identifier
      schema:
        type: integer
        minimum: 1
        example: 1
  schemas:
    HedgeEmGameState:
      type: object
      description: |
        Full game state for a Texas Hedge'Em table at a point in time.
        This is the primary object consumed by the game client (gameClient/).
      properties:
        tableId:
          type: integer
          example: 1
        gameId:
          type: string
          example: game-001
        gameState:
          $ref: '#/components/schemas/GameState'
        bettingStage:
          $ref: '#/components/schemas/BettingStage'
        numberOfHands:
          type: integer
          description: Number of simultaneous hands in play (typically 4)
          example: 4
        numberOfSeats:
          type: integer
          description: Total seat capacity at this table
          example: 6
        jackpotValue:
          type: number
          description: Current jackpot value in chips
          example: 1250
        hands:
          type: array
          description: >
            The four hole card pairs as card strings (e.g. "AcKd").

            Null before STATUS_HOLE. See [Card
            Notation](/concepts/card-notation).
          items:
            type: string
            nullable: true
          example:
            - AcKd
            - QsJs
            - 8h7c
            - 5d2c
        flopCard1:
          type: string
          nullable: true
          description: First community card. Null before STATUS_FLOP.
          example: Ah
        flopCard2:
          type: string
          nullable: true
          example: 3s
        flopCard3:
          type: string
          nullable: true
          example: 9d
        turnCard:
          type: string
          nullable: true
          description: Turn card. Null before STATUS_TURN.
          example: null
        riverCard:
          type: string
          nullable: true
          description: River card. Null before STATUS_RIVER.
          example: null
        seats:
          type: array
          items:
            $ref: '#/components/schemas/HedgeEmSeat'
        bets:
          type: array
          description: All bets placed in the current game
          items:
            $ref: '#/components/schemas/HedgeEmBet'
        handOdds:
          type: array
          description: |
            Odds panel data for each hand at each betting stage.
            The game client uses this to render betting panels.
          items:
            $ref: '#/components/schemas/HedgeEmHandOdds'
    GameState:
      type: string
      description: |
        The lifecycle state of a Texas Hedge'Em game.
        States progress linearly: SETUP → START → HOLE → FLOP → TURN → RIVER.
      enum:
        - UNCHANGED
        - INVALID_CARD
        - CARD_ALREADY_DEALT
        - STATUS_SETUP
        - STATUS_START
        - STATUS_MANUAL_DEALING_HOLE
        - STATUS_HOLE
        - STATUS_FLOP_CARD1
        - STATUS_FLOP_CARD2
        - STATUS_FLOP_CARD3
        - STATUS_FLOP
        - STATUS_TURN
        - STATUS_RIVER
      example: STATUS_HOLE
    BettingStage:
      type: integer
      description: |
        The current betting stage.
        - `-1` NON_BETTING — no bets accepted (river, setup)
        - `0` HOLE — betting on hole cards
        - `1` FLOP — betting on flop cards
        - `2` TURN — betting on turn card
      enum:
        - -1
        - 0
        - 1
        - 2
      example: 0
    HedgeEmSeat:
      type: object
      properties:
        seatId:
          type: integer
          example: 1
        playerId:
          type: string
          description: Supabase auth UUID
          example: abc123
        playerName:
          type: string
          example: Simon
        seatBalance:
          type: number
          description: Chips currently at this seat
          example: 500
        avatarImageUrl:
          type: string
          example: /avatars/user_square.jpg
    HedgeEmBet:
      type: object
      properties:
        playerId:
          type: string
          example: abc123
        bettingStage:
          $ref: '#/components/schemas/BettingStage'
        seatIndex:
          type: integer
          description: Zero-based seat index
          example: 0
        handIndex:
          type: integer
          description: Zero-based hand index (0–3)
          minimum: 0
          maximum: 3
          example: 0
        betAmount:
          type: number
          example: 50
        recordedOdds:
          type: number
          description: The odds at the moment the bet was placed, used for payout
          example: 1.6
    HedgeEmHandOdds:
      type: object
      description: >
        Odds panel data for a single hand at a single betting stage.

        Used by the game client to render the 12 betting panels (4 hands × 3
        stages).
      properties:
        handIndex:
          type: integer
          minimum: 0
          maximum: 3
          example: 0
        bettingStage:
          $ref: '#/components/schemas/BettingStage'
        handStatus:
          $ref: '#/components/schemas/HandStatus'
        winPercentage:
          type: number
          description: Probability of this hand winning (0–100)
          example: 62.4
        drawPercentage:
          type: number
          description: Probability of a draw (0–100)
          example: 2.1
        odds:
          type: number
          description: |
            Payout odds. A bet of X returns X × odds.
            0.0 when the hand is Dead or in a non-betting stage.
          example: 1.6
    ApiError:
      type: object
      properties:
        error:
          type: string
          description: Human-readable error message
          example: Invalid tableId.
    HandStatus:
      type: string
      description: >
        The display status of a hand's betting panel at a given stage.

        Used by the game client to render panels appropriately.

        - `IN_PLAY_DEAD` — hand cannot win; no bets accepted

        - `IN_PLAY_WILL_WIN` — hand is guaranteed to win or draw; no bets
        accepted

        - `IN_PLAY_FAVOURITE` — leading hand; bets accepted at lower odds

        - `IN_PLAY_WINNER` — revealed winner at river
      enum:
        - UNDEFINED
        - IN_NON_BETTING_STAGE
        - IN_PLAY_PREVIOUS_BETTING_STAGE_NOT_ACTIVE
        - IN_PLAY_BETTING_STAGE_ACTIVE
        - IN_PLAY_DISABLED
        - IN_PLAY_DEAD
        - IN_PLAY_FAVOURITE
        - IN_PLAY_WILL_WIN
        - IN_PLAY_WINNER
      example: IN_PLAY_FAVOURITE
  responses:
    BadRequest:
      description: Invalid request parameters
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          example:
            error: betAmount must be a positive number.
    Unauthorized:
      description: Missing or invalid Bearer token
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          example:
            error: Missing or invalid Authorization header.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: Supabase Auth JWT. Obtain via Supabase Auth sign-in.

````