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

# F014 — Multi-stage Betting

> Operator-configurable betting stages: ANTE-BET, PRE-FLOP, POST-FLOP, TURN

# F014 — Multi-stage Betting

| Field  | Value               |
| ------ | ------------------- |
| ID     | F014                |
| Phase  | 2 — Betting         |
| Jira   | HEDGE-133           |
| Status | TS ⬜ · JS ⬜ · UMA ✅ |

## Business Rule

Texas HedgeEm supports up to four betting windows, each corresponding to a game stage. The operator configures which stages are active at installation time.

**Available betting stages:**

| Stage name | When                   | Cards visible      | HedgeEm `dealStatus` |
| ---------- | ---------------------- | ------------------ | -------------------- |
| ANTE-BET   | Before any cards dealt | None               | Pre-deal (-1)        |
| PRE-FLOP   | After hole cards dealt | Hole cards only    | Hole (0)             |
| POST-FLOP  | After flop dealt       | Hole + 3 community | Flop (1)             |
| TURN       | After turn card dealt  | Hole + 4 community | Turn (2)             |

There is no betting window at the River — betting always closes before the final card is dealt.

**Default configuration:** POST-FLOP only (single betting stage). The operator can enable any combination of the four stages.

## Source: Game Concept Document

> "In its default configuration there is only one betting stage (POST-FLOP) but the operator can choose to enable other betting stages: ANTE-BET, PRE-FLOP, POST-FLOP, and TURN."

> "The configuration changes the gameplay experience to suit the target audience."

## Current Implementation vs Design Doc

The TypeScript standalone client currently implements **three betting stages** (PRE-FLOP / POST-FLOP / TURN, i.e. hole/flop/turn). This is intentional for the reference implementation — it showcases the full multi-stage betting experience. The POST-FLOP-only default from the design doc is for the simpler/faster operator configuration.

The JavaScript reference client at `hedgeem.qeetoto.com` should be audited to confirm which stages are active.

## Design Detail

### Per-stage bet display

When a player has placed bets across multiple stages on the same hand, each stage bet is shown as a **separate labelled row** below the chip:

```
£1.00 (x4.9)    ← bet placed at HOLE, locked odds 4.9
£1.00 (x10.4)   ← bet placed at FLOP, locked odds 10.4
```

The odds shown per row are the **locked odds at the time the bet was placed** (`recordedOdds`), not the current offered odds. The current offered odds are shown separately above the hand panel as `xN.N`.

**Implementation:** GDK `player.stages[]` array — one entry per committed bet, each `{ bet: pence, multiplier: recordedOdds }`. The game renders one labelled row per entry. A single `stages` entry with the accumulated total is incorrect — it collapses all stage rows into one and shows only the latest odds.

**Cancel behaviour:** Only uncommitted pending chips (placed in the UI but not yet POSTed to `/bet`) should be cancelled. Prior stage bets are locked and must not be affected by a cancel action at a later stage.

### Per-stage bet accumulation

Each bet is recorded with its stage at placement:

```typescript theme={null}
interface Bet {
    stage:       number;   // 0=hole(PRE-FLOP), 1=flop(POST-FLOP), 2=turn(TURN)
    handIndex:   number;
    stakeAmount: number;
    oddsAtBet:   number;   // odds locked at placement time
}
```

Bets from all active stages accumulate. At river, only the winning hand's bets across all stages are paid (F015).

### Ante-Bet stage

ANTE-BET (before hole cards) is not implemented in the current TS or JS clients. When implemented:

* No cards visible
* Odds would be equal for all hands (pure speculation, no information)
* `dealStatus = -1` — betting window added before `advance()` to hole

### Operator configuration scope

Configuring betting stages is an installation-time setting (F032), not a per-game or per-player option.

## JavaScript Reference

**JS Source:** Audit required to confirm which stages are active in the live JS client at `hedgeem.qeetoto.com`.

## TypeScript Implementation

**Current status:** Three betting stages active (hole/flop/turn = PRE-FLOP/POST-FLOP/TURN). Stage is enforced in `GameEngine.placeBet()`:

```typescript theme={null}
placeBet(handIndex: number, stakeAmount: number): boolean {
    if (this.dealStatus < 0 || this.dealStatus > 2) return false; // betting only at stages 0,1,2
    ...
}
```

ANTE-BET (`dealStatus = -1`) is not currently enabled.

## Acceptance Criteria

| #   | Criterion                                                     | JS | TS           | UMA |
| --- | ------------------------------------------------------------- | -- | ------------ | --- |
| AC1 | Bets can be placed at each configured active stage            | ⬜  | ✅ (3 stages) | ✅   |
| AC2 | Bets cannot be placed at river (`dealStatus = 3`)             | ⬜  | ✅            | ✅   |
| AC3 | Bets from all stages accumulate in `bets[]`                   | ⬜  | ✅            | ✅   |
| AC4 | Stage identifier stored with each bet for payout traceability | ⬜  | ✅            | ✅   |
| AC5 | Operator can configure POST-FLOP only (single stage)          | ⬜  | ⬜            | ⬜   |
| AC6 | ANTE-BET stage: betting before hole cards                     | ⬜  | ⬜            | ⬜   |

## Version Parity

| Version        | Status                         | Notes                                                                                                                                                                                                                                          |
| -------------- | ------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| JS (reference) | ⬜ Not audited                  | Live config unknown — audit required                                                                                                                                                                                                           |
| TS             | ⬜ Partial                      | 3 of 4 stages active; ANTE-BET not implemented                                                                                                                                                                                                 |
| UMA            | ✅ Playwright-tested 2026-04-15 | AC1–AC4 pass (7 tests). 3 stages active (HOLE/FLOP/TURN). Per-stage accumulation verified via `_lastStages`. River correctly has no betting window (`_gamePhase==='result'`). AC5/AC6 not tested (operator config + ANTE-BET not implemented). |

## Related Features

* F004 — Game Stages (stage definitions and transitions)
* F011 — Bet Placement (per-stage mechanics)
* F015 — Payout Calculation (bets from all stages resolved)
* F032 — RTP Config (operator stage configuration)
