Skip to content

Latest commit

 

History

History
40 lines (35 loc) · 986 Bytes

create-a-game.rst

File metadata and controls

40 lines (35 loc) · 986 Bytes

Create a Normal Form Game

A game in Nashpy is created by passing 1 or 2 matrices to the nash.Game class. Here is the zero sum game matching-pennies:

>>> import nashpy as nash
>>> import numpy as np
>>> A = np.array([[1, -1], [-1, 1]])
>>> matching_pennies = nash.Game(A)
>>> matching_pennies
Zero sum game with payoff matrices:
<BLANKLINE>
Row player:
[[ 1 -1]
 [-1  1]]
<BLANKLINE>
Column player:
[[-1  1]
 [ 1 -1]]

Here is the non zero sum game prisoners-dilemma:

>>> import nashpy as nash
>>> import numpy as np
>>> A = np.array([[3, 0], [5, 1]])
>>> B = np.array([[3, 5], [0, 1]])
>>> prisoners_dilemma = nash.Game(A, B)
>>> prisoners_dilemma
Bi matrix game with payoff matrices:
<BLANKLINE>
Row player:
[[3 0]
 [5 1]]
<BLANKLINE>
Column player:
[[3 5]
 [0 1]]