# Engine test: choosing a subset (choose with min and max). The engine asks for it as a sequence
# of decisions, one item at a time, with 'done' once the minimum is reached.
game: subset
label: Knapsack (test)
num_players: 1
mode: competitive
description: >
  Test game for subset choices. Pick 1 to 3 of 5 items; the payoff is their total value if their
  weight stays within the carrying capacity, and 0 otherwise. The engine asks for the choice as a
  sequence: each item in a fixed order, or 'done'.
constants:
  ITEMS: [a, b, c, d, e]
  WEIGHT: {a: 4, b: 3, c: 2, d: 5, e: 1}
  VALUE: {a: 5, b: 4, c: 3, d: 6, e: 1}
  CAPACITY: 7
state:
  vars:
    chosen_items: {scope: global, type: list, init_x: "[]"}
    finished: {scope: global, type: bool, init: false}
  derived:
    weight: {text: total weight, x: "sum(WEIGHT[i] for i in chosen_items)"}
    value: {text: total value, x: "sum(VALUE[i] for i in chosen_items)"}
flow:
  id: root
  kind: sequence
  children:
    - {id: pack, kind: step, actor_x: "0", do: pack}
actions:
  pack:
    effect:
      - {op: choose, options_x: "ITEMS", min: 1, max: 3, bind: picks}
      - {op: set, var: chosen_items, value_x: "picks"}
      - {op: set, var: finished, value: true}
end:
  - {id: finished, if_x: "finished", result: score, returns_x: "[value if weight <= CAPACITY else 0]"}
