#OK to post homework #Yuxuan Yang, Jan 23rd, Assignment 1 #2 #For matrix(GameDB()[4]) #If the row player choose 1 and the col player choose 1, the payoff for them is 1 and 0 respectively #If the row player choose 1 and the col player choose 2, the payoff for them is 1 and 2 respectively #... #If the row player choose 2 and the col player choose 3, the payoff for them is 2 and 0 respectively #For matrix(GameDB()[5]) #If the row player choose 1 and the col player choose 1, the payoff for them is 0 and 4 respectively #If the row player choose 1 and the col player choose 2, the payoff for them is 4 and 0 respectively #If the row player choose 1 and the col player choose 3, the payoff for them is 5 and 3 respectively #... #If the row player choose 3 and the col player choose 3, the payoff for them is 6 and 6 respectively #4 #Using Rand2PlayerGame(3,3,3) #[[[0, 2], [2, 1], [0, 3]], [[1, 1], [2, 3], [3, 1]], [[0, 2], [3, 0], [3, 0]]] #[[[1, 2], [1, 1], [3, 3]], [[2, 2], [0, 1], [0, 3]], [[0, 1], [1, 2], [2, 3]]] #[[[1, 1], [3, 0], [0, 2]], [[3, 0], [1, 0], [1, 2]], [[3, 2], [2, 1], [0, 2]]] #After elimination #[[[0, 2], [2, 1], [0, 3]], [[1, 1], [2, 3], [3, 1]], [[0, 2], [3, 0], [3, 0]]] #[[[3, 3]]] #[[[3, 0], [1, 2]], [[3, 2], [0, 2]]] #5 #outputs a row that can be eliminated, or returns 0 FindDominatedRowStrategy:=proc(G) local i,j: for i from 1 to nops(G) do for j from 1 to nops(G) do if IsStrictDom([seq(G[i][k][1],k=1..nops(G[1]))],[seq(G[j][k][1],k=1..nops(G[1]))]) then RETURN(i): fi: od: od: 0: end: #outputs a column that can be eliminated, or returns 0 FindDominatedColumnStrategy:=proc(G) local i,j: for i from 1 to nops(G[1]) do for j from 1 to nops(G[1]) do if IsStrictDom([seq(G[k][i][2],k=1..nops(G))],[seq(G[k][j][2],k=1..nops(G))]) then RETURN(i): fi: od: od: 0: end: #6 ShrinkGame:=proc(G) local row,col,i,j: row:=FindDominatedRowStrategy(G): if row<>0 then RETURN([op(1..row-1,G),op(row+1..nops(G),G)]): else col:=FindDominatedColumnStrategy(G): if col<>0 then RETURN([seq([op(1..col-1,G[i]),op(col+1..nops(G[i]),G[i])],i=1..nops(G))]): fi: fi: G: end: ReducedGame:=proc(G) local G1,r1,r2,c1,c2,k: G1:=G: r1:=nops(G1): c1:=nops(G1[1]): for k from 1 to 1000 do G1:=ShrinkGame(G1): r2:=nops(G1): c2:=nops(G1[1]): if r2=r1 and c2=c1 then RETURN(G1): else r1:=r2: c1:=c2: fi: od: end: ################### C1.txt ############################ Help1:=proc(): print(` GameDB(), Rand2PlayerGame(a,b,K), IsDom(v1,v2), IsStictDom(v1,v2)`):end: #GameDB(): A list of length 5 consisiting of a a "data base" of famous games(and less famous ones): #Prisoner's dillema, Boattle of the Sexes, Matching pennies, Figure 1.1.1. in Gibbons, Figure 1.1.4 in Gibbons #For example, to see the Prisoner's dillema, type #matrix(GameDB()[1]) GameDB:=proc(): [ [ [[-1,-1],[-9,0]], [[0,-9],[-6,-6]]], [ [[2,1],[0,0]], [[0,0],[1,2]]], [ [[-1,1],[1,-1]], [[1,-1],[-1,1]]], [ [ [1,0],[1,2],[0,1]], [ [0,3],[0,1],[2,0]]], [ [ [0,4],[4,0],[5,3]],[ [4,0],[0,4],[5,3]], [ [3,5],[3,5],[6,6]]] ]: end: #added after class: #Rand2PlayerGame(a,b,K): A random 2-player (static) game where the Row player has a strategies (Row 1, .., Row a), the Column player has b strategies (Col. 1, ..., Crol. b) #and the pay-offs are from 0 to K. For example, to see a random game where Player Row has four strategy choices, and Player Column has five strategy choices #and the pay-offs are integers from 0 to 20 type: #matrix(Rand2PlayerGame(4,5,20)); Rand2PlayerGame:=proc(a,b,K) local ra,i,j: ra:=rand(0..K): [seq([seq([ra(),ra()],j=1..b)],i=1..a)]: end: #IsDom(v1,v2): Given two lists of numbers is v1[i]<=v2[i] for all i. For example #IsDom([1,3,2],[2,4,3]); should return true but IsDom([1,3,2],[2,4,1]); should return false IsDom:=proc(v1,v2) local i: for i from 1 to nops(v1) do if v1[i]>v2[i] then RETURN(false): fi: od: true: end: ##Added Jan. 23, 2022, thanks to comments by Lucy Martinez, Rebecca Embar, and George Spahn #IsStictDom(v1,v2): Given two lists of numbers is v1[i]<=v2[i] for all i. For example #IsStrictDom([1,3,2],[2,4,3]); should return true but IsDom([1,3,2],[2,4,1]); should return false IsStrictDom:=proc(v1,v2) local i: for i from 1 to nops(v1) do if v1[i]>=v2[i] then RETURN(false): fi: od: true: end: