# Engine test: cooperative outcomes (mode: cooperative, a shared win or loss for the whole team).
game: coop-clock
label: Together against the clock
players: "2 players"
mode: cooperative
num_players: 2
summary: >
  Test game for co-op outcomes. Two players must score 9 points together within 3 rounds. On each
  turn the current player rolls either safe (1 or 2) or risky (0, 0, 3 or 4). The best choice
  depends on the score so far, so a good agent must reason for the team, not for itself.

constants:
  TARGET: 9
  ROUNDS: 3
  SAFE: [1, 2]
  RISKY: [0, 0, 3, 4]

state:
  vars:
    points: {scope: global, type: int, init: 0}
    round: {scope: global, type: int, init: 1}
    current: {scope: global, type: ref, init: 0}

flow:
  id: game
  label: Game
  kind: loop
  over: players
  over_x: players
  as: current
  until: "last round is over"
  until_x: "round > ROUNDS"
  children:
    - id: throw
      label: "Roll safe or risky"
      kind: step
      actor: current
      actor_x: current
      do: [safe, risky]

actions:
  safe:
    effect:
      - {op: roll, die: "safe: 1 or 2", die_x: SAFE, bind: x}
      - {op: add, var: points, amount_x: x}
      - op: if
        cond: "last player of the round"
        cond_x: "current == n_players - 1"
        then: [{op: add, var: round, amount: 1}]
  risky:
    effect:
      - {op: roll, die: "risky: 0, 0, 3 or 4", die_x: RISKY, bind: x}
      - {op: add, var: points, amount_x: x}
      - op: if
        cond: "last player of the round"
        cond_x: "current == n_players - 1"
        then: [{op: add, var: round, amount: 1}]

end:
  - {id: goal, check: immediate, if: "target reached", if_x: "points >= TARGET", result: win}
  - {id: time_up, check: immediate, if: "out of rounds", if_x: "round > ROUNDS", result: loss}
