#C11.txt: Bearoff with Two players, Feb. 28, 2013 Help:=proc(): print(`LegalMoves(L,i), FW(L1,L2,r), fW(L1,L2,r,i), Exceptions3(N,j) `): end: #LegalMoves(L,i): inputs a list of length nops(L) #and a pos. integer i telling you that the option #to move any counter i pieces towards the end #without waste. And if you must waste, minimize it LegalMoves:=proc(L,i) local S, j: if i>nops(L) then RETURN(FAIL): fi: if L=[0$nops(L)] then RETURN({}): fi: S:={}: if L[i]>0 then S:=S union {[op(1..i-1,L),L[i]-1,op(i+1..nops(L),L)]}: fi: for j from i+1 to nops(L) do if L[j]>0 then #a counter distance j away goes to distance j-i away S:=S union {[op(1..j-i-1,L) , L[j-i]+1, op(j-i+1..j-1,L), L[j]-1, op(j+1..nops(L),L)]}: fi: od: if S<>{} then RETURN(S): fi: for j from i-1 by -1 to 1 while L[j]=0 do od: { [op(1..j-1,L),L[j]-1,op(j+1..nops(L),L)] }: end: #fW(L1,L2,r,i): The probability of L1 winning #if the roll was i, followed by the optimal move fW:=proc(L1,L2,r,i) local tom, champ,rec,mr: option remember: if L1=[0$nops(L1)] then RETURN(FAIL): fi: tom:=LegalMoves(L1,i): if tom={} then RETURN(FAIL): fi: champ:=tom[1]: rec:=1-FW(L2,champ,r): for mr in tom minus {tom[1]} do if 1-FW(L2,mr,r)>rec then champ:=mr: rec:=1-FW(L2,mr,r): fi: od: rec,champ: end: #FW(L1,L2,r): Probability of winning if your are about #to roll and your position is L1 and your opponent's #is L2 in a SINGLE r-faced fair die FW:=proc(L1,L2,r) local i: option remember: if L1=[0$nops(L1)] and L2<>[0$nops(L2)] then RETURN(1): fi: if L2=[0$nops(L2)] and L1<>[0$nops(L1)] then RETURN(0): fi: add(fW(L1,L2,r,i)[1], i=1..r)/r: end: Exceptions3:=proc(N,j) local i1,i2,i3,j1,j2,j3,gu,P,Pw,lu1,lu2: gu:={}: for i1 from 0 to N do for i2 from 0 to N-i1 do for i3 from 1 to N-i1-i2 do for j1 from 0 to N do for j2 from 0 to N-j1 do for j3 from 1 to N-j1-j2 do if f([i1,i2,i3],3,j)[1]<> fW([i1,i2,i3],[j1,j2,j3],3,j)[2] then print(`In position `,[[i1,i2,i3],[j1,j2,j3]], `the strategies conflict when the die rolled`, j): P:=f([i1,i2,i3],3,j)[1]: Pw:=fW([i1,i2,i3],[j1,j2,j3], 3,j)[2]: print(`according to the minimize-expected length, the optimal move is`): print(P): print(`according to the maximize the probability of winning, the optimal move is`): print(Pw): lu1:=evalf(F(Pw,3)-F(P,3)): print(`The increase in expected duration if you follow the latter is`, lu1): lu2:=evalf(FW([j1,j2,j3],P,3)-FW([j1,j2,j3],Pw,3)): print(`The loss of proba. of winning if you follow the former is`,lu2): gu:=gu union {[[i1,i2,i3],[j1,j2,j3], P,Pw,lu1,lu2]}: fi: od: od: od: od: od: od: gu: end: