# configure BLAS and GLPK locations in Makefile.local
# note: if you don't do this, things will still compile, but
#  - BLAS makes CFR 3.5x faster
#  - GLPK is required for LP solving / computing the value of a game (accurately)
GS9673:zerosum.release kwaugh$ emacs Makefile.local

# compile
GS9673:zerosum.release kwaugh$ make
...

# lets check out Leduc
GS9673:zerosum.release kwaugh$ ./game_info 
usage: ./game_info [arguments]

arguments:
  -g --game=[game file]
  -c --chance
  -p --player
  -z --terminal
  -a --actions
  -i --info-sets
  -x --abstraction1=[abstraction]
  -y --abstraction2=[abstraction]
  -s --sequences
  -A --payoff-matrix
GS9673:zerosum.release kwaugh$ ./game_info --game=games/leduc.txt 
game name:     Leduc poker
histories:     1936
  chance:      46
  player:      774 (387 387)
  terminal:    1116
utility:       -13 13 26
info sets:     288 (144 144)
actions:       1935 (129 903 903)
root:          45
abstraction x: null
  sequences:   337
  info sets:   144
abstraction y: null
  sequences:   337
  info sets:   144

# how about Leduc with J.Q.K - JQ.K
GS9673:zerosum.release kwaugh$ ./game_info --game=games/leduc.txt --abstraction1=abstractions/J.Q.K-p0 --abstraction2=abstractions/JQ.K-p1
game name:     Leduc poker
histories:     1936
  chance:      46
  player:      774 (387 387)
  terminal:    1116
utility:       -13 13 26
info sets:     288 (144 144)
actions:       1935 (129 903 903)
root:          45
abstraction x: abstractions/J.Q.K-p0
  sequences:   232
  info sets:   99
abstraction y: abstractions/JQ.K-p1
  sequences:   155
  info sets:   66

# lets use CFR to compute a strategy in the J.Q.K-JQ.K game
# note that the output EV/epsilon is in terms of the abstract game
GS9673:zerosum.release kwaugh$ ./solve_regret --game=games/leduc.txt --x-abstraction1=abstractions/J.Q.K-p0 --y-abstraction2=abstractions/JQ.K-p1 --x=abstract-p0 --x-lifted=unabstracted-p0 --y=abstract-p1 --y-lifted=unabstracted-p1 --player1=cfr --player2=cfr --T=10000
t=1 ev=-0.078125 br0=2.0875 br1=2.61944 eps=2.54132
...
t=9998 ev=-0.0322242 br0=-0.0182682 br1=0.0457773 eps=0.013956
t=9999 ev=-0.0322242 br0=-0.0182748 br1=0.0457695 eps=0.0139494
t=10000 ev=-0.0322242 br0=-0.0182814 br1=0.0457605 eps=0.0139428
game's value = -0.0322242

# play the two abstract strategies against one and other
GS9673:zerosum.release kwaugh$ ./ev --game=games/leduc.txt --abstraction1=abstractions/J.Q.K-p0 --abstraction2=abstractions/JQ.K-p1 --x=abstract-p0 --y=abstract-p1 
# ev = -0.032343

# play the two unabstracted strategies against one and other
GS9673:zerosum.release kwaugh$ ./ev --game=games/leduc.txt --x=unabstracted-p0 --y=unabstracted-p1 
# ev = -0.032343

# best response to strategy in abstract game
GS9673:zerosum.release kwaugh$ ./best_response --game=games/leduc.txt --strategy=unabstracted-p0 --who=0 --abstraction2=abstractions/JQ.K-p1 
# best response value = 0.0440157

# best response to strategy in full game
GS9673:zerosum.release kwaugh$ ./best_response --game=games/leduc.txt --strategy=unabstracted-p0 --who=0
# best response value = 0.771366

#
# the rest of this stuff requires GLPK
#

# exploitability in abstract game
GS9673:zerosum.release kwaugh$ ./exploitability --game=games/leduc.txt --abstraction1=abstractions/J.Q.K-p0 --abstraction2=abstractions/JQ.K-p1 --strategy=abstract-p0 --who=0
# exploitability = 0.016496

# exploitability in full game
GS9673:zerosum.release kwaugh$ ./exploitability --game=games/leduc.txt --strategy=unabstracted-p0 --who=0
# exploitability = 0.68576

# solve the same abstract game with an LP
GS9673:zerosum.release kwaugh$ ./solve_eqm_lp --game=games/leduc.txt --abstraction1=abstractions/J.Q.K-p0 --abstraction2=abstractions/JQ.K-p1 --x=abstract-p0 --x-lifted=unabstracted-p0 --y=abstract-p1 --y-lifted=unabstracted-p1
game's value = -0.0275197

# evs / best responses / exploitabilities
GS9673:zerosum.release kwaugh$ ./ev --game=games/leduc.txt --abstraction1=abstractions/J.Q.K-p0 --abstraction2=abstractions/JQ.K-p1 --x=abstract-p0 --y=abstract-p1
# ev = -0.0275197
GS9673:zerosum.release kwaugh$ ./ev --game=games/leduc.txt --x=unabstracted-p0 --y=unabstracted-p1 
# ev = -0.0275197
GS9673:zerosum.release kwaugh$ ./best_response --game=games/leduc.txt --strategy=unabstracted-p0 --who=0 --abstraction2=abstractions/JQ.K-p1
# best response value = 0.0275216
GS9673:zerosum.release kwaugh$ ./best_response --game=games/leduc.txt --strategy=unabstracted-p0 --who=0
# best response value = 0.776239
GS9673:zerosum.release kwaugh$ ./exploitability --game=games/leduc.txt --abstraction1=abstractions/J.Q.K-p0 --abstraction2=abstractions/JQ.K-p1 --strategy=abstract-p0 --who=0
# exploitability = 1.94312e-06
GS9673:zerosum.release kwaugh$ ./exploitability --game=games/leduc.txt --strategy=unabstracted-p0 --who=0
# exploitability = 0.690633

# the script to create the Leduc game is in scripts/
GS9673:zerosum.release kwaugh$ less scripts/leduc.py
