︠bd3b9eea-1eec-4328-9535-f0ba44e5c2bci︠ %html

Code that defines a very simple function entitled "TwobyTwoNashEquilibria" and uses simple algebra to compute the equilibria for a 2 by 2 bi-matrix game.

︡44fd23b2-766b-4bca-a5bf-5fd88a7a170f︡{"html": "

Code that defines a very simple function entitled \"TwobyTwoNashEquilibria\" and uses simple algebra to compute the equilibria for a 2 by 2 bi-matrix game.

"}︡ ︠231d03db-788b-4ea9-a9ba-0cd5bbcfce46︠ def TwobyTwoNashEquilibria(A,B=0): "Computes the Equilibria for a general 2 by 2 bi matrix game defined by $(A,B)\in\mathbb{R}^{2\\times2}\\times\mathbb{R}^{2\\times 2}$. If B is omitted from input, a zero sum game is assumed." A=matrix(A) if B==0: B=-A else: B=matrix(B) if max(A[0]-A[1])<0: # This implies that the second row strategy dominates the first row strategy p=0 if B[1,0]<=B[1,1]: q=0 else: q=1 elif min(A[0]-A[1])>0: # This implies that the first row strategy dominates the second row strategy p=1 if B[0,0]<=B[0,1]: q=0 else: q=1 elif max(transpose(B)[0]-transpose(B)[1])<0: # This implies that the second column strategy dominates the first column strategy q=0 if A[0,1]<=A[1,1]: p=0 else: p=1 elif min(transpose(B)[0]-transpose(B)[1])>0: # This implies that the first column strategy dominates the second column strategy q=0 if A[0,0]<=A[1,0]: p=0 else: p=1 else: #This computes 0\n\n
\n \n

File: /tmp/tmpXNMwn5/___code___.py

\n

Type: <type ‘function’>

\n

Definition: TwobyTwoNashEquilibria(A, B=0)

\n

Docstring:

\n

Computes the Equilibria for a general 2 by 2 bi matrix game defined by (A,B)\\in\\mathbb{R}^{2\\times2}\\times\\mathbb{R}^{2\\times 2}. If B is omitted from input, a zero sum game is assumed.

\n\n\n
\n"}︡ ︠5c79813b-7624-47c4-bef0-a2e641638690i︠ %html

Obtaining the equilibria strategies for: matching pennies

︡26d2406a-4d79-461b-8fb3-ef352f46ad1c︡{"html": "

Obtaining the equilibria strategies for: matching pennies

"}︡ ︠7f9c7bc4-8641-43b6-9c50-beebf12376d7︠ TwobyTwoNashEquilibria([[1,-1],[-1,1]]) ︡7e6cc32d-9686-4b60-9cd8-6ae3dfb86bff︡{"stdout": "[(1/2, 1/2), (1/2, 1/2)]"}︡ ︠db3ff3d3-70a2-48b6-9f69-63bf0bb62f2fi︠ %html

Obtaining the equilibria strategies for: prisoner's dilemma

︡2e98e5c8-ac80-4a65-93e5-685631cc65c6︡{"html": "

Obtaining the equilibria strategies for: prisoner's dilemma

"}︡ ︠51f25728-58d3-4d81-b21b-6d5704ae0dc4︠ TwobyTwoNashEquilibria([[4,1],[5,2]],[[4,5],[1,2]]) ︡d10ca6ca-f751-4c6d-ae2b-4b424018ca1c︡{"stdout": "[(0, 1), (0, 1)]"}︡ ︠9a69a8e8-5276-42c2-886d-eedac1b32af8i︠ %html

Obtaining the equilibria strategies for the box kick game of this blog post.

︡959904a2-2c74-45b9-b25b-ad88c31fbc51︡{"html": "

Obtaining the equilibria strategies for the box kick game of this blog post.

"}︡ ︠b579b58e-7802-4377-9fb8-d30b012286ec︠ TwobyTwoNashEquilibria([[20,80],[95,70]]) ︡0290abc5-64e4-414b-af55-a0430cf4d146︡{"stdout": "[(5/17, 12/17), (2/17, 15/17)]"}︡