Help:=proc(): print(` PSB(m,n), IP(m,n), RHM(S,B), Moves(S,B) , RG(S,B) , Cont(L,B) , AllGramesK(S,B) `):end: PSB:=proc(m,n) local i,j: { seq(seq([i,j],i=m+1..m+2*n-1),j=1..m), seq(seq([i,j],i=1..2*m+2*n-1),j=m+1..m+2*n-1), seq(seq([i,j],i=m+1..m+2*n-1),j=m+n+1..2*m+2*n-1)} end: IP:=proc(m,n): PSB(m,n) minus {[m+n,m+n]}: end: #RHM(S,B): Given a position S in a peg-solitaire with board B, all the right horizontal moves in Peg Solitaire RHM:=proc(S,B) local mo,s: mo:={}: for s in S do if member(s+[1,0],S) and (not member(s+[2,0],S)) and member(s+[2,0],B) then mo:=mo union {S minus {s,s+[1,0]} union {s+[2,0]}}: fi: od: mo: end: #LHM(S,B): Given a position S in a peg-solitaire with board B, all the left horizontal moves in Peg Solitaire LHM:=proc(S,B) local mo,s: mo:={}: for s in S do if member(s-[1,0],S) and (not member(s-[2,0],S)) and member(s-[2,0],B) then mo:=mo union {S minus {s,s-[1,0]} union {s-[2,0]}}: fi: od: mo: end: #UVM(S,B): Given a position S in a peg-solitaire with board B, all the up vertical moves in Peg Solitaire UVM:=proc(S,B) local mo,s: mo:={}: for s in S do if member(s+[0,1],S) and (not member(s+[0,2],S)) and member(s+[0,2],B) then mo:=mo union {S minus {s,s+[0,1]} union {s+[0,2]}}: fi: od: mo: end: #DVM(S,B): Given a position S in a peg-solitaire with board B, all the down vertical moves in Peg Solitaire DVM:=proc(S,B) local mo,s: mo:={}: for s in S do if member(s-[0,1],S) and (not member(s-[0,2],S)) and member(s-[0,2],B) then mo:=mo union {S minus {s,s-[0,1]} union {s-[0,2]}}: fi: od: mo: end: Moves:=proc(S,B):RHM(S,B) union LHM(S,B) union UVM(S,B) union DVM(S,B): end: #RG(S,B): a random game RG:=proc(S,B) local L,S1,mo: L:=[S]; S1:=S: while Moves(S1,B)<>{} do mo:=Moves(S1,B): S1:=mo[rand(1..nops(mo))()]: L:=[op(L),S1]: od: L: end: Cont:=proc(L,B) local la,gu,gu1: la:=L[-1]: gu:=Moves(la,B): {seq([op(L),gu1],gu1 in gu)} end: #AllGamesK(S,B,K) of length K AllGamesK:=proc(S,B,K) local gu,gu1: option remember: if K=0 then RETURN({[S]}): fi: gu:=AllGamesK(S,B,K-1): {seq(op(Cont(gu1,B)), gu1 in gu)}: end: