####################################################################### ##ConnectFour: Save this file as ConnectFour To use it, stay in the # ##same directory, get into Maple (by typing: maple ) # ##and then type: read ConnectFour : # ##Then follow the instructions given there # ## # ##Written by Doron Zeilberger, Rutgers University , # #zeilberg at math dot rutgers dot edu # ####################################################################### #First Posted: Feb. 1, 2008 print(`Created: Feb. 1, 2008`): print(` This is ConnectFour `): print(`to Play, and especially create interesting and challenging Connect-Four End-Game Problems.`): print(`written by Doron Zeilberger.`): print(): print(`It was used to automatically create Shalosh B. Ekhad's marvelous Web-Book`): print(`One Hundred and Twenty Connect-Four End-Game Problems, E-published in `): print(` http://www.math.rutgers.edu/~zeilberg/C4/C4.html `): print(``): print(`Please report bugs to zeilberg at math dot rutgers dot edu`): print(``): print(`The most current version of this package and the book`): print(` are available from`): print(`http://www.math.rutgers.edu/~zeilberg .`): print(`For a list of the procedures type ezra();, for help with`): print(`a specific procedure, type ezra(procedure_name); .`): print(``): print(`VERY IMPORTANT: M, N, and K are global variables. Do not use them for anything else`): print(`M is the number of columns, N is the number of rows, and K is the`): print(`"four" in "Connect-Four". To play "Connect-Three" change K in the`): print(`line below to 3, to play "Connect-Five" Change it to 5, etc.`): print(` You are welcome to re-set, at the very beginning, after loading the program`): print(` M:=DesiredNumberOfColumns: N:=DesiredNumberOfRows: K:=DesiredValueOfWinningLength`): M:=7: N:=6: K:=4: with(combinat): with(plots): ezra:=proc(): if nargs=0 then print(`To play connect-k on an M by N board`): print(`Contains procedures: BlackMoves,`): print(`BlackWon, DrawPos, IsGoodProb, `): print(`HopeLessB1, HopeLessR1, HopeLessB2,`): print(` HopeLessR2, HopeLessB3, HopeLessR3`): print(`MakeAprob, MakeProbs, MakeGoodProbs1, MakeGoodProbs2 `): print(`MakeGoodProbs3 `): print(` MakeProb1, ProveRk, RandGameC, RandGameN, RandGameNv, RedGoodMoves`): print(` RedMoves, RedWon, Sefer30P, Upgrade, Upgrades,`): print(` WinAdBk, WinAdRk, WinBk `): print(` WinRk, WinRkAll `): elif nargs=1 and args[1]=BlackMoves then print(`BlackMoves(POS): The set of Red's moves `): elif nargs=1 and args[1]=BlackWon then print(`BlackWon(POS): Did Red win? `): elif nargs=1 and args[1]=DrawPos then print(`DrawPos(POS): draws a position POS `): elif nargs=1 and args[1]=HopeLessB1 then print(`HopeLessB1(P): Is the position such that whatever`): print(`Black will do, Red can win in <=one move?`): elif nargs=1 and args[1]=HopeLessR1 then print(`HopeLessR1(P): Is the position such that whatever`): print(`Red will do, Red can win in <=one move?`): elif nargs=1 and args[1]=HopeLessB2 then print(`HopeLessB2(P): Is the position such that whatever`): print(`Black will do, Red can win in <=2 moves?`): elif nargs=1 and args[1]=HopeLessR2 then print(`HopeLessR2(P): Is the position such that whatever`): print(`Red will do, Red can win in <=2 moves?`): elif nargs=1 and args[1]=HopeLessB3 then print(`HopeLessB3(P): Is the position such that whatever`): print(`Black will do, Red can win in <=3 moves?`): elif nargs=1 and args[1]=HopeLessR3 then print(`HopeLessR3(P): Is the position such that whatever`): print(`Red will do, Red can win in <=3 moves?`): elif nargs=1 and args[1]=IsGoodProb then print(`IsGoodProb(P,k): Is the position P a good problem`): print(`for win-for-red-in k-moves?`): elif nargs=1 and args[1]=MakeAprob then print(`MakeAprob(m,R,Gvul): Makes one problem of the kind "Red can win in`): print(`R moves", if possible, starting with a position with m white`): print(`and m black checkers in the connect-four board`): print(`trying Gvul number of times. The number of problems is a surprise`): print(`For example, try:`): print(`MakeAprob(6,2,200);`): elif nargs=1 and args[1]=MakeGoodProbs1 then print(`MakeGoodProbs1(k,m,L,Gvul): Makes L good problems of`): print(` win-in-k-moves with m checkers of each color.`): print(`by first doing problems with k-1 moves and than upgrading once`): print(` For example, try: MakeGoodProbs1(3,8,4,200);`): elif nargs=1 and args[1]=MakeGoodProbs2 then print(`MakeGoodProbs2(k,m,L,Gvul): Makes L good problems of`): print(` win-in-k-moves with m checkers of each color.`): print(`by first doing problems with k-2 moves and than upgrading twice`): print(` For example, try: MakeGoodProbs2(3,8,4,200);`): elif nargs=1 and args[1]=MakeGoodProbs3 then print(`MakeGoodProbs3(k,m,L,Gvul): Makes L good problems of`): print(` win-in-k-moves with m checkers of each color.`): print(`by first doing problems with k-3 moves and than upgrading three times`): print(` For example, try: MakeGoodProbs3(3,8,4,200);`): elif nargs=1 and args[1]=MakeProb1 then print(`MakeProb1(m,R): Tries to make a problem Red-Can-Win in R-moves`): print(`R moves, starting with a position with m white`): print(`and m black checkers in the connect-four board`): print(`trying Gvul number of times`): print(`For example, try:`): print(`MakeProb1(7,2);`): elif nargs=1 and args[1]=MakeProbs then print(`MakeProbs(k,m,L,Gvul): Makes L problems of`): print(` win-in-k-moves with m checkers of each color.`): print(` For example, try: MakeProbs(3,8,4,200);`): elif nargs=1 and args[1]=ProveRk then print(`ProveRk(P,k, Shem,i):`): print(`Finds the winning move of Red for a win-in-k moves`): print(`and gives a formal proof. Shem is the name, and i is the level`): print(`(upper-level has i=0)`): print(`For exapmpe, try:`): print(`ProveRk(Pr2[1],2,1,0);`): elif nargs=1 and args[1]=RandGameC then print(`RandGameC(k): A random game `): print(`until one of the players can win on k moves `): elif nargs=1 and args[1]=RandGameN then print(`RandGameN(): A random Naive game `): elif nargs=1 and args[1]=RandGameNv then print(`RandGameNv(): A random Naive game, verbose version `): elif nargs=1 and args[1]=RedGoodMoves then print(`RedGoodMoves(POS,k): all the moves of Red that do not`): print(`lead to Black winning in k moves`): elif nargs=1 and args[1]=RedWon then print(`RedWon(POS): Did Red win? `): elif nargs=1 and args[1]=RedMoves then print(`RedMoves(POS): The set of Red's moves `): elif nargs=1 and args[1]=Sefer30P then print(`Sefer30P(S):Given a set of 30 problems S, does the`): print(`pictorial part`): elif nargs=1 and args[1]=Upgrade then print(`Upgrade(P,R): Given a position P that is win for white`): print(`in R moves, outputs one that is win in R+1 moves`): elif nargs=1 and args[1]=Upgrades then print(`Upgrades(P,R): Given a position P that is win for white`): print(`in R moves, outputs all unmoves that are wins in R+1 moves`): elif nargs=1 and args[1]=WinAdBk then print(`WinAdBk(POS,k): The smallest i<=k such that POS is Win with <=i`): print(`moves for Black followed by the set of good moves`): elif nargs=1 and args[1]=WinAdRk then print(`WinAdRk(POS,k): The smallest i<=k such that POS is Win with <=i`): print(`moves for Red followed by the set of good moves`): elif nargs=1 and args[1]=WinB1 then print(`WinB1(P): Can Black Win in one move?, followed by the winning move`): elif nargs=1 and args[1]=WinB2 then print(`WinB2(P): Can Black Win in two moves?, followed by the winning move`): elif nargs=1 and args[1]=WinR1 then print(`WinR1(P): Can Red Win in one move?, followed by the winning move`): elif nargs=1 and args[1]=WinR2 then print(`WinR2(P): Can Red Win in two moves?, followed by the winning move`): elif nargs=1 and args[1]=WinR3 then print(`WinR3(P): Can Red Win in three moves?, followed by the winning move`): elif nargs=1 and args[1]=WinRk then print(`WinRk(P): Can Red Win in k moves?, followed by the winning move`): elif nargs=1 and args[1]=WinRkAll then print(`WinRkAll(P): Can Red Win in k moves?, followed by the winning move`): else print(`There is no ezra for`, args): fi: end: ####Specifics for the Game (in this case Generalized Connetct 4) #IniPos(): The initial position IniPos:=proc() global M,N: local i,j: [seq([seq(0,i=1..N)],j=1..M)]: end: #DrawPos(POS): draws a position POS DrawPos:=proc(POS) local i,j: for i from nops(POS[1]) by -1 to 1 do lprint(seq(POS[j][i],j=1..nops(POS))): od: end: #RedWon(POS): Did Red win? RedWon:=proc(POS) local i,j,i1,j1: global M,N,K: if not member(0,{seq(POS[i][nops(POS[i])],i=1..nops(POS))}) then RETURN(true): fi: for i from 1 to M do for j from 1 to N-K+1 do if {seq(POS[i][j+j1],j1=0..K-1)}={1} then RETURN(true): fi: od: od: for j from 1 to N do for i from 1 to M-K+1 do if {seq(POS[i+i1][j],i1=0..K-1)}={1} then RETURN(true): fi: od: od: for j from 1 to N-K+1 do for i from 1 to M-K+1 do if {seq(POS[i+i1][j+i1],i1=0..K-1)}={1} then RETURN(true): fi: od: od: for i from 1 to M-K+1 do for j from K to N do if {seq(POS[i+i1][j-i1],i1=0..K-1)}={1} then RETURN(true): fi: od: od: false: end: #BlackWon(POS): Did Black win? BlackWon:=proc(POS) local i,j,i1,j1: global M,N,K: if not member(0,{seq(POS[i][nops(POS[i])],i=1..nops(POS))}) then RETURN(true): fi: for i from 1 to M do for j from 1 to N-K+1 do if {seq(POS[i][j+j1],j1=0..K-1)}={2} then RETURN(true): fi: od: od: for j from 1 to N do for i from 1 to M-K+1 do if {seq(POS[i+i1][j],i1=0..K-1)}={2} then RETURN(true): fi: od: od: for j from 1 to N-K+1 do for i from 1 to M-K+1 do if {seq(POS[i+i1][j+i1],i1=0..K-1)}={2} then RETURN(true): fi: od: od: for i from 1 to M-K+1 do for j from K to N do if {seq(POS[i+i1][j-i1],i1=0..K-1)}={2} then RETURN(true): fi: od: od: false: end: #RedMoves(POS): all the moves of Red RedMoves:=proc(POS) local i,gu: gu:=[]: for i from 1 to nops(POS) do if POS[i][nops(POS[i])]=0 then gu:=[op(gu),[1,i]]: fi: od: gu: end: #BlackMoves(POS): all moves of Black BlackMoves:=proc(POS) local i,gu: gu:=[]: for i from 1 to nops(POS) do if POS[i][nops(POS[i])]=0 then gu:=[op(gu),[2,i]]: fi: od: gu: end: #ExecMove(POS,M): executes move M on pos POS ExecMove:=proc(POS,M) local a,j,i: if not type(POS,list) and type(M,list) and nops(M)=2 and type(M[1],integer) then ERROR(`Bad input`): fi: a:=M[1]: i:=M[2]: for j from 1 while POS[i][j]<>0 do od: [op(1..i-1,POS),[op(1..j-1, POS[i]),a,op(j+1..nops(POS[i]),POS[i])], op(i+1..nops(POS),POS)]: end: #ExecMoves(POS,M): executes the sequence of moves M on pos POS ExecMoves:=proc(POS,M) local gu, i: gu:=POS: for i from 1 to nops(M) do gu:=ExecMove(gu,M[i]): od: gu: end: ####End Spefics of the Game RandGameN:=proc() local POS,ra,co,lu: POS:=IniPos(): for co from 1 do lu:=RedMoves(POS): ra:=rand(1..nops(lu)): POS:=ExecMove(POS,lu[ra()]): if RedWon(POS) then RETURN(1,co,POS): fi: lu:=BlackMoves(POS): ra:=rand(1..nops(lu)): POS:=ExecMove(POS,lu[ra()]): if BlackWon(POS) then RETURN(2,co,POS): fi: od: end: RandGameNv:=proc() local POS,ra,co,lu,mo: POS:=IniPos(): DrawPos(POS): for co from 1 do lu:=RedMoves(POS): ra:=rand(1..nops(lu)): mo:=lu[ra()]: print(` Red `, co, `-th move is the `, mo[2],` -th column `): POS:=ExecMove(POS,mo): print(` Now the Position is `): DrawPos(POS): if RedWon(POS) then print(`Red won after`, co, `moves `): RETURN(1,co,POS): fi: lu:=BlackMoves(POS): ra:=rand(1..nops(lu)): mo:=lu[ra()]: print(` Black `, co, `-th move is at the `, mo[2], `column `): POS:=ExecMove(POS,mo): print(` Now the Position is `): DrawPos(POS): if BlackWon(POS) then print(` Black won after `, co, ` moves `): RETURN(2,co,POS): fi: od: end: ####Win in Five Moves Pr5:= {[[2, 1, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0 ], [2, 1, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0]], [[1, 2, 1, 1, 0 , 0], [2, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0]], [[2, 1, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [2, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [2, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0 ], [2, 1, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0]], [[1, 0, 0, 0, 0 , 0], [2, 2, 1, 1, 0, 0], [2, 2, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 1, 1, 2, 0, 0], [2, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0]], [[2, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0]], [[2, 0, 0, 0, 0, 0], [2, 2, 1, 1, 0, 0], [2, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0]], [[2, 2, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0 ], [2, 1, 1, 0, 0, 0], [1, 2, 1, 1, 0, 0], [1, 0, 0, 0, 0, 0]], [[2, 2, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0 ], [2, 1, 1, 0, 0, 0], [1, 2, 1, 1, 0, 0], [1, 0, 0, 0, 0, 0]], [[1, 1, 0, 0, 0 , 0], [0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 1, 2, 0, 0], [2, 2, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0]], [[2, 1, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0 ], [2, 1, 2, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0]], [[1, 2, 1, 2, 0 , 0], [2, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0]], [[2, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0], [2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0]], [[2, 2, 1, 0, 0, 0], [1, 1, 1, 2, 0, 0], [1, 2, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 2, 1 , 0, 0], [1, 2, 1, 0, 0, 0], [2, 2, 1, 0, 0, 0]]}: ####End Win in Five Moves ###Begin Good Win in Four Moves Pr4:= {[[2, 2, 1, 1, 0, 0], [1, 2, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0 ], [2, 1, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [2, 1, 0, 0, 0, 0]], [[2, 2, 0, 0, 0 , 0], [1, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 2, 1, 1, 0, 0], [1, 1, 2, 1, 0, 0], [2, 2, 0, 0, 0, 0]], [[2, 2, 2, 1, 0, 0], [1, 0, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [1, 1, 2, 0, 0, 0], [1, 0, 0, 0, 0, 0]], [[2, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0], [1, 1, 1, 2, 0, 0]], [[2, 1, 2, 1, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0], [2, 2, 1, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0]], [[ 1, 1, 2, 2, 0, 0], [1, 2, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 1, 2, 0, 0]], [[2, 0, 0, 0, 0, 0 ], [1, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0], [2, 1, 1, 2, 0, 0]], [[2, 1, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0], [1, 1, 2, 0, 0, 0], [1, 2, 1, 2, 0, 0]], [[1, 1, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [2, 2, 1, 0, 0, 0], [2, 2, 1, 2, 0, 0]], [[1, 2, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 2, 2, 1, 0, 0], [1, 2, 2, 1, 0, 0]], [[2, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0 ], [1, 1, 2, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0 , 0], [2, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0]], [[1, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [2, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[ 1, 0, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0 ], [2, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0]], [[1, 2, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0]], [[2, 2, 1, 1, 0, 0], [1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0 ], [2, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0]], [[1, 0, 0, 0, 0 , 0], [2, 2, 1, 0, 0, 0], [2, 1, 2, 1, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0]], [[1, 2, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 2, 2, 0, 0, 0]], [[1, 2, 1, 2, 0, 0], [2, 1, 1, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0]], [[2, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [1, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 1, 1, 2, 0, 0]], [[1, 2, 2, 1, 0, 0], [1, 1, 2, 2, 0, 0], [1, 2, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0 ], [2, 1, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [1, 1, 2, 0, 0, 0]], [[2, 2, 1, 2, 0 , 0], [1, 0, 0, 0, 0, 0], [1, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 1, 2, 1, 0, 0], [2, 1, 2, 2, 0, 0]], [[2, 2, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0], [2, 1, 2, 1, 0, 0], [1, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0]], [[1, 1, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 2, 2, 1, 0, 0], [2, 1, 1, 2, 0, 0], [1, 2, 2, 0, 0, 0]], [[1, 2, 1, 2, 0, 0], [1, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 1, 2, 0, 0], [1, 2, 1, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 2, 0, 0, 0, 0]], [[ 2, 1, 2, 0, 0, 0], [2, 1, 2, 1, 0, 0], [1, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 1, 2, 2, 0, 0], [2, 1, 1, 0, 0, 0]], [[2, 1, 2, 1, 0, 0 ], [2, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [1, 2, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0], [2, 1, 1, 0, 0, 0]]}: ###End Good Win in Four Moves ####Win in Four Moves Old Pr4Old:= [[[2, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 1, 1, 2, 0, 0], [2, 1, 0, 0, 0, 0 ], [2, 2, 2, 1, 0, 0], [1, 1, 0, 0, 0, 0], [1, 1, 2, 2, 0, 0]], [[1, 2, 2, 1, 0 , 0], [1, 1, 2, 2, 0, 0], [1, 2, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [1, 1, 2, 0, 0, 0]], [[2, 2, 1, 2, 0, 0], [1, 0, 0, 0, 0, 0], [1, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 1, 2, 1, 0, 0], [2, 1, 2, 2, 0, 0]], [[1, 2, 1, 1, 0, 0], [2, 2, 2, 1, 0, 0], [1, 1, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0]], [[2, 1, 1, 2, 0, 0], [1, 2, 2, 1, 0, 0], [1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 1, 2, 2, 0, 0]], [[ 1, 1, 2, 1, 0, 0], [2, 2, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [2, 1, 2, 1, 0, 0]], [[1, 2, 0, 0, 0, 0 ], [1, 2, 1, 0, 0, 0], [2, 2, 1, 1, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0], [2, 2, 1, 0, 0, 0], [2, 1, 2, 0, 0, 0]], [[1, 2, 1, 2, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [2, 1, 2, 1, 0, 0], [1, 2, 1, 2, 0, 0]], [[1, 1, 2, 0, 0, 0], [1, 2, 1, 2, 0, 0], [2, 1, 1, 0, 0, 0], [2, 2, 1, 2, 0, 0], [1, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 2, 0, 0, 0]], [[2, 2, 1, 1, 0, 0], [2, 2, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0]], [[2, 2, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [2, 2, 1, 1, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0], [2, 2, 1, 0, 0, 0]], [[2, 2, 0, 0, 0, 0], [ 2, 1, 2, 1, 0, 0], [2, 1, 2, 1, 0, 0], [1, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0]], [[2, 2, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0 ], [1, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0], [1, 2, 1, 2, 0, 0], [2, 1, 2, 0, 0, 0]], [[2, 2, 1, 1, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 2, 1, 0, 0, 0], [2, 1, 2, 1, 0, 0]], [[1, 2, 1, 2, 0, 0], [1, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 2, 2, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 2, 2, 1, 0, 0]], [[2, 2, 0, 0, 0, 0], [1, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [2, 2, 1, 1, 0, 0], [2, 1, 1, 2, 0, 0], [1, 1, 2, 1, 0, 0]], [[1, 1, 2, 0, 0, 0], [1, 1, 1, 2, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0], [2, 2, 1, 2, 0, 0]], [[1, 0, 0, 0, 0, 0], [2, 2, 1, 2, 0, 0], [ 2, 2, 1, 1, 0, 0], [2, 1, 2, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 2, 1, 1, 0, 0], [1, 1, 0, 0, 0, 0]], [[1, 1, 2, 2, 0, 0], [2, 1, 1, 2, 0, 0], [1, 1, 0, 0, 0, 0 ], [0, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 2, 1, 2, 0, 0], [2, 1, 1, 2, 0, 0]], [[1, 1, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 2, 2, 1, 0, 0], [2, 1, 1, 2, 0, 0], [1, 2, 2, 0, 0, 0]], [[2, 2, 1, 1, 0, 0], [1, 2, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [2, 1, 1, 0, 0, 0], [2, 2, 2, 0, 0, 0]], [[1, 2, 1, 2, 0, 0], [1, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 1, 2, 0, 0], [1, 2, 1, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 2, 0, 0, 0, 0]], [[2, 1, 2, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0], [1, 2, 1, 1, 0, 0], [2, 2, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 2, 2, 0, 0]], [[2, 1, 2, 0, 0, 0], [2, 1, 2, 1, 0, 0], [1, 1, 2, 0, 0, 0], [ 0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 1, 2, 2, 0, 0], [2, 1, 1, 0, 0, 0]], [[2, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0], [2, 2, 2, 0, 0, 0] , [2, 1, 2, 1, 0, 0], [1, 2, 0, 0, 0, 0], [2, 2, 1, 1, 0, 0]], [[1, 1, 2, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 1, 1, 0, 0], [2, 0, 0, 0, 0, 0], [2, 2, 1, 2, 0, 0], [1, 2, 0, 0, 0, 0], [2, 2, 1, 1, 0, 0]], [[2, 1, 2, 0, 0, 0], [2, 2, 1, 1, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 1, 2, 0, 0], [1, 1, 2, 1, 0, 0], [2, 1, 1, 2, 0, 0]], [[1, 2, 2, 1, 0, 0], [2, 2, 1, 1, 0, 0], [2, 2, 2, 1, 0, 0], [2, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [1, 1, 0, 0, 0, 0]], [[2, 1, 2, 1, 0, 0], [1, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [1, 2, 1, 1, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [2, 2, 1, 1, 0, 0]], [[2, 2, 1, 2, 0, 0], [1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 1, 1, 0, 0], [1, 2, 1, 1, 0, 0], [1, 1, 2, 0, 0, 0], [2, 2, 2, 0, 0, 0]], [[2, 1, 2, 1, 0, 0], [ 1, 1, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0], [1, 2, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 1, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0]], [[2, 0, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0 ], [1, 1, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0], [1, 1, 2, 0, 0, 0], [1, 2, 2, 0, 0, 0], [2, 1, 1, 0, 0, 0]], [[1, 2, 2, 0, 0, 0], [1, 2, 2, 1, 0, 0], [2, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0], [1, 1, 2, 0, 0, 0], [2, 1, 1, 0, 0, 0]], [[2, 1, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [2, 2, 2, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0], [2, 2, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0]], [[2, 1, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 2, 1, 1, 0, 0], [2, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0], [1, 2, 2, 1, 0, 0]], [[2, 1, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [1, 2, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0], [2, 1, 1, 0, 0, 0]]] : ####end Win In Four Moves ####start Win In Three Moves Pr3:= {[[1, 0, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0 ], [1, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0]], [[0, 0, 0, 0, 0 , 0], [2, 1, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [2, 1, 1, 2, 0, 0], [2, 1, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [2, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0], [2, 1, 0, 0, 0, 0]], [[2, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0]], [[ 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0]], [[1, 0, 0, 0, 0, 0 ], [1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0]], [[2, 2, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0]], [[2, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0]], [[0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0], [1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 2, 1, 2, 0, 0]], [[1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [2, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0]], [[2, 1, 1, 0, 0, 0], [ 0, 0, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[2, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0 ], [1, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0]], [[1, 1, 2, 0, 0, 0], [2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0]], [[2, 1, 1, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]], [[2, 0, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [ 2, 1, 1, 0, 0, 0], [1, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0]], [[2, 2, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0 ], [1, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0]], [[2, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 1, 1, 2, 0, 0], [1, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[1, 1, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [2, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0]], [[1, 2, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0], [1, 0, 0, 0, 0, 0], [ 2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0], [2, 1, 0, 0, 0, 0]], [[1, 1, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0] , [2, 2, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[1, 1, 2, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 1, 1, 2, 0, 0], [1, 2, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[1, 2, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[2, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0]]}: ####End Win In Three Moves ####Start Wins in Two Moves Pr2:= {[[2, 0, 0, 0, 0, 0], [2, 1, 2, 2, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0 ], [1, 0, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [1, 0, 0, 0, 0, 0]], [[1, 0, 0, 0, 0 , 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [2, 2, 1, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 1, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 2, 1, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0]], [[1, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0]], [[2, 1, 1, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0]], [[ 1, 1, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0]], [[2, 1, 1, 0, 0, 0 ], [2, 1, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0]], [[2, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 1, 0, 0, 0, 0]], [[1, 0, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [2, 1, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0]], [[2, 0, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [2, 2, 0, 0, 0, 0]], [[1, 0, 0, 0, 0, 0], [ 2, 1, 2, 0, 0, 0], [2, 2, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0 ], [2, 1, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0]], [[0, 0, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 1, 1, 2, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0]], [[2, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [1, 1, 2, 0, 0, 0]], [[2, 1, 1, 0, 0, 0], [2, 1, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 2, 0, 0], [1, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0]], [[2, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [ 2, 0, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0]], [[1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0 ], [1, 1, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 2, 2, 0, 0]], [[1, 2, 1, 0, 0, 0], [2, 2, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0]], [[2, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 1, 1, 0, 0, 0]], [[2, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 2, 2, 0, 0], [1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0], [1, 0, 0, 0, 0, 0]], [[2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0]], [[2, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [ 1, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 2, 1, 0, 0, 0], [2, 2, 0, 0, 0, 0]], [[2, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 1, 2, 2, 0, 0], [1, 0, 0, 0, 0, 0] , [1, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0]], [[1, 2, 2, 1, 0, 0], [2, 1, 2, 1, 0, 0], [1, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[2, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 1, 2, 0, 0]], [[1, 2, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 1, 2, 0, 0]], [[1, 1, 2, 1, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0]], [[2, 1, 0, 0, 0, 0], [1, 1, 1, 2, 0, 0], [1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0]]}: ####End Wins in Two Moves ###Start with problems Red wins in 1 move Pr1:= {[[2, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 1, 1, 0, 0, 0], [2, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [1, 1, 2, 0, 0, 0]], [[2, 1, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 2, 1, 2 , 0, 0], [2, 2, 1, 2, 0, 0], [1, 0, 0, 0, 0, 0]], [[1, 0, 0, 0, 0, 0], [2, 1, 1, 1, 0, 0], [2, 0, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0], [1, 2, 0, 0, 0, 0], [0, 0 , 0, 0, 0, 0], [1, 2, 1, 2, 0, 0]], [[0, 0, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0], [ 1, 1, 2, 1, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0], [2, 2, 2, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 1, 1, 0, 0], [1, 2, 2, 0, 0, 0], [1, 1, 2, 0, 0 , 0]], [[2, 1, 1, 1, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0]], [[2, 2, 2, 0, 0, 0], [1, 1, 2, 0, 0, 0], [1, 1, 2, 0, 0, 0], [1, 2, 1, 1, 0, 0], [0, 0 , 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0]], [[2, 1, 1, 1, 0, 0], [ 0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [2, 1, 1, 2, 0, 0], [1, 2, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 1, 1, 1, 0 , 0], [2, 2, 0, 0, 0, 0]], [[2, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 1, 1, 0, 0], [1, 2, 2 , 1, 0, 0]], [[1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 2, 2, 0, 0], [2, 2, 2, 0, 0, 0], [1, 1, 1, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0]], [ [1, 1, 1, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0] , [1, 2, 2, 0, 0, 0], [2, 2, 1, 0, 0, 0], [2, 2, 1, 0, 0, 0]], [[1, 1, 2, 0, 0 , 0], [2, 0, 0, 0, 0, 0], [2, 2, 1, 1, 0, 0], [1, 1, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[1, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 2, 2, 0, 0], [2, 1, 1 , 2, 0, 0], [0, 0, 0, 0, 0, 0]], [[1, 1, 2, 2, 0, 0], [1, 2, 1, 1, 0, 0], [1, 2, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [0 , 0, 0, 0, 0, 0]], [[1, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0] , [2, 2, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 2, 2, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 1, 2, 0, 0, 0]], [[2, 1, 2, 0, 0, 0], [2, 1, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 2, 0 , 0, 0, 0], [1, 1, 2, 1, 0, 0], [2, 2, 0, 0, 0, 0]], [[2, 1, 1, 1, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2 , 1, 2, 0, 0, 0], [2, 2, 0, 0, 0, 0]], [[2, 1, 2, 0, 0, 0], [2, 2, 2, 0, 0, 0] , [1, 2, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0]], [[2, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0], [2, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [2, 2, 2, 0 , 0, 0]], [[2, 1, 1, 0, 0, 0], [1, 1, 2, 2, 0, 0], [1, 1, 2, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[1, 1, 1, 0, 0, 0], [2, 2, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 1, 2, 0, 0], [0 , 0, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [1, 2, 1, 0, 0, 0]], [[2, 1, 1, 0, 0, 0] , [1, 2, 2, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [1, 1, 2, 0, 0, 0]], [[1, 2, 1, 0, 0, 0], [1, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 2, 0 , 0, 0], [2, 1, 2, 0, 0, 0]], [[2, 2, 0, 0, 0, 0], [2, 2, 2, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1 , 1, 0, 0, 0]], [[1, 2, 1, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [ 1, 2, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0]] , [[1, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [1, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 2, 2, 0, 0]], [[2, 2, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0], [1, 2, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 1, 0 , 0, 0], [1, 2, 0, 0, 0, 0], [2, 2, 2, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [2, 1, 1, 1, 0, 0], [1, 1, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [2, 0, 0, 0, 0, 0], [2, 2 , 2, 0, 0, 0], [1, 2, 0, 0, 0, 0]]}: ###End problems Red wins in 1 move #WinR1(P): Can Red Win in one move?, followed by the winning move WinR1:=proc(P) local MO,m: option remember: if BlackWon(P) then RETURN(false,FAIL): fi: MO:=RedMoves(P): for m in MO do if RedWon(ExecMove(P,m)) then RETURN(true,m): fi: od: false,FAIL: end: #WinB1(P): Can Black Win in one move?, followed by the winning move WinB1:=proc(P) local MO,m: option remember: if RedWon(P) then RETURN(false,FAIL): fi: MO:=BlackMoves(P): for m in MO do if BlackWon(ExecMove(P,m)) then RETURN(true,m): fi: od: false,FAIL: end: #WinR1All(P): Can Red Win in one move?, all the moves WinR1All:=proc(P) local MO,m,gu: option remember: if BlackWon(P) then RETURN(false,FAIL): fi: MO:=RedMoves(P): gu:={}: for m in MO do if RedWon(ExecMove(P,m)) then gu:=gu union {m}: fi: od: gu: end: #WinB1All(P): Can Black Win in one move?,all the moves WinB1All:=proc(P) local MO,m,gu: option remember: if RedWon(P) then RETURN(false,FAIL): fi: MO:=BlackMoves(P): gu:={}: for m in MO do if BlackWon(ExecMove(P,m)) then gu:=gu union {m}: fi: od: gu: end: #HopeLessB1(P): Is the position such that whatever #Black will do, Red can win in one move? HopeLessB1:=proc(P) local MO,m: option remember: if BlackWon(P) or RedWon(P) then RETURN(false): fi: if WinB1(P)[1] then RETURN(false): fi: MO:=BlackMoves(P): for m in MO do if not WinR1(ExecMove(P,m))[1] then RETURN(false): fi: od: true: end: #HopeLessR1(P): Is the position such that whatever #Red will do, Red can win in one move? HopeLessR1:=proc(P) local MO,m: option remember: if BlackWon(P) or RedWon(P) then RETURN(false): fi: if WinR1(P)[1] then RETURN(false): fi: MO:=RedMoves(P): for m in MO do if not WinB1(ExecMove(P,m))[1] then RETURN(false): fi: od: true: end: #WinR2(P): Can Red Win in two moves?, followed by the winning move WinR2:=proc(P) local MO,m: option remember: if HopeLessR1(P) then RETURN(false,FAIL): fi: MO:=RedMoves(P): for m in MO do if HopeLessB1(ExecMove(P,m)) then RETURN(true,m): fi: od: false,FAIL: end: #WinB2(P): Can Black Win in two moves?, followed by the winning move WinB2:=proc(P) local MO,m: option remember: if HopeLessB1(P) then RETURN(false,FAIL): fi: MO:=BlackMoves(P): for m in MO do if HopeLessR1(ExecMove(P,m)) then RETURN(true,m): fi: od: false,FAIL: end: #HopeLessB2(P): Is the position such that whatever #Black will do, Red can win in two or one moves? HopeLessB2:=proc(P) local MO,m: option remember: if BlackWon(P) or RedWon(P) then RETURN(false): fi: if WinB1(P)[1] or WinB2(P)[1] then RETURN(false): fi: if HopeLessB1(P) then RETURN(true): fi: MO:=BlackMoves(P): for m in MO do if not (WinR1(ExecMove(P,m))[1] or WinR2(ExecMove(P,m))[1]) then RETURN(false): fi: od: true: end: #HopeLessR2(P): Is the position such that whatever #Red will do, Black can win in two or one moves? HopeLessR2:=proc(P) local MO,m: option remember: if BlackWon(P) or RedWon(P) then RETURN(false): fi: if WinR1(P)[1] or WinR2(P)[1] then RETURN(false): fi: if HopeLessR1(P) then RETURN(true): fi: MO:=RedMoves(P): for m in MO do if not (WinB1(ExecMove(P,m))[1] or WinB2(ExecMove(P,m))[1]) then RETURN(false): fi: od: true: end: #WinR3(P): Can Red Win in three moves?, followed by the winning move WinR3:=proc(P) local MO,m,P1: option remember: if HopeLessR2(P) then RETURN(false,FAIL): fi: MO:=RedMoves(P): for m in MO do P1:= ExecMove(P,m): if HopeLessB2(P1) then RETURN(true,m): fi: od: false,FAIL: end: #WinB3(P): Can Black Win in three moves?, followed by the winning move WinB3:=proc(P) local MO,m,P1: option remember: if HopeLessB2(P) then RETURN(false,FAIL): fi: MO:=BlackMoves(P): for m in MO do P1:= ExecMove(P,m): if HopeLessR2(P1) then RETURN(true,m): fi: od: false,FAIL: end: #HopeLessB3(P): Is the position such that whatever #Black will do, Red can win in three or two or one moves? HopeLessB3:=proc(P) local MO,m,P1: option remember: if BlackWon(P) or RedWon(P) then RETURN(false): fi: if WinB1(P)[1] or WinB2(P)[1] or WinB3(P)[1] then RETURN(false): fi: if HopeLessB1(P) or HopeLessB2(P) then RETURN(true): fi: MO:=BlackMoves(P): for m in MO do P1:=ExecMove(P,m): if not (WinR1(P1)[1] or WinR2(P1)[1] or WinR3(P1)[1]) then RETURN(false): fi: od: true: end: #HopeLessR3(P): Is the position such that whatever #Red will do, Black can win in three or two or one moves? HopeLessR3:=proc(P) local MO,m,P1: option remember: if BlackWon(P) or RedWon(P) then RETURN(false): fi: if WinR1(P)[1] or WinR2(P)[1] or WinR3(P)[1] then RETURN(false): fi: if HopeLessR1(P) or HopeLessR2(P) then RETURN(true): fi: MO:=RedMoves(P): for m in MO do P1:=ExecMove(P,m): if not (WinB1(P1)[1] or WinB2(P1)[1] or WinB3(P1)[1]) then RETURN(false): fi: od: true: end: #WinR4(P): Can Red Win in four moves?, followed by the winning move WinR4:=proc(P) local MO,m,P1: option remember: if HopeLessR3(P) then RETURN(false,FAIL): fi: MO:=RedMoves(P): for m in MO do P1:= ExecMove(P,m): if HopeLessB3(P1) then RETURN(true,m): fi: od: false,FAIL: end: #WinB4(P): Can Black Win in four moves?, followed by the winning move WinB4:=proc(P) local MO,m,P1: option remember: if HopeLessB3(P) then RETURN(false,FAIL): fi: MO:=BlackMoves(P): for m in MO do P1:= ExecMove(P,m): if HopeLessR3(P1) then RETURN(true,m): fi: od: false,FAIL: end: #HopeLessB4(P): Is the position such that whatever #Black will do, Red can win in four or three or two or one moves? HopeLessB4:=proc(P) local MO,m,P1: option remember: if BlackWon(P) or RedWon(P) then RETURN(false): fi: if WinB1(P)[1] or WinB2(P)[1] or WinB3(P)[1] then RETURN(false): fi: if HopeLessB1(P) or HopeLessB2(P) or HopeLessB3(P) then RETURN(true): fi: MO:=BlackMoves(P): for m in MO do P1:=ExecMove(P,m): if not (WinR1(P1)[1] or WinR2(P1)[1] or WinR3(P1)[1] or WinR4(P1)[1]) then RETURN(false): fi: od: true: end: #HopeLessR4(P): Is the position such that whatever #Red will do, Black can win in four or three or two or one moves? HopeLessR4:=proc(P) local MO,m,P1: option remember: if BlackWon(P) or RedWon(P) then RETURN(false): fi: if WinR1(P)[1] or WinR2(P)[1] or WinR3(P)[1] then RETURN(false): fi: if HopeLessR1(P) or HopeLessR2(P) or HopeLessR3(P) then RETURN(true): fi: MO:=RedMoves(P): for m in MO do P1:=ExecMove(P,m): if not (WinB1(P1)[1] or WinB2(P1)[1] or WinB3(P1)[1] or WinB4(P1)[1]) then RETURN(false): fi: od: true: end: #WinR5(P): Can Red Win in five moves?, followed by the winning move WinR5:=proc(P) local MO,m,P1: option remember: if HopeLessR4(P) then RETURN(false,FAIL): fi: MO:=RedMoves(P): for m in MO do P1:= ExecMove(P,m): if HopeLessB4(P1) then RETURN(true,m): fi: od: false,FAIL: end: ####General #WinRk(P,k): Can Red Win in k moves?, followed by the winning move WinRk:=proc(P,k) local MO,m,P1: option remember: if k=1 then RETURN(WinR1(P)): fi: if HopeLessRk(P,k-1) then RETURN(false,FAIL): fi: MO:=RedMoves(P): for m in MO do P1:= ExecMove(P,m): if HopeLessBk(P1,k-1) then RETURN(true,m): fi: od: false,FAIL: end: #WinBk(P,k): Can Black Win in k moves?, followed by the winning move WinBk:=proc(P,k) local MO,m,P1: option remember: if k=1 then RETURN(WinB1(P)): fi: if HopeLessBk(P,k-1) then RETURN(false,FAIL): fi: MO:=BlackMoves(P): for m in MO do P1:= ExecMove(P,m): if HopeLessRk(P1,k-1) then RETURN(true,m): fi: od: false,FAIL: end: #HopeLessRk(P,k): Is the position such that whatever #Red will do, Black can win in <=k moves? HopeLessRk:=proc(P,k) local MO,m,P1,i: option remember: if BlackWon(P) or RedWon(P) then RETURN(false): fi: if member(true, { seq(WinRk(P,i)[1],i=1..k-1) } ) then RETURN(false): fi: if member(true,{seq(HopeLessRk(P,i), i=1..k-1)}) then RETURN(true): fi: MO:=RedMoves(P): for m in MO do P1:=ExecMove(P,m): if not member(true,{seq(WinBk(P1,i)[1],i=1..k)}) then RETURN(false): fi: od: true: end: #HopeLessBk(P,k): Is the position such that whatever #Black will do, Red can win in <=k moves? HopeLessBk:=proc(P,k) local MO,m,P1,i: option remember: if BlackWon(P) or RedWon(P) then RETURN(false): fi: if member(true, { seq(WinBk(P,i)[1],i=1..k-1) } ) then RETURN(false): fi: if member(true,{seq(HopeLessBk(P,i), i=1..k-1)}) then RETURN(true): fi: MO:=BlackMoves(P): for m in MO do P1:=ExecMove(P,m): if not member(true,{seq(WinRk(P1,i)[1],i=1..k)}) then RETURN(false): fi: od: true: end: #WinAdRk(POS,k): The smallest i<=k such that POS is Win with <=i #moves for Red followed by the set of good moves WinAdRk:=proc(POS,k) local i,lu: option remember: for i from 1 to k do lu:=WinRk(POS,i): if lu[1] then RETURN([i,lu[2]]): fi: od; [k+1,FAIL]: end: #WinAdBk(POS,k): The smallest i<=k such that POS is Win with <=i #moves for Red followed by the set of good moves WinAdBk:=proc(POS,k) local i,lu: option remember: for i from 1 to k do lu:=WinBk(POS,i): if lu[1] then RETURN([i,lu[2]]): fi: od; [k+1,FAIL]: end: #Pars(n,k,r): all the paritions of n with k parts and largest part <=r Pars:=proc(n,k,r) local gu,m,s,mu,n1,i: option remember: if k=0 then if n=0 then RETURN({[]}): else RETURN({}): fi: fi: if n=1 then RETURN({[1$k]}): else RETURN({}): fi: fi: n1:=n-k: gu:={}: for s from 1 to k do mu:=Pars(n1,s,r-1): gu:=gu union {seq([seq(m[i]+1,i=1..nops(m)),1$(k-s)],m in mu)}: od: gu: end: #ParsA(n,k,r): all partitions of n with <=k parts ParsA:=proc(n,k,r) local i: {seq(op(Pars(n,i,r)),i=1..k)}: end: #RandPos(m): a random position with m 1's and m 2's #For example, try RandPos(4); RandPos:=proc(m) local i,j,lu,pi,ra,mu,mu1,co,P,P1: global M,N: lu:=[1$m,2$m]: pi:=randperm(2*m): lu:=[seq(lu[pi[i]],i=1..2*m)]: mu:=ParsA(2*m,M,N-2): ra:=rand(1..nops(mu)): mu1:=mu[ra()]: mu1:=[op(mu1),0$(M-nops(mu1))]: pi:=randperm(nops(mu1)): mu1:=[seq(mu1[pi[i]],i=1..nops(pi))]: #[seq([seq(0,i=1..N)],j=1..M)]: P:=[]: co:=0: for j from 1 to M do P1:=[]: for i from 1 to mu1[j] do co:=co+1: P1:=[op(P1),lu[co]]: od: P1:=[op(P1),0$(N-mu1[j]) ]: P:=[op(P),P1]: od: P: end: #MakeProb1(m,R): Tries to make a problem Red-Can-Win in R-moves #R moves, starting with a position with m white #and m black checkers in the connect-four board #trying Gvul number of times #For example, try: #MakeProb1(6,2); MakeProb1:=proc(m,R) local P,gu: P:=RandPos(m): if RedWon(P) or BlackWon(P) then RETURN(FAIL): fi: gu:=WinAdRk(P,R): if gu[1]=R then RETURN(P): else RETURN(FAIL): fi: end: #MakeAprob(m,R,Gvul): Makes one problem of the kind "Red can win in #R moves", if possible, starting with a position with m white #and m black checkers in the connect-four board #trying Gvul number of times. The number of problems is a surprise #For example, try: #MakeAprob(6,2,200); MakeAprob:=proc(m,R,Gvul) local i,gu: for i from 1 to Gvul do gc(): gu:=MakeProb1(m,R): if gu<>FAIL then RETURN(gu): fi: od: end: #hakhiG(L): the top non-zero element in the list L hakhiG:=proc(L) local i: if L=[] or L=[0$(nops(L))] then RETURN(FAIL): fi: for i from nops(L) by -1 to 1 while L[i]=0 do od: L[i],i: end: #RedUnMoves(P): all the unwhite moves. For example, try: #RedUnMoves([[1,0$5],[0$6]$6]); RedUnMoves:=proc(P) local i,gu,P1,lu,i1: gu:={}: for i from 1 to nops(P) do P1:=P[i]: lu:=hakhiG(P1): if lu<>FAIL then i1:=lu[2]: if lu[1]=1 then P1:=[op(1..i1-1,P1),0$(nops(P1)-i1+1)]: gu:=gu union {[op(1..i-1,P),P1,op(i+1..nops(P),P)]}: fi: fi: od: gu: end: #BlackUnMoves(P): all the unblack moves. For example, try: #BlackUnMoves([[1,2,0$4],[0$6]$6]); BlackUnMoves:=proc(P) local i,gu,P1,lu,i1: gu:={}: for i from 1 to nops(P) do P1:=P[i]: lu:=hakhiG(P1): if lu<>FAIL then i1:=lu[2]: if lu[1]=2 then P1:=[op(1..i1-1,P1),0$(nops(P1)-i1+1)]: gu:=gu union {[op(1..i-1,P),P1,op(i+1..nops(P),P)]}: fi: fi: od: gu: end: #Upgrade(P,R): Given a position P that is win for white #in R moves, outputs one that is win in R+1 moves Upgrade:=proc(P,R) local gu,P1,i: gu:=BlackUnMoves(P): gu:={seq(op(RedUnMoves(gu[i])),i=1..nops(gu))}: for i from 1 to nops(gu) do P1:=gu[i]: if WinAdRk(P1,R+1)[1]=R+1 then RETURN(P1): fi: od: FAIL: end: #Upgrades(P,R): Given a position P that is win for white #in R moves, outputs those that win in R+1 moves Upgrades:=proc(P,R) local gu,P1,i,mu: gu:=BlackUnMoves(P): gu:={seq(op(RedUnMoves(gu[i])),i=1..nops(gu))}: mu:={}: for i from 1 to nops(gu) do P1:=gu[i]: if WinAdRk(P1,R+1)[1]=R+1 then mu:=mu union {P1}: fi: od: mu: end: #WinRkAll(P,k): Can Red Win in k moves?, followed by the #set of winning moves WinRkAll:=proc(P,k) local MO,m,P1,gu: option remember: if k=1 then RETURN(WinR1All(P)): fi: if HopeLessRk(P,k-1) then RETURN({}): fi: MO:=RedMoves(P): gu:={}: for m in MO do P1:= ExecMove(P,m): if HopeLessBk(P1,k-1) then gu:=gu union {m}: fi: od: gu: end: #WinBkAll(P,k): The set of moves that guarantee #win--in-k moves for Black followed by the #set of winning moves WinBkAll:=proc(P,k) local MO,m,P1,gu: option remember: if k=1 then RETURN(WinB1All): fi: if HopeLessBk(P,k-1) then RETURN(FAIL): fi: MO:=BlackMoves(P): gu:={}: for m in MO do P1:= ExecMove(P,m): if HopeLessRk(P1,k-1) then gu:=gu union {m}: fi: od: gu: end: #IsGoodProb(P,k): Is the position P a good problem #for win-for-red-in k-moves? IsGoodProb:=proc(P,k) local gu,P1: gu:=WinRk(P,k): if WinB1(P)[1] then RETURN(false): fi: if not gu[1] then RETURN(false): fi: gu:=WinRkAll(P,k): if nops(gu)>1 then RETURN(false): fi: P1:=ExecMove(P,gu[1]): if WinR1(P1)[1] then RETURN(false): fi: true: end: #GoodRedMoves(POS,k): all the moves that do not let #Black win in k moves GoodRedMoves:=proc(POS,k) local gu,g,POS1,mu: gu:=RedMoves(POS): mu:={}: for g in gu do POS1:=ExecMove(POS,g): if WinAdBk(POS1,k)[1]>k then mu:=mu union {g}: fi: od: mu: end: #GoodBlackMoves(POS,k): all the moves that do not let #Red win in k moves GoodBlackMoves:=proc(POS,k) local gu,g,POS1,mu: gu:=BlackMoves(POS): mu:={}: for g in gu do POS1:=ExecMove(POS,g): if WinAdRk(POS1,k)[1]>k then mu:=mu union {g}: fi: od: mu: end: #MakeGoodProbs1(k,m,L,Gvul): Makes L good problems of win-in-k-moves #with m checkers of each color. For example, try: #MakeGoodProbs1(3,8,4,200); MakeGoodProbs1:=proc(k,m,L,Gvul) local gu,P: gu:={}: while nops(gu)FAIL and IsGoodProb(P,k) then gu:=gu union {P}: lprint(gu): fi: od: gu: end: #MakeProbs(k,m,L,Gvul): Makes L problems of win-in-k-moves #with m checkers of each color. For example, try: #MakeProbs(3,8,4,200); MakeProbs:=proc(k,m,L,Gvul) local gu,P: gu:={}: while nops(gu)FAIL then gu:=gu union {P}: fi: od: gu: end: #MakeProbsD(k,m,L,Gvul): Makes L problems of win-in-k-moves #with m checkers of each color, using the direct method. #For example, try: #MakeProbsD(3,8,4,200); MakeProbsD:=proc(k,m,L,Gvul) local gu,P: gu:={}: while nops(gu)FAIL then gu:=gu union {P}: fi: od: gu: end: #MakeGoodProbsD(k,m,L,Gvul): Makes L good problems of win-in-k-moves #with m checkers of each color, using the direct method. For example, try: #MakeGoodProbsD(3,8,4,200); MakeGoodProbsD:=proc(k,m,L,Gvul) local gu,P: gu:={}: while nops(gu)FAIL and IsGoodProb(P,k) then gu:=gu union {P}: fi: od: gu: end: #######################Drawing######## #DrawEl(c,d): The ellipse (x-c[1])^2/d[1]^2+(y-c[2])^2/d[2]^2=1 DrawEl:=proc(c,d,tseva) local x,y: implicitplot((x-c[1])^2/d[1]^2+(y-c[2])^2/d[2]^2=1, x=c[1]-d[1]..c[1]+d[1],y=c[2]-d[2]..c[2]+d[2],axes=none,scaling=CONSTRAINED, color=tseva,numpoints=3000): end: #DrawElTh(c,d): The ellipse (x-c[1])^2/d[1]^2+(y-c[2])^2/d[2]^2=1 DrawElTh:=proc(c,d,tseva) local x,y: implicitplot((x-c[1])^2/d[1]^2+(y-c[2])^2/d[2]^2=1, x=c[1]-d[1]..c[1]+d[1],y=c[2]-d[2]..c[2]+d[2],axes=none,scaling=CONSTRAINED, color=tseva,numpoints=3000,thickness=20): end: #DrawPosN(P): a nice picture of the Connect-F position P DrawPosN:=proc(P) local p,i,j: p:=plot([[0,0],[M,0]],axes=none,scaling=CONSTRAINED): for i from 1 to N do p:=p,plot([[0,i],[M,i]],linestyle=3): od: for j from 0 to M do p:=p,plot([[j,0],[j,N]],linestyle=3): od: for i from 1 to M do for j from 1 to N do if P[i][j]=1 then p:=p,DrawElTh([i-.5,j-.5],[.45 , .45],red): elif P[i][j]=2 then p:=p,DrawElTh([i-.5,j-.5],[.45 , .45],black): fi: od: od: display(p): end: #######################End Drawing######## #Sefer30P(S):Given a set of 30 problems S, does the #pictorial part Sefer30P:=proc(S1) local S: if nops(S1)>30 then S:=[op(1..30,S1)]: fi: if nops(S1)<30 then ERROR(`Not enough problems`): fi: plotsetup(gif,plotoutput=`P1.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[1]); plotsetup(gif,plotoutput=`P2.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[2]); plotsetup(gif,plotoutput=`P3.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[3]); plotsetup(gif,plotoutput=`P4.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[4]); plotsetup(gif,plotoutput=`P5.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[5]); plotsetup(gif,plotoutput=`P6.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[6]); plotsetup(gif,plotoutput=`P7.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[7]); plotsetup(gif,plotoutput=`P8.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[8]); plotsetup(gif,plotoutput=`P9.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[9]); plotsetup(gif,plotoutput=`P10.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[10]); plotsetup(gif,plotoutput=`P11.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[11]); plotsetup(gif,plotoutput=`P12.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[12]); plotsetup(gif,plotoutput=`P13.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[13]); plotsetup(gif,plotoutput=`P14.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[14]); plotsetup(gif,plotoutput=`P15.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[15]); plotsetup(gif,plotoutput=`P16.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[16]); plotsetup(gif,plotoutput=`P17.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[17]); plotsetup(gif,plotoutput=`P18.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[18]); plotsetup(gif,plotoutput=`P19.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[19]); plotsetup(gif,plotoutput=`P20.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[20]); plotsetup(gif,plotoutput=`P21.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[21]); plotsetup(gif,plotoutput=`P22.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[22]); plotsetup(gif,plotoutput=`P23.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[23]); plotsetup(gif,plotoutput=`P24.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[24]); plotsetup(gif,plotoutput=`P25.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[25]); plotsetup(gif,plotoutput=`P26.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[26]); plotsetup(gif,plotoutput=`P27.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[27]); plotsetup(gif,plotoutput=`P28.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[28]); plotsetup(gif,plotoutput=`P29.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[29]); plotsetup(gif,plotoutput=`P30.gif`,plotoptions=`portrait,noborder`): DrawPosN(S[30]); end: #ReasRMoves(POS): all the reasonable red moves ReasRMoves:=proc(POS) local gu,i,mu: gu:=WinBk(POS,1): if gu[1] then mu:=WinBkAll(POS,1): mu:={seq([1,mu[i][2]],i=1..nops(mu))}: RETURN(mu): fi: RedMoves(POS): end: #ReasBMoves(POS): all the reasonable red moves ReasBMoves:=proc(POS) local gu,i,mu: gu:=WinRk(POS,1)[1]: if gu then mu:=WinRkAll(POS,1): mu:=sort([seq(mu[i][2],i=1..nops(mu))]): mu:=[seq([2,mu[i]],i=1..nops(mu))]: RETURN(mu): fi: mu:=BlackMoves(POS): mu:=sort([seq(mu[i][2],i=1..nops(mu))]): [seq([2,mu[i]],i=1..nops(mu))]: end: #SolRk(P,k): detailed solution for the Win-in-k moves problem P SolRk:=proc(P,k) local gu,m,i1,mu,mu1,P1,lu,P2,k1: gu:=WinRk(P,k): if not gu[1] then RETURN(FAIL): fi: print(`The position is`): DrawPos(P): mu:=WinRkAll(P,k): mu1:={seq(mu[i1][2],i1=1..nops(mu))}: m:=mu[1]: if nops(mu)>1 then print(`Red can win in `, k, `moves by putting its piece(1) in columns`): print( op(mu1)): print(`We will only prove it for column`, m[2]): fi: print(`Red can win in `, k, `moves by putting its piece(1) in column`, m[2]): print(`leading to position`): P1:=ExecMove(P,m): DrawPos(P1): if k=1 then print(`Red obviously won!`): RETURN(): fi: if k=2 then lu:=WinRkAll(P1,1): if nops(lu)=2 then print(`This is a double-or-nothing in columns`, seq(lu[i1][2],i1=1..2) ): RETURN(): elif nops(lu)>2 then print(`This is a multiple-or-nothing in columns`): print( seq(lu[i1][2],i1=1..nops(lu)) ): RETURN(): fi: fi: lu:=ReasBMoves(P1): if nops(lu)>1 then print(`The reasonable moves for Black are to move in columns`,seq(lu[i1][2],i1=1..nops(lu)) ): else print(`The reasonable moves for Black are to move in column`,lu[1][2]): fi: for m in lu do print(`if Black moves in column`, m[2], `then the position is`): P2:=ExecMove(P1,m): DrawPos(P2): k1:=WinAdRk(P2,k)[1]: if k1>k-1 then RETURN(FAIL): fi: print(`from which Red can win in`, k1, ` moves. Indeed `): print(`--------------------------------`): SolRk(P2,k1) : print(`--------------------------------------------------`): od: end: #MakeGoodProbs2(k,m,L,Gvul): Makes L good problems of win-in-k-moves #with m checkers of each color. For example, try: #MakeGoodProbs2(3,8,4,200); MakeGoodProbs2:=proc(k,m,L,Gvul) local gu,P: gu:={}: while nops(gu)FAIL then P:=Upgrade(P,k-1): if P<>FAIL and IsGoodProb(P,k) then gu:=gu union {P}: lprint(gu): fi : fi: od: gu: end: #RedGoodMoves(POS,k): all the moves of Red that do not #lead to Black winning in k moves RedGoodMoves:=proc(P,k) local gu,P1,g,mu,k1,i: if member(true,{seq(HopeLessRk(P,i),i=1..k)}) or BlackWon(P) then RETURN({}): fi: k1:=WinAdRk(P,k)[1]: if k1<=k then RETURN(WinRkAll(P,k1)): fi: gu:=RedMoves(P): mu:={}: for g in gu do P1:=ExecMove(P,g): if WinAdBk(P1,k)[1]=k+1 then mu:=mu union {g}: fi: od: mu: end: #RedBlackMoves(POS,k): all the moves of Black that do not #lead to Red winning in k moves BlackGoodMoves:=proc(P,k) local gu,P1,g,mu,k1,i: if member(true,{seq(HopeLessBk(P,i),i=1..k)}) or RedWon(P) then RETURN({}): fi: k1:=WinAdBk(P,k)[1]: if k1<=k then RETURN(WinBkAll(P,k1)): fi: gu:=BlackMoves(P): mu:={}: for g in gu do P1:=ExecMove(P,g): if WinAdRk(P1,k)[1]=k+1 then mu:=mu union {g}: fi: od: mu: end: #RandGameC(k): clever random game until one side has #win-in-k-moves RandGameC:=proc(k) local POS,ra,co,lu: POS:=IniPos(): for co from 1 do if WinRk(POS,k)[1] then RETURN(1,POS): fi: lu:=RedGoodMoves(POS,k): if lu={} then RETURN(2,co,POS): fi: ra:=rand(1..nops(lu)): POS:=ExecMove(POS,lu[ra()]): if WinAdBk(POS,k)[1]<=k then RETURN(2,co,POS): fi: lu:=BlackGoodMoves(POS,k): if lu={} then RETURN(1,co,POS): fi: ra:=rand(1..nops(lu)): POS:=ExecMove(POS,lu[ra()]): if WinAdRk(POS,k)[1]<=k then RETURN(1,co,POS): fi: od: end: #GoodUpgrade(P,R): Given a position P that is win for white #in R moves, outputs one that is win in R+1 moves and is good GoodUpgrade:=proc(P,R) local gu,P1,i: gu:=BlackUnMoves(P): gu:={seq(op(RedUnMoves(gu[i])),i=1..nops(gu))}: for i from 1 to nops(gu) do P1:=gu[i]: if WinAdRk(P1,R+1)[1]=R+1 and IsGoodProb(P1,R+1) then RETURN(P1): fi: od: FAIL: end: #MakeProbsD(k,m,L,Gvul): Makes L problems of win-in-k-moves #with m checkers of each color. For example, try: #MakeProbsD(1,8,4,200); MakeProbsD:=proc(k,m,L,Gvul) local gu,P: gu:={}: while nops(gu)FAIL then gu:=gu union {P}: fi: od: gu: end: #MakeGoodProbs3(k,m,L,Gvul): Makes L good problems of win-in-k-moves #with m checkers of each color. For example, try: #MakeGoodProbs3(3,8,4,200); MakeGoodProbs3:=proc(k,m,L,Gvul) local gu,P: if k<4 then ERROR(` k>=4 `): fi: gu:={}: while nops(gu)FAIL then P:=Upgrade(P,k-2): if P<>FAIL then P:=Upgrade(P,k-1): if P<>FAIL and IsGoodProb(P,k) then gu:=gu union {P}: lprint(gu): fi : fi: fi: od: gu: end: #ProveRk(P,k, Shem,i): Finds the winning move of Red for a win-in-k moves #and gives a formal proof. Shem is the name, and i is the level #(upper-level has i=0) #For exapmpe, try: #ProveRk(Pr2[1],2,1,0); ProveRk:=proc(P,k,Shem,i) local gu,mu,i1,mo,P1,lu,P2,ku: gu:=WinRk(P,k): if not gu[1] then RETURN(FAIL): fi: mu:=WinRkAll(P,k): mo:=mu[1]: if i=0 then print(`Theorem`, Shem, ` In position `): elif i=1 then print(`Lemma`, Shem, `In position `): elif i=2 then print(`SubLemma`, Shem, `In position `): elif i=2 then print(`SubSubLemma`, Shem, `In position `): elif i=3 then print(`SubSubSubLemma`, Shem, `In position `): elif i=4 then print(`SubSubSubSubLemma`, Shem, `In position `): elif i=5 then print(`SubSubSubSubSubLemma`, Shem, `In position `): elif i=6 then print(`SubSubSubSubSubSubLemma`, Shem, `In position `): elif i=7 then print(`SubSubSubSubSubSubSubLemma`, Shem, `In position `): fi: DrawPos(P): print(`Red can win in`, k, ` moves ` ): if nops(mu)=1 then print(`by putting its piece in column `, mo[2]): else print(`by putting its piece in columns `, seq(mu[i1][2],i1=1..nops(mu))): print(`We will only prove it for column`, mo[2]): fi: print(`Indeed, if Red puts its piece(1) in column`, mo[2], `the position is`): P1:=ExecMove(P,mo): DrawPos(P1): if k=1 then print(`Red won!`): RETURN(): fi: if k=2 and WinRk(P1,1)[1] then ku:=WinRkAll(P1,1): if nops(ku)=2 then print(`This is double-or-nothing in columns`, seq(ku[i1][2],i1=1..nops(ku))): RETURN(): elif nops(ku)>2 then print(`This is multiple-or-nothing in columns`, seq(ku[i1][2],i1=1..nops(ku))): RETURN(): fi: fi: lu:=ReasBMoves(P1): if nops(lu)>1 then print(`The reasonable moves for Black are to move in columns`,seq(lu[i1][2],i1=1..nops(lu))): print(`We have to prove that each of these moves will lead to a position`): if k>2 then print(`where Red can win in <=`, k-1, `moves. `): elif k=2 then print(`where Red can win in one move. `): fi: else print(`The only reasonable move for Black is to move in columns`,seq(lu[i1][2],i1=1..nops(lu))): print(`We have to prove that with this move, it will lead to a position`): if k>2 then print(`where Red can win in <=`, k-1, `moves `): elif k=2 then print(`where Red can win in one move. `): fi: fi: print(`This will follow from the following:`): for i1 from 1 to nops(lu) do P2:=ExecMove(P1,lu[i1]): print(`If Black goes in column`, lu[i1][2] , `then `): ProveRk(P2,k-1,cat(Shem,`.`,i1),i+1): od: end: