# Demonstrates: a draw pile, a hand per player, hidden information, a secret choice, revealing,
# and a score result.
game: higher-lower
label: Higher or lower
players: "2 players"
num_players: 2
mode: competitive
summary: >
  Each player gets one face-down card (1 to 5, shuffled). Player 1 secretly says whether their
  card will turn out higher or lower than player 2's card; then both cards are revealed. A correct
  guess wins player 1 one point from player 2; a wrong guess does the reverse.

constants:
  CARDS: [1, 2, 3, 4, 5]

state:
  zones:
    # A shuffled, face-down pile: drawing from it is a chance node that nobody sees.
    deck: {kind: stack, owner: global, visibility: hidden, shuffled: true, init_x: "list(CARDS)"}
    # One hand per player, visible only to its owner. Path in ops: hand[0], hand[1].
    hand: {kind: set, owner: player, visibility: owner}
  vars:
    guess: {scope: global, type: str, init: ""}
    done: {scope: global, type: bool, init: false}

flow:
  id: round
  label: Round
  kind: sequence
  children:
    - {id: deal, label: Deal, kind: step, do: deal}
    - {id: guess, label: Guess, kind: step, actor: player 1, actor_x: "0", do: guess}
    - {id: reveal, label: Reveal, kind: step, do: reveal}

actions:
  deal:
    effect:
      # Drawing into hand[i]: only player i sees which card it was.
      - {op: draw, from: deck, to: "hand[0]", n: 1}
      - {op: draw, from: deck, to: "hand[1]", n: 1}
  guess:
    effect:
      # secret: only the actor sees the choice; the opponent only sees that a choice was made.
      - {op: choose, options: [higher, lower], bind: g, secret: true}
      - {op: set, var: guess, value_x: g}
  reveal:
    effect:
      - {op: reveal, what: cards, what_x: "[hand[0][0], hand[1][0]]"}
      - {op: set, var: done, value: true}

end:
  # score: a payoff per player. Zero-sum: +1 for one player is -1 for the other.
  - id: settle
    if: after the reveal
    if_x: done
    result: score
    returns_x: "[1, -1] if (guess == 'higher') == (hand[0][0] > hand[1][0]) else [-1, 1]"
