# yaml-language-server: $schema=../docs/tactic.schema.json
tactic: chess-material
label: "Material: take the most valuable piece, leave nothing hanging"
game: chess
summary: >
  Greedy player for the chess model: captures the most valuable piece, promotes, and does not
  leave a piece undefended on an attacked square. On a tie: give check. Looks no further than one
  move; checkmate only happens if it follows by chance from giving check.
let:
  value: "{'P': 1, 'N': 3, 'B': 3, 'R': 5, 'Q': 9, 'K': 0}"
  my_color: "COLOR[me]"
rules:
  - at: action move
    max_x: >-
      [(value.get((pieces.get(o['capture']) or '  ')[1], 0)
        + (value[o['promo'][1]] - 1 if o['promo'] else 0)
        - (value[(o['promo'] or o['piece'])[1]] if attacked(t, o['to'], enemy(my_color)) else 0),
        1 if attacked(t, king(t, enemy(my_color)), my_color) else 0)
       for t in [after(pieces, o)]][0]
