#OK to post homework #Natalya Ter-Saakov, Jan 30, 2022, Assignment 2 read "C2.txt"; #Print first random matrix G1:= Rand2PlayerGame(2,3,7):matrix(G1[1]); BR1v(G1[1]); #The best response list for Player Row is [{2}, {1}, {1}]. BR2v(G1[1]); #The best response list for Player Column is [{3}, {3}]. #Print second random matrix G2:= Rand2PlayerGame(5,5,20): matrix(G2[1]); BR1v(G2[1]);BR2v(G2[1]); #The best response list for Player Row is [{4}, {4}, {5}, {1}, {5}] #The best response list for Player Column is [{3}, {1}, {5}, {3}, {3}] #Print third random matrix G3:= Rand2PlayerGame(3,3,3): matrix(G3[1]); BR1v(G3[1]);BR2v(G3[1]); #The best response list for Player Row is [{1, 2, 3}, {1, 3}, {2}] #The best response list for Player Column is [{1}, {1}, {1, 3}] #Print fourth random matrix G4:= Rand2PlayerGame(3,3,100): matrix(G4[1]); BR1v(G4[1]);BR2v(G4[1]); #The best response list for Player Row is [{1}, {3}, {3}] #The best response list for Player Column is [{2}, {2}, {3}] #Print fifth random matrix G5:= Rand2PlayerGame(6,6,100): matrix(G5[1]); BR1v(G5[1]);BR2v(G5[1]); #The best response list for Player Row is [{5}, {5}, {4}, {2}, {2}, {5}] #The best response list for Player Column is [{4}, {1}, {1}, {6}, {6}, {2}] #IsNash(G,a1,a2): inputs a 2-player game bi-matrix G, and members a1,a2 of A1, A2 respectively (that in our convention are integers from {1, ..., nops(G)} and {1, ..., nops(G[1])}) and outputs true or false according to whether [a1,a2] is a Nash Equilibrium. IsNash:= proc(G,a1, a2): if a1 in BR1(G,a2) and a2 in BR2(G,a1) then: return true fi: false: end: #PureNashEqui(G): inputs a bi-matrix G, and outputs the (possibly) emtpy set of pairs [a1,a2] that are (pure) Nash Equilibria. PureNashEqui:=proc(G) local a1,a2,nash: nash:={}: for a1 from 1 to nops(G) do: for a2 from 1 to nops(G[1]) do: if IsNash(G,a1,a2) then: nash := nash union {[a1,a2]}: fi: od: od: nash: end: PureNashEqui(GameDB(1)[1][1]); #This correctly identifies the Nash equilibrium of 'Prisoner's Dilemma': {[2, 2]} matrix(GameDB(1)[2][1]); PureNashEqui(GameDB(1)[2][1]); #This correctly identifies the Nash equilibria of 'Battle of the sexes':{[1, 1], [2, 2]} GN1:=Rand2PlayerGame(10,12,20): matrix(GN1[1]): PureNashEqui(GN1[1]); # {[7, 9]} GN2:=Rand2PlayerGame(10,12,20): matrix(GN2[1]): PureNashEqui(GN2[1]); # {[1, 12], [4, 3], [5, 4]} GN3:=Rand2PlayerGame(10,12,20): matrix(GN3[1]): PureNashEqui(GN3[1]); # {[1, 5], [4, 10], [8, 11], [9, 8]} GN4:=Rand2PlayerGame(10,12,20): matrix(GN4[1]): PureNashEqui(GN4[1]); # {[1, 6]} GN5:=Rand2PlayerGame(10,12,20): matrix(GN5[1]): PureNashEqui(GN5[1]); # {[2, 6], [5, 8], [7, 2], [9, 11], [10, 7]}