In [ ]:
import gambit
In [ ]:
gambit.__version__
In [ ]:
g = gambit.Game.read_game("poker.efg")
In [ ]:
# Serialisation of a game
g
In [ ]:
# Pythonic interface: access elements of a game via collections
g.players
In [ ]:
# Indexing works by text labels, if defined
g.players["Alice"]
In [ ]:
# Alice has two information sets - when she has the Ace, and when she has the King
g.players["Alice"].infosets
In [ ]:
# Nature is a special player
g.players.chance
In [ ]:
g.players.chance.infosets
In [ ]:
# Indexing collections can also be done by integer indices as well
g.players.chance.infosets[0].actions
In [ ]:
deal = g.players.chance.infosets[0]
In [ ]:
# For starters, we have assumed that Ace and King are equally likely
deal.actions["A"].prob
In [ ]:
deal.actions["K"].prob
In [ ]:
# Compute equilibria of the game via Lemke's algorithm
eqa = gambit.nash.lcp_solve(g)
In [ ]:
# We have a list of behaviour profiles
len(eqa)
In [ ]:
eqm = eqa[0]
In [ ]:
eqm
In [ ]:
# Can index behaviour profiles by player
eqm[g.players["Alice"]]
In [ ]:
eqm[g.players["Bob"]]
In [ ]:
# Can compute various interesting quantities about behaviour profiles as well
eqm.payoff(g.players["Alice"])
In [ ]:
# What does Bob believe about Alice's hand when she raises?
eqm.belief(g.players["Bob"].infosets[0].members[0])
In [ ]:
from IPython.display import display
probs = [ gambit.Rational(i, 20) for i in xrange(1, 20) ]
bluff = [ ]
belief = [ ]
payoff = [ ]
for prob in probs:
g.players.chance.infosets[0].actions[0].prob = prob
g.players.chance.infosets[0].actions[1].prob = 1-prob
eqa = gambit.nash.lcp_solve(g)
display("Prob of ace=%.2f" % float(prob), "Alice's strategy with king:", eqa[0][g.players["Alice"].infosets["k"]], "Bob's belief:", eqa[0][g.players["Bob"]])
bluff.append(eqa[0][g.players["Alice"].infosets["k"].actions["R"]])
belief.append(eqa[0].belief(g.players["Bob"].infosets[0].members[0]))
payoff.append(eqa[0].payoff(g.players["Alice"]))
In [ ]:
import pylab
In [ ]:
pylab.plot(probs, bluff, '-'); pylab.xlabel("Probability Alice gets ace"); pylab.ylabel("Probability Alice bluffs with king")
In [ ]:
pylab.plot(probs, payoff, '-'); pylab.xlabel("Probability Alice gets ace"); pylab.ylabel("Alice's equilibrium payoff")
In [ ]:
pylab.plot(probs, belief, '-'); pylab.xlabel("Probability Alice gets ace"); pylab.ylabel("Bob's equilibrium belief"); pylab.ylim(0,1)
In [ ]:
deal.actions[0].prob = gambit.Rational(1,2)
In [ ]:
deal.actions[1].prob = gambit.Rational(1,2)
In [ ]:
g
In [ ]:
g.outcomes["Alice wins big"]
In [ ]:
g.outcomes["Alice wins big"][0] = 3
In [ ]:
g.outcomes["Alice wins big"][1] = -3
In [ ]:
g.outcomes["Bob wins big"][0] = -3
In [ ]:
g.outcomes["Bob wins big"][1] = 3
In [ ]:
g
In [ ]:
eqa = gambit.nash.lcp_solve(g)
In [ ]:
len(eqa)
In [ ]:
eqa[0].payoff(g.players["Alice"])
In [ ]:
import gambit.gte
In [ ]:
print gambit.gte.write_game(g)
In [ ]:
|