COMP 2711H: Lecture 36

Date: 2024-11-25 08:43:58

Reviewed:

Topic / Chapter:

summary

❓Questions

Notes

Nim: Revisited
  • Nim: with 2 heaps

    • Nim: the game with decreasing numbers
    • property:
      • turn-based
      • finite
      • impartial
      • standard winning condition
    • if you can't make a move: you lose
      • 2 players
    • convert: game into a graph
  • Conversion

    • each vertex: state
      • if a state can reach , state exist
    • the graph: a DAG
      • πŸ‘¨β€πŸ« as the number of states are finite, it
    • a state : winning () if, starting from , player 1 wins
    • a state : losing () if, starting from , player 1 wins
      • πŸ‘¨β€πŸ« there is no way that no one wins!
graph LR
  0((W))
  1((W))
  2((L))
  3((L))
  4((W))
  5((W))
  6((L))
  0-->1; 0-->3;
  1-->2; 1-->5;
  3-->1; 3-->5;
  4-->0; 4-->3; 4-->5;
  5-->2; 5-->6;
  • rules
    • rule 0: if : no outgoing edges
      • then
    • rule 1: if s.t. and , then
      • optimal players!
    • rule 2: if s.t. , then
  • and: apply rules only if all its successors are covered
  • aka topological ordering: given a DAG , topological order:
    • permutation of vertices s.t. then appears before
    • πŸ‘¨β€πŸ« in our case, we want the reverse: thus, just inverse the order
  • theorem: every DAG has a topological order
  • Nim with heaps

    • with natural numbers:
      • each player: choosing a no. and decrease it in their turn
    • theorem: state of winning: depends on of all
        • intuition: you lose when too
    • suppose:
      • then player: changes to
      • e.g. initially:
        • then
      • similarly, means:
    • yet: showing existence of move leading to win is hard
      • for , there exists index s.t.
      • deduction resulting from XOR: always possible
        • πŸ‘¨β€πŸ« for the first encounter of in result, pick a number that is in that digit
  • Nim with 1 heap

    • e.g. when , its graph :
graph LR
    5((5))
    4((4))
    3((3))
    2((2))
    1((1))
    0((0))
    5-->4; 4-->3; 3-->2; 2-->1; 1-->0
    2-->0;
    3-->1; 3-->0;
    4-->2; 4-->1; 4-->0;
    5-->3; 5-->2; 5-->1; 5-->0;
  • and for heap: it's Cartesian product of each
  • Sprague–Grundy theorem
  • Sprague-Grundy theorem

    • every game: winning conditions can be found, like Nim
    • actually: you can convert any game into Nim!
    • assign a nimber to every vertex in each :
      • rule 0: if has no outgoing edge:
      • rule 1: otherwise:
    • there might be a case: where path exist and
      • πŸ‘¨β€πŸ« however, it doesn't really matter: the other player can undo the move!
        • thus, we can ignore this move!
    • and there is a corner case: where neighbors have the same nimber
      • which doesn't exist
  • Reverse Nim

    • w/ two natural numbers and two players
    • in each turn, a player can:
      • decrease
      • decrease
      • decrease both to
        • goal: not giving two equal numbers to opponents
      • πŸ‘¨β€πŸ« exercise: find for this game