###################################################################### ## FinitePoker.txt Save this file as FinitePoker.txt to use it, # # stay in the # # same directory, get into Maple (by typing: maple ) # ## and then type: read `FinitePoker.txt` # ## Then follow the instructions given there # ## # ## Written by Tipaluck Krityakierne, Thotsaporn "Aek" Thanatipanonda # #and Doron Zeilberger, Rutgers University , # ## DoronZeil at gmail dot com # ###################################################################### print(`First Written: June, 2024: tested for Maple 2020 `): print(`Version : June 14 2024 `): print(): print(`This is FinitePoker.txt, A Maple package`): print(`accompanying Tipaluck Krityakierne, Thotsaporn "Aek" Thanatipanonda, and Doron Zeilberger's article: `): print(` von Neumann and Newman pokers with Finite Decks`): print(` http://sites.math.rutgers.edu/~zeilberg/tokhniot/mamarim/mamarimhtml/poker.html `): print(): print(`The most current version is available on WWW at:`): print(` http://sites.math.rutgers.edu/~zeilberg/tokhniot/FinitePoker.txt .`): print(`Please report all bugs to: DoronZeil at gmail dot com .`): print(): print(`For general help, and a list of the MAIN functions,`): print(` type "ezra();". For specific help type "ezra(procedure_name);" `): print(`------------------------------`): print(`For a list of the supporting functions type: ezra1();`): print(): print(`------------------------------`): print(`For a list of the simulation functions type: ezraSi();`): print(`------------------------------`): print(`For a list of the Story functions type: ezraSt();`): print(`------------------------------`): print(`For a list of the Linear Programming procedures: ezraLP();`): print(`------------------------------`): with(combinat): with(simplex): ezraLP:=proc() if args=NULL then print(`The Linear Programming procedures are: Call, djnFastLP1, djnFastLP2, FastLP1, FastLP2, vnPseq `): print(``): else ezra(args): fi: end: ezraSt:=proc() if args=NULL then print(`The Story procedures (just for checking) are: djnMNEv, djnStory, djnStoryMixed, djnStory1, PayTableN, vnMNEv, vnStoryA, vnStory1, vnStory1a, vnStoryMixed , vnStoryMixedV `): print(``): else ezra(args): fi: end: ezraOld:=proc() if args=NULL then print(`The Old procedures (just for checking) are: BR1, BR2, MNEold, NEold, djnMNEold, vnMNEold `): print(``): else ezra(args): fi: end: ezra1:=proc() if args=NULL then print(`The SUPPORTING procedures are: EnS1S2, EnS1S2djn, MNE, NE, PayOffP1P2, PayTable, PayTableDJN, PayTableVNa, PnS1S2, SolveLP1, SolveLP2, Stra1, Stra1djn, Stra1VNa, Stra2, Stra2djn, Stra2VNa`): print(``): else ezra(args): fi: end: ezra:=proc() if args=NULL then print(` FinitePoker.txt: A Maple package for investigating simplified, von Neumann style Poker but for a FINITE Deck`): print(`The MAIN procedures are: djnNE, djnMNE, djnMNElist, vnMNE, vnMNEa , vnMNEh, vnNE, vnNEa, vnNEh `): elif nargs=1 and args[1]=BR1 then print(` BR1(n,S1,b): Inputs n, a positive integer, `): print(` and a subset S1 of {1,..,n} indicating `): print(` Player 1's strategy (bet if x in S1, check otherwise), `): print(` Output: the set of S2`): print(` that are the best response by player2, to S1. `): print(` b is the bet size.Try:`): print(` BR1(4,{1,4},2);`): elif nargs=1 and args[1]=BR2 then print(`BR2(n,S2,b): Inputs n, a positive integer, `): print(`and a subset S2 of {1,..,n} indicating `): print(`Player 2's strategy (call if y in S2, fold otherwise), `): print(`finds the set of S1 that are the best response to S2. `): print(`b is the bet size.Try:`): print(`BR2(4,{1,4},2);`): elif nargs=1 and args[1]=Call then print(`Call(i,j,c): `): print(``): print(` Input: card i of P1, card j of P2 and stake c`): print(` output: c if i>j and -c if iB for all 1<=AC" (fold otherwise)`): print(` Try: Stra2VNa(10);`): elif nargs=1 and args[1]=vnMNE then print(` vnMNE(n,b): ONE Mixed Nash equilbrium to the discrete von Neumann Poker with n cards {1,...,n}, and bet size b.`): print(`It outputs the quadruple [V,evalf(V), P1, P2] where V is the value, evalf(V) is V in decimals, `): print(`P1 is a list of length n where P1[x] is the probability that Player 1 shuold bet (rather then call) if his card is x`): print(`P2 is a list of length n where, in case Player 1 decided to bet, P2[y] is the probability that Player 2 shuold call (rather then fold) if his card is y. Try:`): print(` vnMNE(4,2);`): print(` vnMNE(4,3);`): print(` vnMNE(5,2);`): elif nargs=1 and args[1]=vnMNEa then print(` vnMNEa(n,b): ONE mixed Nash Equilibria [S1,S2] `): print(` with n cards and bet size b, where S1 `): print(` is Player 1's strategy and S2 is Player 2's strategy`): print(`BUT ONLY USING the suggested strategies`): print(` Try: vnMNEa(4,2);`): elif nargs=1 and args[1]=vnMNEh then print(` vnMNEh(n,b): ONE MIXED Nash Equilibrium [S1,S2] `): print(` with n cards and bet size b, where S1 `): print(` is Player 1's strategy and S2 is Player 2's strategy`): print(`BUT ONLY USING HONEST strategies`): print(` Try: vnMNEh(4,2);`): elif nargs=1 and args[1]=vnMNEv then print(` vnMNEv(n,b): Verbose form of vnMNE(n,b). Try:`): print(` vnMNEv(9,2);`): elif nargs=1 and args[1]=vnNE then print(` vnNE(n,b): all the "pure" Nash Equilibria [S1,S2] `): print(` with n cards and bet size b, for von Neumann poker where S1 `): print(` is Player 1's strategy (bet iff x is in S1) add S2 is Player 2's strategy (call iff y in S2)`): print(` Try: vnNE(4,2)`): elif nargs=1 and args[1]=vnNEa then print(` vnNEa(n,b): all the "pure" Nash Equilibria [S1,S2] `): print(` with n cards and bet size b, where S1 `): print(` is Player 1's strategy and S2 is Player 2's strategy`): print(`BUT ONLY USING the suggested strategies`): print(` Try: vnNEa(4,2);`): elif nargs=1 and args[1]=vnNEh then print(` vnNEh(n,b): all the "pure" Nash Equilibria [S1,S2] `): print(` with n cards and bet size b, where S1 `): print(` is Player 1's strategy and S2 is Player 2's strategy`): print(`BUT ONLY USING HONEST strategies`): print(` Try: vnNEh(4,2);`): elif nargs=1 and args[1]=vnPseq then print(`vnPseq(N): The integer sequenec whose n-th entry is the largest bet-size for which there exists a mixed Nash Equlibrium for von Neuman poker with n cards whose value for Player 1 is still positive`): print(`it also returns the set of pairs [betSize, NonZero Value]. try`): print(`vnPseq(10);`): elif nargs=1 and args[1]=vnStory then print(`vnStory(N,B1,B2): An article about Nash Equilibria of von Neumann Poker with number of cards from 2 to N and bet size from B1 to B2. Try:`): print(`vnStory(5,2,3);`): elif nargs=1 and args[1]=vnStory1 then print(`vnStory1(n,b): the story of von Neumann poker with n cards and bet size b. Each player puts an ante of 1 chip (so now the pot has 2 chips)`): print(`Each player gets a random card from a deck of n cards (with different numbers)`): print(`and of course they are different. Looking at his card, Player 1 decides whether to bet or check. If he checks, than the cards are compared`): print(`and whoever has the larger card gets the pot. If Player 1 bets, he puts b additional chips into the pot. Then`): print(`Player 2 has the option to fold, letting Player 1 collect the pot (and hence earning 1 chip)`): print(`or call. The cards are compared and whoever has the larger card gets the pot winning b+1 chips). :`): print(`vnStory1(7,2);`): elif nargs=1 and args[1]=vnStory1a then print(`vnStory1a(n,b): Like vnStory1(n,b) (q.v.) but only using the SUGGESTED strategies. Try"`): print(`vnStory1a(7,2);`): elif nargs=1 and args[1]=vnStoryA then print(`vnStoryA(N,B1,B2): Like vnStory(N,B1,B2) but only using suggested strategies. Try:`): print(`vnStoryA(5,2,3);`): elif nargs=1 and args[1]=vnStoryMixed then print(`vnStoryMixed(N,B1,B2): An article about Mixed Nash Equilibria of von Neumann Poker with number of cards from 2 to N and bet size from B1 to B2. Try:`): print(`vnStoryMixed(5,2,3);`): elif nargs=1 and args[1]=vnStoryMixedV then print(`vnStoryMixedV(N,B1,B2): An article about Mixed Nash Equilibria of von Neumann Poker with number of cards from 2 to N and bet size from B1 to B2. VERBOSE version. Try:`): print(`vnStoryMixedV(5,2,3);`): else print(`There is no such thing as`, args): fi: end: with(combinat): ######################### # Functions: # EnS1S2(n,S1,S2,b), # PnS1S2(n,S1,S2,b,t), # BR1(n,S1,b), # BR2(n,S2,b), # vnNE(n,b), # # My new part on mixed strategy: # Stra1(n), Stra2(n), # PayTable(n,b), # SolveLP1(M,V,P), SolveLP2(M,V,Q), # vnMNE(n,b), # ######################### #EnS1S2(n,S1,S2,b): inputs a positive integer n #and subsets S1 and S2 of {1,...,n} #outputs the expected gain for player 1 #if he follows startegy S1 (bet iff his card is in S1) #and player 2 follows strategy S2 (call iff y is in S2) #if the bet size is b. Try: #EnS1S2(4,{1,2},{1,4},2); EnS1S2:=proc(n,S1,S2,b) local i,x,y,Y,P: if not (type(n, integer) and type(S1,set) and type(S2,set) and S1 minus {seq(i,i=1..n)}={} and S2 minus {seq(i,i=1..n)}={} ) then print(`bad input`): RETURN(FAIL): fi: P := 0; for x from 1 to n do Y := {seq(i,i=1..n)} minus {x}; for y in Y do if member(x,S1) = false then if x > y then P := P+1; elif x y then P := P+b+1; elif x y then G := G+t; elif x y then G := G+t^(b+1); elif x Pay then Best := {S1}; Pay := EnS1S2(n,S1,S2,b); elif EnS1S2(n,S1,S2,b) = Pay then Best := Best union {S1}; fi: od: [Best,Pay]; end: # NEold(n,b): all the "pure" Nash Equilibria [S1,S2] # with n cards and bet size b, where S1 # is Player 1's strategy and S2 is Player 2's strategy # Try: NEold(4,2); NEold:=proc(n,b) local S1,S2,G,Nash,i; G := powerset({seq(i,i=1..n)}); Nash := {}; for S1 in G do for S2 in G do if member(S2,BR1(n,S1,b)[1]) and member(S1,BR2(n,S2,b)[1]) then Nash := Nash union {[S1,S2,BR2(n,S2,b)[2]]}; fi: od: od: Nash; end: # vnNE(n,b): all the "pure" Nash Equilibria [S1,S2] # with n cards and bet size b, where S1 # is Player 1's strategy and S2 is Player 2's strategy # Try: vnNE(4,2); vnNE:=proc(n,b) local M,S1,S2,gu,gu1: M:=PayTable(n,b): S1:=M[2]: S2:=M[3]: M:=M[1]: gu:=NE(M): {seq([S1[gu1[1][1]],S2[gu1[1][2]],gu1[2]],gu1 in gu)}: end: ######################################## # Solve for the mixed strategies # Stra1(n): Set of strategies of player 1 with n cards # Try: Stra1(3); Stra1:=proc(n) local i: option remember; [op(powerset({seq(i,i=1..n)}))]; end: # Stra2(n): Set of strategies of player 2 with n cards # Try: Stra2(3); Stra2 := proc(n) local i: option remember; [op(powerset({seq(i,i=1..n)}))]; end: #PayTable(n,b) # Input: number of card n and amount of bet b # Output: Payoff table as a 2^n-by-2^n list, together with the strategies of Player 1 and Player 2 # Try: # PayTable(2,2); PayTable:=proc(n,b) option remember; local i,j,A,B; A := Stra1(n); B := Stra2(n); [[seq([seq( EnS1S2(n,A[i],B[j],b),j=1..nops(B))],i=1..nops(A))],Stra1(n),Stra1(n)]; end: #SolveLP1(M,V,P) : # Input: Payoff matrix Matrix M, in a zero sum game, giving Player 1's payoff # Output: The optimal best # strategy (i.e mixed maximin) for P1 # Try: # Matching penny game: # SolveLP1([[100,-1],[-1,1]],V,P); # # M := PayTable(4,2)[1]: # SolveLP1(M,V,P); SolveLP1:=proc(M,V,P) local i,j,n,con1,con2: option remember: n := nops(M); con1 := {seq(add(M[i][j]*P[i],i=1..n)>=V,j=1..nops(M[1]))}; con2 := {seq(P[i]>=0,i=1..n),add(P[i],i=1..n)=1}; maximize(V,con1 union con2); end: # Input: Strategy Matrix M # Output: The optimal best # strategy (i.e. mixed minimax) for P2 # Try: # Matching pennies game: # SolveLP2([[100,-1],[-1,1]],V,Q); # # M := PayTable(4,2)[1]: # SolveLP2(M,V,Q); SolveLP2:=proc(M,V,Q) local i,j,n,con1,con2: option remember: n := nops(M[1]); con1 := {seq(add(M[i][j]*Q[j],j=1..n)<=V,i=1..nops(M))}; con2 := {seq(Q[i]>=0,i=1..n),add(Q[i],i=1..n)=1}; minimize(V,con1 union con2); end: #MNEold(n,b): Lile MNE(n,b) but older version. # Solution to discrete von Neuman Poker. #It outputs the mixed strategies and value, so the output is a list of length 3 #consisting of two lists of length 2^n followed by a number # Try: # MNEold(4,2); # MNEold(4,3); # MNEold(5,2); MNEold:=proc(n,b) local i,P,Q,M,S1,S2,V,gu1,gu2; #option remember; M := PayTable(n,b)[1]; S1 := SolveLP1(M,V,P); S2 := SolveLP2(M,V,Q); if subs(S1,V) <> subs(S2,V) then ERROR("Payoff should be equal"); fi: gu1:=subs(S1,[seq(P[i],i=1..2^n)]); gu2:=subs(S2,[seq(Q[i],i=1..2^n)]); print("Strategy for player 1 is", Stra1(n)); print("Strategy for player 2 is", Stra2(n)); print("The payoff at Nash Equilibrium is", S1[1]); print("The corresponding mixed strategy of Player 1 is", gu1); print("The corresponding mixed strategy of Player 2 is", gu2); print("Disclaimer: the solution to NE might not be unique. "); [gu1,gu2,subs(S1,V)]: end: #RM(m,n,K): RM(m,n,K) a random m by b matrix with entries from -K to K. Try: #RM(10,5,10); RM:=proc(m,n,K) local ra,i,j: ra:=rand(-K..K): [seq([seq(ra(),j=1..n)],i=1..m)]: end: #NE(M): inputs a payoff matrix M of a zero-sum game, , outputs the set of pure Nash equilibria. Try: #M:=RM(3,4,2): matrix(M); NE(M); NE:=proc(M) local m,n,i,j,br1,aluf, si,br2,JN: m:=nops(M): n:=nops(M[1]): for i from 1 to m do aluf:={1}: si:=M[i][1]: for j from 2 to n do if M[i][j]si then si:=M[i][j]: aluf:={i}: elif M[i][j]=si then aluf:=aluf union {i}: fi: od: br2[j]:=aluf: od: JN:={}: for i from 1 to m do for j from 1 to n do if member(j,br1[i]) and member(i,br2[j]) then JN:=JN union {[[i,j],M[i][j]]}: fi: od: od: JN: end: #MNE(M,ST1,ST2): inputs a Payoff matrix M, and lists ST1, ST2 of stragies (of length nops(M), and nops(M[1])) respectively). #Output ONE mixed strategy in the format [{[s1,ProbOfs1]}, {[s2,ProbOfs2]}], Value. Try: #M:=RM(4,7,10); S1:=[seq(i1,i1=1..4)}]; S2:=[seq(i1,i1=1..7)}]; MNE(M,S1,S2): MNE:=proc(M,ST1,ST2) local i,P,Q,S1,S2,V,gu1,gu2,lu1,lu2; S1 := SolveLP1(M,V,P); S2 := SolveLP2(M,V,Q); if subs(S1,V) <> subs(S2,V) then ERROR("Payoff should be equal"); fi: gu1:=subs(S1,[seq(P[i],i=1..nops(ST1))]): gu2:=subs(S2,[seq(Q[i],i=1..nops(ST2))]): RETRUN(gu1,gu2): lu1:={}: for i from 1 to nops(gu1) do if gu1[i]<>0 then lu1:=lu1 union {[ST1[i],gu1[i]]}: fi: od: lu2:={}: for i from 1 to nops(gu2) do if gu2[i]<>0 then lu2:=lu2 union {[ST2[i],gu2[i]]}: fi: od: [lu1,lu2,subs(S1,V)]: end: #vnMNEold(n,b) # Solution to discrete von Neuman Poker. #It outputs the mixed strategies and value, so the output is a list of length 3 #consisting of two lists of length 2^n followed by a number # Try: # vnMNEold(4,2); # vnMNEold(4,3); # vnMNEold(5,2); vnMNEold:=proc(n,b) local M,ST1,ST2; M:=PayTable(n,b): ST1:=M[2]: ST2:=M[3]: M:=M[1]: MNE(M,ST1,ST2): end: #vnStory1(n,b): the story of von Neumann poker with n cards and bet size b. Each player puts an ante of 1 chip (so now the pot has 2 chips) #Each player gets a random card from a deck of n cards (with different numbers) #and of course they are different. Looking at his card, Player 1 decides whether to bet or check. If he checks, than the cards are compared #and whoever has the larger card gets the pot. If Player 1 bets, he puts b additional chips into the pot. Then #Player 2 has the option to fold, letting Player 1 collect the pot (and hence earning 1 chip) #or call. The cards are compared and whoever has the larger card gets the pot winning b+1 chips). Try: #vnStory1(7,2); vnStory1:=proc(n,b) local gu,i,gu1,gu2,V1,V2: gu:=vnNE(n,b): print(`If the deck has`, n, `distinct cards and the bet size is`, b): print(``): if gu={} then print(`There are no pure Nash Equilibria `): else print(`There are`, nops(gu), `Nash equilibria `): print(`here they are`): fi: for i from 1 to nops(gu) do print(`NE number`, i): print(`Player 1 bets if his card is in the set`, gu[i][1], `and checks otherwise, while Player 2 calls if his card is in the set`, gu[i][2], `and folds otherwies , the value of the game is`,gu[i][3]): od: print(`Let's find ONE Mixed Nash Equilibrium`): gu1:=FastLP1(n,b): gu2:=FastLP2(n,b): V1:=gu1[1]: V2:=gu2[1]: if V1<>V2 then print(`Something bad happened`): RETURN(FAIL): fi: gu1:=gu1[2]: gu2:=gu2[2]: print(`Player 1's strategy is`): for i from 1 to nops(gu1) do print(`If Player 1 got card`, i, ` he should bet With probability`, gu1[i], `and check with probability`, 1-gu1[i]): od: print(`Player 2's strategy is`): for i from 1 to nops(gu2) do print(`If Player 2 got card`, i, ` he should call With probability`, gu2[i], `and fold with probability`, 1-gu2[i]): od: print(`The value of this pair of strategies is`, V1, `and in decmimals`, evalf(V1)): end: #vnStory(N,B1,B2): An article about Nash Equilibria of von Neumann Poker with number of cards from 2 to N and bet size from B1 to B2. Try: #vnStory(5,2,3); vnStory:=proc(N,B1,B2) local n,b,t0: t0:=time(): print(`All the Pure Nash Equiilbria, and ONE Mixed One, for von Neumann Poker with number of cards from 2 to`, N, `and bet sizes from`, B1, ` to`, B2): print(``): print(`By Shalosh B. Ekhad `): print(``): print(`Player 1 and Player 2 each get (different) cards from a deck of n cards numbered 1,..., n. They each see their own card, but not the other's `): print(``): print(`They each put 1 dollar in the pot`): print(``): print(`Player 1 can either check, in which case the cards are compared, and whoever has the larger card gets the pot (and hence wins 1 dollar), or bet an additional amount of b dollars`): print(``): print(`Now Player 2 can decide to cut his losses, and fold, and the pot goes immediately to player 1, who is going to make a dollar, and player 2 is going to lose a dollar`): print(``): print(`or else to also put b dollars in the pot`): print(``): print(`Now the cards are compared, and whoever has the larger card gets the pot, winning b+1 dollars (and the other player lost b+1 dollars`): print(``): print(`Here all the pure Nash Equilibria, and ONE Mixed one, for card sizes from 2 to`, N, `and bet sizes from` , B1, ` to`, B2): print(``): for n from 2 to N do print(`--------------------------------------------`): for b from B1 to B2 do print(`--------------------------------------------`): vnStory1(n,b): od: od: print(``): print(`-----------------`): print(``): print(`This ends this paper that took`, time()-t0, `seconds. `): print(``): end: #start von Nuemann only using the special candiate stratigies: check of AC, fold otherwise # Stra1VNa(n): Inputs a positive integer n, outputs the set of candiated startegies for Player 1 in von Nuemann poker with n cars of the form "bet if 1<=xB for all 1<=AC" (fold otherwise) # Try: Stra2VNa(10); Stra2VNa:=proc(n) local C,i: {seq({seq(i,i=C+1..n)},C=0..n-1)}: end: #PayTableVNa(n,b) # Input: number of card n and amount of bet b # Output: Payoff table only condidering the spcial types of strategies for Palyer 1 and Player 2, together with the strategies of Player 1 and Player 2 # Try: # PayTableVNa(2,2); PayTableVNa:=proc(n,b) option remember; local i,j,A,B; A := Stra1VNa(n); B := Stra2VNa(n); [[seq([seq( EnS1S2(n,A[i],B[j],b),j=1..nops(B))],i=1..nops(A))],A,B]; end: # vnNEa(n,b): all the "pure" Nash Equilibria [S1,S2] # with n cards and bet size b, where S1 # is Player 1's strategy and S2 is Player 2's strategy #BUT ONLY USING the suggested strategies # Try: vnNEa(4,2); vnNEa:=proc(n,b) local M,S1,S2,gu,gu1: M:=PayTableVNa(n,b): S1:=M[2]: S2:=M[3]: M:=M[1]: gu:=NE(M): {seq([S1[gu1[1][1]],S2[gu1[1][2]],gu1[2]],gu1 in gu)}: end: # vnMNEa(n,b): ONE mixed Nash Equilibria [S1,S2] # with n cards and bet size b, where S1 # is Player 1's strategy and S2 is Player 2's strategy #BUT ONLY USING the suggested strategies # Try: vnMNEa(4,2); vnMNEa:=proc(n,b) local M,ST1,ST2; M:=PayTableVNa(n,b): ST1:=M[2]: ST2:=M[3]: M:=M[1]: MNE(M,ST1,ST2): end: #vnStory1a(n,b): Like vnStory1(n,b) but only using the SUGGESTED strategies. Try: #vnStory1a(7,2); vnStory1a:=proc(n,b) local gu,i,gu1,gu2: gu:=vnNEa(n,b): print(`If the deck has`, n, `distinct cards and the bet size is`, b): print(``): if gu={} then print(`There are no pure Nash Equilibria, using the SUGGESTED STRATEGIES `): else print(`There are`, nops(gu), `Nash equilibria `): print(`here they are`): fi: for i from 1 to nops(gu) do print(`NE number`, i): print(`Player 1 bets if his card is in the set`, gu[i][1], `and checks otherwise, while Player 2 calls if his card is in the set`, gu[i][2], `and folds otherwies , the value of the game is`,gu[i][3]): od: print(`Let's find ONE Mixed Nash Equilibrium`): gu:=vnMNEa(n,b): gu1:=gu[1]: gu2:=gu[2]: print(`Player 1's strategy is`): for i from 1 to nops(gu1) do print(`With with probability`, gu1[i][2], ` bet iff his card belongs to the set`, gu1[i][1] ): od: print(`Player 2's strategy is`): for i from 1 to nops(gu2) do print(`With with probability`, gu2[i][2], ` call iff his card belongs to the set`, gu2[i][1] ): od: print(`The value of this pair of strategies is`, gu[3], `and in decmimals`, evalf(gu[3])): end: #vnStoryA(N,B1,B2): Like vnStory(N,B1,B2): but only using SUGGESTED strategies. Try: #vnStoryA(5,2,3); vnStoryA:=proc(N,B1,B2) local n,b,t0: t0:=time(): print(`All the Pure Nash Equiilbria, and ONE Mixed One, for von Neumann Poker with number of cards from 2 to`, N, `and bet sizes from`, B1, ` to`, B2): print(`USING SUGGESTED STRATEGIES ONLY`): print(``): print(`By Shalosh B. Ekhad `): print(``): print(`Player 1 and Player 2 each get (different) cards from a deck of n cards numbered 1,..., n. They each see their own card, but not the other's `): print(``): print(`They each put 1 dollar in the pot`): print(``): print(`Player 1 can either check, in which case the cards are compared, and whoever has the larger card gets the pot (and hence wins 1 dollar), or bet an additional amount of b dollars`): print(``): print(`Now Player 2 can decide to cut his losses, and fold, and the pot goes immediately to player 1, who is going to make a dollar, and player 2 is going to lose a dollar`): print(``): print(`or else to also put b dollars in the pot`): print(``): print(`Now the cards are compared, and whoever has the larger card gets the pot, winning b+1 dollars (and the other player lost b+1 dollars`): print(``): print(`Here all the pure Nash Equilibria, and ONE Mixed one, for card sizes from 2 to`, N, `and bet sizes from` , B1, ` to`, B2): print(``): for n from 2 to N do print(`--------------------------------------------`): for b from B1 to B2 do print(`--------------------------------------------`): vnStory1a(n,b): od: od: print(``): print(`-----------------`): print(``): print(`This ends this paper that took`, time()-t0, `seconds. `): print(``): end: #Start DJ Newman poker #Stra1djn(n,b): The set of possible strategies for Player 1 in DJ Newman poker with n cards where if you card is x you bet B[x] dollars #and you can bet from 0 to b #The output is the set of (b+1)^n lists of length n with entries in {0,...,b}. Try: #Stra1djn(4,3); Stra1djn:=proc(n,b) local gu,gu1,i: option remember: if n=0 then RETURN({[]}): fi: gu:=Stra1djn(n-1,b): {seq(seq([op(gu1),i],gu1 in gu),i=0..b)}: end: #Stra2djn(n,b): The set of possible strategies for Player 2 in DJ Newman poker a subset of {0,...,b} indicating those where he would call. Try: #Stra2djn(3,2); Stra2djn:=proc(n,b) local i,S,s,gu,gu1: option remember: S:=powerset({seq(i,i=1..n)}): if b=0 then RETURN({seq([s], s in S)}): fi: gu:=Stra2djn(n,b-1): {seq(seq([op(gu1),s],s in S), gu1 in gu)}: end: #EnS1S2djn(n,b,S1,S2): inputs a positive integers n and b #and DJ Newman strategies S1 (for player 1) and S2 (for player 2) #outputs the expected gain for player 1 #if he follows startegy S1 (bet S1[x] if his card is x)) #and player 2 follows strategy call iff y belongs to S2[b+1]. Try #EnS1S2djn(4,3,[0,1,3,0],{2,3}); EnS1S2djn:=proc(n,b,S1,S2) local b1,x,y,Y,P,i: if not (type(n, integer) and type(S1,list) and type(S2,list) and nops(S2)=b+1 and nops(S1)=n ) then print(`bad input`): RETURN(FAIL): fi: P := 0; for x from 1 to n do b1:=S1[x]: Y := {seq(i,i=1..n)} minus {x}; for y in Y do if member(y,S2[b1+1]) then if x>y then P:=P+b1+1: else P:=P-(b1+1): fi: else P:=P+1: fi: od: od: P/(n*(n-1)); end: #PayTableDJN(n,b) # Input: number of card n and the maximal allowed bet b (player 1 can bet integers from 0 to b) # Output: Payoff table of a (b+1)^n*2^(b+1) matrix (list of lists), together with the strategies of Player 1 and Player 2 # Try: # PayTableDJN(2,2); PayTableDJN:=proc(n,b) option remember; local i,j,A,B; A := Stra1djn(n,b); B := Stra2djn(n,b); [[seq([seq( EnS1S2djn(n,b,A[i],B[j]),j=1..nops(B))],i=1..nops(A))],A,B]; end: # djnNE(n,b): all the "pure" Nash Equilibria [S1,S2] # with n cards max bet size b for Player 1 for DJ Newman poker, # where S1 # is Player 1's strategy and S2 is Player 2's strategy # Try: djnNE(3,2); djnNE:=proc(n,b) local M,S1,S2,gu,gu1: M:=PayTableDJN(n,b): S1:=M[2]: S2:=M[3]: M:=M[1]: gu:=NE(M): {seq([S1[gu1[1][1]],S2[gu1[1][2]],gu1[2]],gu1 in gu)}: end: #djnMNEold(n,b) # ONE Mixed Nash Equilibrium for DJ Newman poker with n cards and max. bet size b # Try: #djnMNE(3,2); djnMNEold:=proc(n,b) local M,ST1,ST2; M:=PayTableDJN(n,b): ST1:=M[2]: ST2:=M[3]: M:=M[1]: MNE(M,ST1,ST2): end: #djnStory1(n,b): the story of DJ Newman poker with n cards and max bet size b. #djnStory1(3,1); djnStory1:=proc(n,b) local gu,i,gu1,gu2: gu:=djnNE(n,b): print(`If the deck has`, n, `distinct cards and the alloawed bet sizes for Player 1 are from 0 dolalrs to`, b, `dollars `): print(``): if gu={} then print(`There are no pure Nash Equilibria `): else print(`There are`, nops(gu), `Nash equilibria `): print(`here they are`): fi: for i from 1 to nops(gu) do print(`NE number`, i): print(`Player 1 bets the following amounts according to his card value `, gu[i][1], `while Player 2 calls if his card is in the b+1 entry of he list`, gu[i][2], `and folds otherwies , the value of the game is`,gu[i][3]): od: print(`Let's find ONE Mixed Nash Equilibrium`): gu:=djnMNE(n,b): gu1:=gu[1]: gu2:=gu[2]: print(`Player 1's strategy is`): for i from 1 to nops(gu1) do print(`With with probability`, gu1[i][2], `have the betting table, according to his number cards`, gu1[i][1] ): od: print(`Player 2's strategy is`): for i from 1 to nops(gu2) do print(`With with probability`, gu2[i][2], ` have the calling table (according to the proposed bet, starting at 0)`, gu2[i][1] ): od: print(`The value of this pair of strategies is`, gu[3], `and in decmimals`, evalf(gu[3])): end: #djnStory(N,B): An article about Equilibria of DJ Newman Poker with number of cards from 2 to N and max bet size from 1 to B. Try: #djnStory(4,2); djnStory:=proc(N,B) local n,b,t0: t0:=time(): print(`All the Pure Nash Equiilbria, and ONE Mixed One, for DJ Newman Poker with number of cards from 2 to`, N, `and maximum bet sizes from`, 1, ` to`, B): print(``): print(`By Shalosh B. Ekhad `): print(``): print(`Player 1 and Player 2 each get (different) cards from a deck of n cards numbered 1,..., n. They each see their own card, but not the other's `): print(``): print(`They each put 1 dollar in the pot`): print(``): print(`Player 1 can bet any whole dollar amount from 0 to`, B): print(``): print(`Now Player 2 can decide to have a counter bet (i,e, call) or fold, and concede the pot to Player 1. If he decides to call then`): print(``): print(`The cards are compared, and whoever has the larger card gets the pot, winning b+1 dollars (and the other player lost b+1 dollars`): print(``): print(`Here all the pure Nash Equilibria, and ONE Mixed one, for card sizes from 2 to`, N, `and bet sizes from 1 to`, B ): print(``): for n from 2 to N do print(`--------------------------------------------`): for b from 1 to B do print(`--------------------------------------------`): djnStory1(n,b): od: od: print(``): print(`-----------------`): print(``): print(`This ends this paper that took`, time()-t0, `seconds. `): print(``): end: #Start FAST LP ################################################## #FastLP1(n,b) # Fast Linear programming for discrete number of cards # Input: number of card n and amount of bet b # Output: List of optimal payoff and vector # strategy of P1 # Please check these solution with vnStory of Dr.Z # Try: FastLP1(13,2); FastLP1:=proc(n,b) option remember; local i,j,S,p,V,P,con1,con2,con3,A; # p= raise, 1-p=check S := {seq(j,j=1..n)}; # con1 = Player 2 calls con1 := {seq(add( +Call(i,j,b+1)*p[i] +Call(i,j,1)*(1-p[i]) ,i in S minus {j})/(n-1)>=V[j],j=1..n)}; # con2 = Player 2 folds con2 := {seq(add( p[i]+Call(i,j,1)*(1-p[i]) ,i in S minus {j})/(n-1)>=V[j],j=1..n)}; con3 := {seq(p[i]>=0,i=1..n),seq(p[i]<=1,i=1..n)}; P := add(V[j]/n,j=1..n); A:=maximize(P,con1 union con2 union con3); subs(A,[P,[seq(p[i],i=1..n)]]); end: #FastLP2(n,b): # Input: number of card n and amount of bet b # Output: List of optimal payoff and vector # strategy of P2 # Please check these solution with vnStory of Dr.Z # Try: # FastLP1(13,2); FastLP2(13,2); FastLP2 := proc(n,b) option remember; local i,j,S,q,V,P,con1,con2,con3,A; #q=call, 1-q=fold S := {seq(i,i=1..n)}; # con1 = Player1 checks con1 := {seq(add(Call(i,j,1),j in S minus {i})/(n-1)<=V[i],i=1..n)}; # con2 = Player1 raises con2 := {seq(add(Call(i,j,b+1)*q[j]+(1-q[j]) ,j in S minus {i})/(n-1)<=V[i],i=1..n)}; con3 := {seq(q[j]>=0,j=1..n),seq(q[j]<=1,j=1..n)}; P := add(V[i],i=1..n)/n; A := minimize(P-10^(-15)*add(j*q[j],j=1..n) # substract small extra term to make output looks nice ,con1 union con2 union con3); subs(A,[P,[seq(q[j],j=1..n)]]); end: ############################################# # Input: card i of P1, card j of P2 and stake c # output: c if i>j and -c if i j then return(c); elif i < j then return(-c); else ERROR("CheckInput"); fi: end: #END FAST LP #PayTableN(n,b): Like PayTable(n,b) but with row and column headings # Try: # PayTableN(2,2); PayTableN:=proc(n,b) local i,j,A,B,B1; A := Stra1(n); B := Stra2(n); B1:=[` ` ,op(B)]: [B1, seq([A[i],seq( EnS1S2(n,A[i],B[j],b),j=1..nops(B))],i=1..nops(A))]; end: #PayOffP1P2(n,b,P1,P2): inputs a positive integer n #and lists of probabilities P1 and P2 of length n describing #mixed strategies for player 1 and player 2 #outputs the expected gain for player 1 #Try: #PayOffP1P2(4,2,[1/2,0,0,1],[1,1/2,0,1/2]) ; PayOffP1P2:=proc(n,b,P1,P2) local x,y,P: if not (type(n, integer) and type(P1,list) and type(P2,list) and nops(P1)=n and nops(P2)=n) then print(`bad input`): RETURN(FAIL): fi: P:=add(add( (1-P1[x]) ,y=1..x-1), x=1..n)-add(add( (1-P1[x]) ,y=x+1..n), x=1..n) +add(add(P1[x]*(1-P2[y]),y=1..x-1),x=1..n)+add(add(P1[x]*(1-P2[y]),y=x+1..n),x=1..n) +(b+1)*add(add(P1[x]*P2[y],y=1..x-1),x=1..n)-(b+1)*add(add(P1[x]*P2[y],y=x+1..n),x=1..n): P/(n*(n-1)); end: #vnPseq(N): The integer sequenec whose n-th entry is the largest bet-size for which there exists a mixed Nash Equlibrium for von Neuman poker with n cards whose value for Player 1 is still positive #it also returns the set of pairs [betSize, NonZero Value]. try #vnPseq(10); vnPseq:=proc(N) local n1,gu,b,lu: gu:=[0]: lu:=[[0,0]]: for n1 from 2 to N do for b from 1 while FastLP1(n1,b)[1]<>0 do od: lu:=[op(lu),[b-1,FastLP1(n1,b-1)[1]]]: gu:=[op(gu),b-1]: od: gu,lu: end: #vnStoryMixed(N,B1,B2): An article about Mixed Nash Equilibria of von Neumann Poker with number of cards from 2 to N and bet size from B1 to B2. Try: #vnStoryMixed(5,2,3); vnStoryMixed:=proc(N,B1,B2) local n,b,t0,P1,P2,V1,V2: t0:=time(): print(`One Mixed Nash Equiilbrium for von Neumann Poker with number of cards from 2 to`, N, `and bet sizes from`, B1, ` to`, B2): print(``): print(`By Shalosh B. Ekhad `): print(``): print(`Player 1 and Player 2 each get (different) cards from a deck of n cards numbered 1,..., n. They each see their own card, but not the other's `): print(``): print(`They each put 1 dollar in the pot`): print(``): print(`Player 1 can either check, in which case the cards are compared, and whoever has the larger card gets the pot (and hence wins 1 dollar), or bet an additional amount of b dollars`): print(``): print(`Now Player 2 can decide to cut his losses, and fold, and the pot goes immediately to player 1, who is going to make a dollar, and player 2 is going to lose a dollar`): print(``): print(`or else to also put b dollars in the pot`): print(``): print(`Now the cards are compared, and whoever has the larger card gets the pot, winning b+1 dollars (and the other player loses b+1 dollars`): print(``): print(`Here is ONE Mixed one, for card sizes from 2 to`, N, `and bet sizes from` , B1, ` to`, B2): print(``): print(`For each number of cards n, and bet size, we list:`): print(``): print(` the Player 1 strategy, as a list of length n, let's call it, P1, telling the player that if he got card number x, he should bet with prob. P1[x] and check otherwise.`): print(``): print(` the Player 2 strategy, as a list of length n, let's call it, P2, telling the player that if he got card number y, he should call with prob. P2[y] and fold otherwise.`): print(``): print(`We also list the value, that we call V`): for n from 2 to N do print(`--------------------------------------------`): print(`The deck has`, n, ` cards `): print(``): for b from B1 to B2 do print(`--------------------------------------------`): P1:=FastLP1(n,b): P2:=FastLP2(n,b): V1:=P1[1]: V2:=P2[1]: if V1<>V2 then RETURN(FAIL): fi: print(``): print(`For bet size `, b, `we have that [V,evalf(V), P1,P2] are`): lprint([V1,evalf(V1), P1[2],P2[2]]): print(``): od: od: print(``): print(`----------------------------`): print(``): print(`This ends this paper that took`, time()-t0, `seconds to generate. `): print(``): end: #ez:=proc()print(`The main procedures are: djnFastLP1(n,b) and djnFastLP2(n,b)`):print(`The supporting procedure is Call(i,j,c), Choice1(b) `):end: ################################################## #djnFastLP1(n,b) # Fast Linear programming for a finite number of cards # Input: number of card n and maximal amount of bet b # Output: List of optimal payoff and an n by (b+1) matrix # P1[x,b] such that if he gets card x, he should bet the amount i # with prob. P1[x,i] # Try: djnFastLP1(4,2); # djnFastLP1(20,3); djnFastLP1 := proc(n,b) option remember; local i,j,s,S,p,V,P,con1,con2,con3,A,X,Y; # p[i][0]= check, p[i][s]= raise with amount s+1 S := {seq(j,j=1..n)}; X := {seq(s,s=0..b)}; # con1 = Player 2 calls/fold for each option of betting s>=1 con1 := {seq(seq(add( add( Call(i,j,s+1)*p[i][s],s in Y) +add( p[i][s],s in (X minus Y)) ,i in S minus {j})/(n-1)>=V[j],j=1..n), Y in Choice1(b))}; con2 := {seq(seq(p[i][s]>=0,s=0..b),i=1..n), seq(add(p[i][s],s=0..b)=1,i=1..n)}; P := add(V[j]/n,j=1..n); A:=maximize(P -10^(-15)*add(add(i*s*p[i][s],s=0..b),i=1..n) # add this extra term to make the NE looks nice. ,con1 union con2); subs(A,[P,[seq([seq(p[i][s],s=0..b)],i=1..n)]]); end: # Input: number of card n and amount of bet b # Output: List of optimal payoff and a strategy for Player 2: # a matrix P2[y,b] that tells him that if he gets card y, #and the bet size given by Player 1 is b # call with prob. P2[y,b] and fold with prob. 1-P2[y,b] # Try: # djnFastLP1(4,2); djnFastLP2(4,2); # djnFastLP1(20,3); djnFastLP2(20,3); djnFastLP2:=proc(n,b) option remember; local i,j,s,S,q,V,P,con1,con2,A; #q[y][b]=call, 1-q[y][b]=fold S := {seq(i,i=1..n)}; # con1 = Player1 checks or raises with various values con1 := {seq(seq(add(Call(i,j,s+1)*q[j][s]+(1-q[j][s]) ,j in S minus {i})/(n-1)<=V[i],i=1..n),s=0..b)}; con2 := {seq(q[j][0]=1,j=1..n), seq(seq(q[j][s]>=0,s=1..b),j=1..n), seq(seq(q[j][s]<=1,s=1..b),j=1..n)}; P := add(V[i],i=1..n)/n; A := minimize(P-10^(-15)*add(add(j*s*q[j][s],s=1..b),j=1..n) # substract small extra term to make output looks nice ,con1 union con2); subs(A,[P,[seq([seq(q[j][s],s=0..b)],j=1..n)]]); end: ############################################# # Supporting function to give the possible choices # of call/fold of each card. # Try: Choice1(2); Choice1 := proc(b) option remember; local T; if b = 0 then return({{0}}); fi: {seq( T union {b}, T in Choice1(b-1))} union Choice1(b-1); end: #vnMNE(n,b): ONE mixed Nash equilbrium for von Neumann poker with a deck of n cards {1,..,n} and bet-size b. Try: #vnMNE(9,2); vnMNE:=proc(n,b) local gu1,gu2,V1,V2: gu1:=FastLP1(n,b): gu2:=FastLP2(n,b): V1:=gu1[1]: V2:=gu2[1]: if V1<>V2 then print(`Something is wrong`): RETURN(FAIL): fi: [V1,evalf(V1),gu1[2],gu2[2]]: end: #vnMNEv(n,b): Verbose form of vnMNE(n,b) spelling out advice for both players vnMNEv:=proc(n,b) local gu,P1,P2,S1bet,S1check,S1p,x,y,S2fold, S2call, S2p: gu:=vnMNE(n,b): print(``): print(`-----------------------------------------------------------------`): print(``): print(` (Mixed) Nash Equlibrium for von Neumann Poker with`, n , `cards and fixed bet-size`, b): print(``): print(`Player 1 and Player 2 are each dealt diffrent cards from`, {seq(x,x=1..n)}, `. They can see their own cards but, of course, not their opponent's. They each put 1 dollar in the pot.`): print(``): print(`Player 1 can decide to check, in which case the cards are compared and whoever has the larger card wins the pot, and the game is over.`): print(``): print(`Player 1 can also decide to bet, in which he places`, b, `dollars in the pot, and the game goes to Player 2.`): print(``): print(`Player 2 can decide to fold, and forfeit his money, losing one dollar, and the game ends, or else he can decide to call, putting his own`, b, `dollars, and the cards are compared,`): print(``): print(`and whoever has the larger card takes the whole pot.`): print(``): print(`We will describe ONE mixed strategy that is a Nash Equilibrium.`): print(``): print(`The value (to Player1) of the game is`, gu[1], `and in decimal`, gu[2]): print(``): P1:=gu[3]: P2:=gu[4]: S1bet:={}: S1check:={}: S1p:={}: for x from 1 to n do if P1[x]=0 then S1check:=S1check union {x}: elif P1[x]=1 then S1bet:=S1bet union {x}: else S1p:=S1p union {x}: fi: od: print(`If Player 1's card is in the following set then he should DEFINITELY check`): print(``): print(S1check): print(``): print(`If Player 1's card is in the following set then he should DEFINITELY bet`): print(``): print(S1bet): print(``): for x in S1p do print(`If his card is`, x, `then he should bet with probability`, P1[x], `and check with probability`, 1-P1[x]): print(``): od: S2call:={}: S2fold:={}: S2p:={}: for y from 1 to n do if P2[y]=0 then S2fold:=S2fold union {y}: elif P2[y]=1 then S2call:=S2call union {y}: else S2p:=S2p union {y}: fi: od: print(`If Player 2's card is in the following set then he should DEFINITELY call`): print(``): print(S2call): print(``): print(`If Player 2's card is in the following set then he should DEFINITELY fold`): print(``): print(S2fold): print(``): for y in S2p do print(`If his card is`, y, `then he should call with probability`, P2[y], `and fold with probability`, 1-P2[y]): print(``): od: end: #djnMNE(n,b): ONE mixed Nash equilbrium for von Neumann poker with a deck of n cards {1,..,n} and bet-size b. Try: #djnMNE(9,2); djnMNE:=proc(n,b) local gu1,gu2,V1,V2: option remember: gu1:=djnFastLP1(n,b): gu2:=djnFastLP2(n,b): V1:=gu1[1]: V2:=gu2[1]: if V1<>V2 then print(`Something is wrong`): RETURN(FAIL): fi: [V1,evalf(V1),gu1[2],gu2[2]]: end: #djnMNEv(n,b): Verbose form of djnMNE(n,b) spelling out advice for both players djnMNEv:=proc(n,b) local gu,P1,P2,lu,b1,i,x,y,S2call,S2fold: gu:=djnMNE(n,b): print(``): print(`-----------------------------------------------------------------`): print(``): print(` (Mixed) Nash Equlibrium for DJ Newman Poker with`, n , `cards and allowed bets in`, {seq(i,i=0..b)}): print(``): print(`Player 1 and Player 2 are each dealt diffrent cards from`, {seq(x,x=1..n)}, `. They can see their own cards but, of course, not their opponent's. They each put 1 dollar in the pot.`): print(``): print(`Looking at his card, Player 1 decides what amount to bet (including 0 dollars, that is the same as checking)`): print(``): print(`Looking at his card, and Player1's bet size, Player 2 can decide to fold, and forfeit his money, losing one dollar, and the game ends, or else he can decide to call, putting the same amount as Player 1, and the cards are compared,`): print(``): print(`and whoever has the larger card takes the whole pot.`): print(``): print(`We will describe ONE mixed strategy that is a Nash Equilibrium.`): print(``): print(`The value (to Player1) of the game is`, gu[1], `and in decimal`, gu[2]): print(``): P1:=gu[3]: P2:=gu[4]: for x from 1 to n do lu:=P1[x]: if convert(lu,set) minus {0,1}={} then for b1 from 0 to b while lu[b1+1]=0 do od: print(`If Player 1 has card`, x, `then he should bet`, b1, `dollars `): else print(`if Player 1 has card`, x): for b1 from 0 to b do if lu[b1+1]<>0 then print(`He should bet`,b1, `dollars with prob.`, lu[b1+1]): fi: od: fi: od: print(``): print(`------------------`): print(``): for y from 1 to n do print(`If Player 2 has card`, y): lu:=P2[y]: if convert(lu,set) minus {0,1}={} then S2call:={}: S2fold:={}: for b1 from 0 to b do if lu[b1+1]=0 then S2fold:=S2fold union {b1}: elif lu[b1+1]=1 then S2call:=S2call union {b1}: fi: od: if S2call<>{} then print(`Player 2 should definitely call if Player 1's bet belongs to`, S2call): fi: if S2fold<>{} then print(`Player 2 should definitely fold if Player 1's bet belongs to`, S2fold): fi: else for b1 from 0 to b do print(`If the bet size is`, b1, `then Player 2 should call with prob.`, lu[b1+1], `and fold with prob.`, 1-lu[b1+1]): od: fi: od: print(``): print(`-----------------------------------`): print(``): end: #vnStoryMixedV(N,B1,B2): Verbose form of vnStoryMixed(N,B1,B2). try: #vnStoryMixedV(5,2,3); vnStoryMixedV:=proc(N,B1,B2) local n,b,t0,P1,P2,V1,V2: t0:=time(): print(`One Mixed Nash Equiilbria for von Neumann Poker with number of cards from 2 to`, N, `and bet sizes from`, B1, ` to`, B2): print(``): print(`By Shalosh B. Ekhad `): print(``): print(`Player 1 and Player 2 each get (different) cards from a deck of n cards numbered 1,..., n. They each see their own card, but not the other's `): print(``): print(`They each put 1 dollar in the pot`): print(``): print(`Player 1 can either check, in which case the cards are compared, and whoever has the larger card gets the pot (and hence wins 1 dollar), or bet an additional amount of b dollars`): print(``): print(`Now Player 2 can decide to cut his losses, and fold, and the pot goes immediately to player 1, who is going to make a dollar, and player 2 is going to lose a dollar`): print(``): print(`or else to also put b dollars in the pot`): print(``): print(`Now the cards are compared, and whoever has the larger card gets the pot, winning b+1 dollars (and the other player loses b+1 dollars`): print(``): print(`Here is ONE Mixed one, for card sizes from 2 to`, N, `and bet sizes from` , B1, ` to`, B2): print(``): print(`For each number of cards n, and bet size, we list:`): print(``): print(` the Player 1 strategy, as a list of length n, let's call it, P1, telling the player that if he got card number x, he should bet with prob. P1[x] and check otherwise.`): print(``): print(` the Player 2 strategy, as a list of length n, let's call it, P2, telling the player that if he got card number y, he should call with prob. P2[y] and fold otherwise.`): print(``): print(`We also list the value, that we call V`): for n from 2 to N do print(`--------------------------------------------`): print(`The deck has`, n, ` cards `): print(``): for b from B1 to B2 do print(`--------------------------------------------`): vnMNEv(n,b): od: od: print(`This ends this paper that took`, time()-t0, `seconds to generate. `): print(``): end: #djnStoryMixed(N): doing djnMNE(n,b) for n from 1 to N, and b up to the saturation value. Try #djnStoryMixed(5); djnStoryMixed:=proc(N) local n,gu,t0,b: t0:=time(): print(`One Mixed Nash Equiilbrium for DJ Newman Poker with number of cards from 2 to`, N, `and max. bets until the saturation value`): print(``): print(`By Shalosh B. Ekhad `): print(``): for n from 2 to N do print(`--------------------------------------------`): print(`The deck has`, n, ` cards `): print(``): gu:=djnMNElist(n): for b from 1 to nops(gu) do print(`--------------------------------------------`): djnMNEv(n,b): od: od: print(`This ends this paper that took`, time()-t0, `seconds to generate. `): print(``): end: ###start Honest strategies #PayTableVNh(n,b) # Input: number of card n and amount of bet b # Output: Payoff table only condidering the spcial HONEST types of strategies for Palyer 1 and Player 2, together with the strategies of Player 1 and Player 2 # Try: # PayTableVNh(2,2); PayTableVNh:=proc(n,b) option remember; local i,j,A,B; A := Stra2VNa(n): B := Stra2VNa(n): [[seq([seq( EnS1S2(n,A[i],B[j],b),j=1..nops(B))],i=1..nops(A))],A,B]; end: # vnNEh(n,b): all the "pure" Nash Equilibria [S1,S2] # with n cards and bet size b, where S1 # is Player 1's strategy and S2 is Player 2's strategy #BUT ONLY USING the HONEST strategies # Try: vnNEh(4,2); vnNEh:=proc(n,b) local M,S1,S2,gu,gu1: M:=PayTableVNh(n,b): S1:=M[2]: S2:=M[3]: M:=M[1]: gu:=NE(M): {seq([S1[gu1[1][1]],S2[gu1[1][2]],gu1[2]],gu1 in gu)}: end: #vnMNEh(n,b) # Solution to discrete von Neuman Poker. for HONEST stragetgies #It outputs the mixed strategies and value, so the output is a list of length 3 #consisting of two lists of length 2^n followed by a number # Try: # vnMNEh(5,2); vnMNEh:=proc(n,b) local M,ST1,ST2; M:=PayTableVNh(n,b): ST1:=M[2]: ST2:=M[3]: M:=M[1]: MNE(M,ST1,ST2): end: ###End Honest strategies #djnNMElist(n): The list djnNME(n,b) for b from 1 until it is the same as the next one. Try: #djnMNElist(4); djnMNElist:=proc(n) local gu,b: gu:=[djnMNE(n,1)]: for b from 2 while djnMNE(n,b)[1]<> djnMNE(n,b-1)[1] do gu:=[op(gu),djnMNE(n,b)]: od: gu: end: