M:=7: N:=6: K:=4: #M:=5: N:=3: K:=3: with(combinat): with(plots): ezra:=proc(): if nargs=0 then print(`To play connect-k on an M by N board`): print(`Contains procedures: BestBmove, BestWmove `): print(`BlackMoves, BlackUnMoves, BlackWon,DrawPos, `): print(` DrawPosN, ExecMove, ExecMoves `): print(` HopeLessBk, HopeLessWk `): print(` IniPos, MakeAprob, MakeProb, MakeProb3, MakeProb4`): print(` MakeProbs, MakeProbs3, MakeProbs4, RandGame, RandGame0, `): print(` RandGameN, RandGameNv, RandPos, WhiteMoves, WhiteUnMoves,`): print(` WhiteWon `): print(` WinAdBk, WinAdWk, WinBk, WinWk, WinWkV `): elif nargs=1 and args[1]=BestBmove then print(`BestBmove(POS,k): What is the best move for Black with`): print(`k-step-look-ahead?, chosen randomly amongst equals`): elif nargs=1 and args[1]=BestWmove then print(`BestWmove(POS,k): What is the best move for Red with`): print(`k-step-look-ahead?, chosen randomly amongst equals`): elif nargs=1 and args[1]=BlackMoves then print(`WhiteMoves(POS): all the legal Black Moves`): elif nargs=1 and args[1]=BlackUnMoves then print(`BlackUnMoves(P): all the unwhite moves. For example, try:`): print(`BlackUnMoves([1,2,0$4],[0$6]$6]);`): elif nargs=1 and args[1]=BlackWon then print(`BlackWon(POS): Did Black win? followed by the proof (if true,`): print(`otherwise false, {}. `): print(` For example try: BlackWon([[1,1,1,0,0,0],[0$6]$5]); `): elif nargs=1 and args[1]=DrawPos then print(`DrawPos(POS):Draws the position, for example, try`): print(`DrawPos(IniPos());`): elif nargs=1 and args[1]=DrawPosN then print(`DrawPosN(POS):Draws the position nicely, for example, try`): print(`DrawPosN(IniPos());`): elif nargs=1 and args[1]=ExecMove then print(`ExecMove(POS,M): executes move M on pos POS`): elif nargs=1 and args[1]=ExecMoves then print(`ExecMoves(POS,L): executes list of moves L on pos POS`): elif nargs=1 and args[1]=HopeLessAdBk then print(`HopeAdLessBk(POS,k): The smallest i<=k such that `): print(` POS is HopeLessBk, or k+1`): elif nargs=1 and args[1]=HopeLessAdWk then print(`HopeAdLessWk(POS,k): The smallest i<=k such that `): print(` POS is HopeLessWk, or k+1`): elif nargs=1 and args[1]=HopeLessBk then print(`HopeLessBk(POS,k): Does every move of Black lead to a win in<=k`): print(` moves for Red`): elif nargs=1 and args[1]=HopeLessWk then print(`HopeLessWk(POS,k): Does every move of Red lead to a win in<=k`): print(` moves for Black`): elif nargs=1 and args[1]=IniPos then print(`IniPos(); the initial position `): 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]=MakeProb then print(`MakeProb(m,R,Gvul): Make a problem Red can win in`): 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(`MakeProb(6,2,20);`): elif nargs=1 and args[1]=MakeProb3 then print(`MakeProb3(R): makes a problem white wins in 3 moves`): print(`with R+1 pieces each. For example, try:`): print(`MakeProb3(10);`): elif nargs=1 and args[1]=MakeProbs then print(`MakeProbs(m,R,Gvul): Makes a set of problems "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(`MakeProbs(6,2,200);`): elif nargs=1 and args[1]=MakeProbs3 then print(`MakeProbs3(m,K): Makes a set of problems "Red can win in`): print(`3 moves", if possible, starting with a position with m white`): print(`and m black checkers in the connect-four board`): print(`trying K number of times. The number of problems is a surprise.`): print(`For example, try:`): print(`MakeProbs3(6,200);`): elif nargs=1 and args[1]=MakeProbs4 then print(`MakeProbs4(m,K): Makes a set of problems "Red can win in`): print(`4 moves", if possible, starting with a position with m white`): print(`and m black checkers in the connect-four board`): print(`trying K number of times. The number of problems is a surprise.`): print(`For example, try:`): print(`MakeProbs4(8,200);`): elif nargs=1 and args[1]=RandGame0 then print(`RandGame0(k): Plays a random game between k-smart players`): print(`starting with the initial position`): elif nargs=1 and args[1]=RandGame then print(`RandGame(STA,k): Plays a random game between k-smart players`): print(`staring with position STA`): elif nargs=1 and args[1]=RandGameN then print(`RandGameN(): A Naive Random Game`): elif nargs=1 and args[1]=RandGameNv then print(`RandGameN(): A Naive Random Game, Verbose Version`): elif nargs=1 and args[1]=RandPos then print(`RandPos(m): a random position with m 1's and m 2's.`): print(`For example, try RandPos(4);`): elif nargs=1 and args[1]=ReasWMoves then print(`ReasWMoves(POS): all the reasonable white moves`): elif nargs=1 and args[1]=WhiteUnMoves then print(`WhiteUnMoves(P): all the unwhite moves. For example, try:`): print(`WhiteUnMoves([[1,0$5],[0$6]$6]);`): elif nargs=1 and args[1]=WinAdBk then print(`WinAdBk(POS,k): If it is possible to win in i<=k moves for Black`): print(`returns i, and the winning moves or k+1 and []`): elif nargs=1 and args[1]=WinAdWk then print(`WinAdWk(POS,k): If it is possible to win in i<=k moves for Red`): print(`returns i, and the winning moves or k+1 and []`): elif nargs=1 and args[1]=WinBk then print(`WinBk(POS,k): is the position win in k moves for Black`): print(`followed by all the set of such moves `): elif nargs=1 and args[1]=WinWk then print(`WinWk(POS,k): is the position win in k moves for Red`): print(`followed by the set of such moves`): elif nargs=1 and args[1]=WinWkV then print(`WinWkV(POS,k): Verbose version of WinWk.`): print(`Does there exist at least one move for Red that leads`): print(`to win in <=k moves ( but it is not a win in <=k-1 moves)`): print(`listing the good moves.`): elif nargs=1 and args[1]=WhiteMoves then print(`WhiteMoves(POS): all the legal Red Moves`): elif nargs=1 and args[1]=WhiteWon then print(`WhiteWon(POS): Did white win? followed by the proof (if true,`): print(`otherwise false, {}. `): print(` For example try: WhiteWon([[1,1,1,0,0,0],[0$6]$5]); `): 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: #WhiteWon(POS): Did white win? followed by the proof (if true, #otherwise false, {} WhiteWon:=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, [seq([i,j+j1],j1=0..K-1)]): 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, [seq([i+i1,j],i1=0..K-1)]): 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, [seq([i+i1,j+i1],i1=0..K-1)]): 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, [seq([i+i1,j-i1],i1=0..K-1)]): fi: od: od: false, []: end: #BlackWon(POS): Did Black win? followed by the proof (if true, #otherwise false, {} 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, [seq([i,j+j1],j1=0..K-1)]): 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, [seq([i+i1,j],i1=0..K-1)]): 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, [seq([i+i1,j+i1],i1=0..K-1)]): 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, [seq([i+i1,j-i1],i1=0..K-1)]): fi: od: od: false, []: end: WhiteMoves:=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:=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: 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 move 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: #WhoseTurn(POS): whose turn is it WhoseTurn:=proc(POS,White,Black) local x,i,j,lu: lu:=convert([seq(seq(x[POS[i][j]],j=1..nops(POS[i])),i=1..nops(POS))],`+`): if coeff(lu,x[1],1)=coeff(lu,x[2],1) then RETURN(White): elif coeff(lu,x[1],1)=coeff(lu,x[2],1)+1 then RETURN(Black): else ERROR(`Bad Position`): fi: end: ####End Spefics of the Game RandGameN:=proc() local POS,ra,co,lu: POS:=IniPos(): for co from 1 do lu:=WhiteMoves(POS): ra:=rand(1..nops(lu)): POS:=ExecMove(POS,lu[ra()]): if WhiteWon(POS)[1] then RETURN(1,co,POS): fi: lu:=BlackMoves(POS): ra:=rand(1..nops(lu)): POS:=ExecMove(POS,lu[ra()]): if BlackWon(POS)[1] 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:=WhiteMoves(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 WhiteWon(POS)[1] 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)[1] then print(`Black won after`, co, `moves `): RETURN(2,co,POS): fi: od: end: #HopeLessWk(POS,k): Does every move of Red lead to #a Win in <=k moves for Black? HopeLessWk:=proc(POS,k) local mu,gu,i,move,POS1: option remember: if k=0 then if BlackWon(POS)[1] then RETURN(true,{}): else RETURN(false, WhiteMoves(POS)): fi: fi: if WinAdWk(POS,k)[1]<=k then RETURN(false,{}): fi: if HopeLessAdWk(POS,k-1)<=k-1 then RETURN(false,{}): fi: mu:=WhiteMoves(POS): gu:={}: for i from 1 to nops(mu) do move:=mu[i]: POS1:=ExecMove(POS,move): if WinAdBk(POS1,k)[1]=k+1 then gu:=gu union {move}: fi: od: if gu={} then RETURN(true,{}): else RETURN(false,gu): fi: end: #HopeLessBk(POS,k): Does every move of Black lead to #a Win in <=k moves for Red? HopeLessBk:=proc(POS,k) local mu,gu,i,move,POS1: option remember: if k=0 then if WhiteWon(POS)[1] then RETURN(true,{}): else RETURN(false, BlackMoves(POS)): fi: fi: if WinAdBk(POS,k)[1]<=k then RETURN(false,{}): fi: if HopeLessAdBk(POS,k-1)<=k-1 then RETURN(false,{}): fi: mu:=BlackMoves(POS): gu:={}: for i from 1 to nops(mu) do move:=mu[i]: POS1:=ExecMove(POS,move): if WinAdWk(POS1,k)[1]=k+1 then gu:=gu union {move}: fi: od: if gu={} then RETURN(true,{}): else RETURN(false,gu): fi: end: #WinWk(POS,k): Does there exist at least one move for Red that leads #to win in <=k moves ( but it is not a win in <=k-1 moves) #followed by the good moves WinWk:=proc(POS,k) local gu,mu,i,move,POS1: option remember: if k=0 then if WhiteWon(POS)[1] then RETURN(true,{}): else RETURN(false,{}): fi: fi: if k>1 and WinAdWk(POS,k-1)[1]<=k-1 then RETURN(false, {}): fi: mu:=WhiteMoves(POS): gu:={}: for i from 1 to nops(mu) do move:=mu[i]: POS1:=ExecMove(POS,move): if HopeLessBk(POS1,k-1)[1] then gu:=gu union {move}: fi: od: if gu<>{} then RETURN(true, gu): else RETURN(false, {}): fi: end: #WinBk(POS,k): Does there exist at least one move for Black that leads #to win in <=k moves ( but it is not a win in <=k-1 moves) #followed by the good moves WinBk:=proc(POS,k) local gu,mu,i,move,POS1: option remember: if k=0 then if WhiteWon(POS)[1] then RETURN(true,{}): else RETURN(false,{}): fi: fi: if k>1 and WinAdBk(POS,k-1)[1]<=k-1 then RETURN(false, {}): fi: mu:=BlackMoves(POS): gu:={}: for i from 1 to nops(mu) do move:=mu[i]: POS1:=ExecMove(POS,move): if HopeLessWk(POS1,k-1)[1] then gu:=gu union {move}: fi: od: if gu<>{} then RETURN(true, gu): else RETURN(false, {}): fi: end: #WinAdWk(POS,k): The smallest i<=k such that POS is Win wih <=i #moves for Red followed by the set of good moves WinAdWk:=proc(POS,k) local i,lu: for i from 0 to k do lu:=WinWk(POS,i): if lu[1] then RETURN([i,lu[2]]): fi: od; [k+1,{}]: end: #WinAdBk(POS,k): The smallest i<=k such that POS is Win wih <=i #moves for Black followed by the set of good moves WinAdBk:=proc(POS,k) local i,lu: for i from 0 to k do lu:=WinBk(POS,i): if lu[1] then RETURN([i,lu[2]]): fi: od; [k+1,{}]: end: HopeLessAdWk:=proc(POS,k) local i: for i from 0 to k do if HopeLessWk(POS,i)[1] then RETURN(i): fi: od: i: end: HopeLessAdBk:=proc(POS,k) local i: for i from 0 to k do if HopeLessBk(POS,i)[1] then RETURN(i): fi: od: i: end: #RandGame(STA,k): a random game up to level k, starting with #position STA RandGame:=proc(STA,k) local gu,POS,co,lu,move,ku: gu:=[]: POS:=STA: gu:=[]: for co from 1 do lu:=WinAdWk(POS,k): if lu[1]<=k then RETURN(1,co,co+lu[1],gu,POS): fi: lu:=HopeLessAdWk(POS,k-1): if lu<=k-1 then RETURN(2,co-1/2,co+lu[1]-1/2,gu,POS): fi: ku:=HopeLessWk(POS,k-1)[2]: move:=ku[rand(1..nops(ku))()]: gu:=[op(gu),move]: POS:=ExecMove(POS,move): lu:=WinAdBk(POS,k): if lu[1]<=k then RETURN(2,co,co+lu[1],gu,POS): fi: lu:=HopeLessAdBk(POS,k-1): if lu<=k-1 then RETURN(1,co-1/2,co+lu[1]-1/2,gu,POS): fi: ku:=HopeLessBk(POS,k-1)[2]: move:=ku[rand(1..nops(ku))()]: gu:=[op(gu),move]: POS:=ExecMove(POS,move): od: end: #BestWmove(POS,k): What is the best move for Red with #k-step-look-ahead?, chosen randomly amongst equals BestWmove:=proc(POS,k) local gu: gu:=WinAdWk(POS,k): if gu[1]<=k then print(`Red can win in`, gu[1], ` moves, with : `,gu[2]): RETURN(gu[2]): fi: gu:=HopeLessAdWk(POS,k): if gu<=k then print(`Black can win in`, gu , `moves whatever you will do`): print(`The best moves, nevertheless are`,HopeLessWk(POS,gu-1)[2]): RETURN(HopeLessWk(POS,gu-1)[2]): fi: RETURN(HopeLessWk(POS,k)[2]): end: #BestBmove(POS,k): What is the best move for Black with #k-step-look-ahead?, chosen randomly amongst equals BestBmove:=proc(POS,k) local gu: gu:=WinAdBk(POS,k): if gu[1]<=k then print(`Black can win in`, gu[1], ` moves, with : `,gu[2]): RETURN(gu[2]): fi: gu:=HopeLessAdBk(POS,k): if gu<=k then print(`Red can win in`, gu , `moves whatever you will do`): print(`The best moves, nevertheless are`,HopeLessWk(POS,gu-1)[2]): RETURN(HopeLessBk(POS,gu-1)[2]): fi: RETURN(HopeLessBk(POS,k)[2]): end: #WinWkV(POS,k): Verbose version of WinWk #Does there exist at least one move for Red that leads #to win in <=k moves ( but it is not a win in <=k-1 moves) #followed by the good moves WinWkVold:=proc(POS,k) local gu,mu,i,move,POS1,POS2, i1,mu1,k1,pu: #option remember: if k=0 then if WhiteWon(POS)[1] then print(`The position now is`): print(DrawPos(POS)): print(` This is a winning position for Red `): RETURN(true,{}): else RETURN(false,{}): fi: fi: if k>1 and WinAdWk(POS,k-1)[1]<=k-1 then RETURN(false, {}): fi: ###k=1 if k=1 and WinWk(POS,1)[1] then mu:=WhiteMoves(POS): gu:={}: print(DrawPos(POS)): for i from 1 to nops(mu) do move:=mu[i]: POS1:=ExecMove(POS,move): if HopeLessBk(POS1,k-1)[1] then print(`Red can win immediately by moving in column`, move[2]): gu:=gu union {move}: print(`resulting in position`): print(DrawPos(POS1)): fi: od: RETURN(true,gu): fi: ##end k=1 mu:=WhiteMoves(POS): gu:={}: print(DrawPos(POS)): for i from 1 to nops(mu) do move:=mu[i]: POS1:=ExecMove(POS,move): if HopeLessBk(POS1,k-1)[1] then print(`Red wins in`, k ,`moves by putting its piece(1) in column`,move[2]): gu:=gu union {move}: print(`resulting in position`): print(DrawPos(POS1)): if k=2 and WinWk(POS1,1)[1] and nops(WinWk(POS1,1)[2])>=2 then pu:=WinWk(POS1,1)[2]: pu:=seq(pu[i1][2],i1=1..nops(pu)): print(`This is double-or-nothing in columns`,pu): else if k=2 and WinWk(POS1,1)[1] and nops(WinWk(POS1,1)[2])=1 then mu1:=WinWk(POS1,1)[2]: mu1:={seq([2,mu1[i1][2]],i1=1..nops(mu1))}: else mu1:=BlackMoves(POS1): fi: print(`Indeed, the reasonable moves of Black are to place its piece(2) in columns`, seq(mu1[i1][2],i1=1..nops(mu1)) ): for i1 from 1 to nops(mu1) do print(`If Black goes in column`, mu1[i1][2], `then the position is`): POS2:=ExecMove(POS1,mu1[i1]): k1:=WinAdWk(POS2,k-1)[1]: WinWkV(POS2,k1): od: fi: fi: od: if gu<>{} then RETURN(true, gu): else RETURN(false, {}): fi: end: #RandGame0(k): a random game up to level k, starting with #Initial position RandGame0:=proc(k):RandGame(IniPos(),k):end: #WinBkV(POS,k): Verbose version of WinBk #Does there exist at least one move for Black that leads #to win in <=k moves ( but it is not a win in <=k-1 moves) #followed by the good moves WinBkVold:=proc(POS,k) local gu,mu,i,move,POS1,POS2, i1,mu1,k1,pu: #option remember: if k=0 then if BlackWon(POS)[1] then print(`The position now is`): print(DrawPos(POS)): print(` This is a winning position for Black `): RETURN(true,{}): else RETURN(false,{}): fi: fi: if k>1 and WinAdBk(POS,k-1)[1]<=k-1 then RETURN(false, {}): fi: ###k=1 if k=1 and WinBk(POS,1)[1] then mu:=BlackMoves(POS): gu:={}: print(DrawPos(POS)): for i from 1 to nops(mu) do move:=mu[i]: POS1:=ExecMove(POS,move): if HopeLessWk(POS1,k-1)[1] then print(`Black can win immediately by moving in column`, move[2]): gu:=gu union {move}: print(`resulting in position`): print(DrawPos(POS1)): fi: od: RETURN(true,gu): fi: ##end k=1 mu:=BlackMoves(POS): gu:={}: print(DrawPos(POS)): for i from 1 to nops(mu) do move:=mu[i]: POS1:=ExecMove(POS,move): if HopeLessWk(POS1,k-1)[1] then print(`Black wins in`, k ,`moves by putting its piece(2) in column`,move[2]): gu:=gu union {move}: print(`resulting in position`): print(DrawPos(POS1)): if k=2 and WinBk(POS1,1)[1] and nops(WinBk(POS1,1)[2])>=2 then pu:=WinBk(POS1,1)[2]: pu:=seq(pu[i1][2],i1=1..nops(pu)): print(`This is double-or-nothing in columns`,pu): else if k=2 and WinBk(POS1,1)[1] and nops(WinBk(POS1,1)[2])=1 then mu1:=WinBk(POS1,1)[2]: mu1:={seq([1,mu1[i1][2]],i1=1..nops(mu1))}: else mu1:=WhiteMoves(POS1): fi: print(`Indeed, the reasonable moves of Red are to place its piece(1) in columns`, seq(mu1[i1][2],i1=1..nops(mu1)) ): for i1 from 1 to nops(mu1) do print(`If Red goes in column`, mu1[i1][2], `then the position is`): POS2:=ExecMove(POS1,mu1[i1]): k1:=WinAdBk(POS2,k-1)[1]: WinBkV(POS2,k1): od: fi: fi: od: if gu<>{} then RETURN(true, gu): else RETURN(false, {}): fi: end: #ReasWMoves(POS): all the reasonable white moves ReasWMoves:=proc(POS) local gu,i,mu: gu:=WinBk(POS,1): if gu[1] then mu:=gu[2]: mu:={seq([1,mu[i][2]],i=1..nops(mu))}: RETURN(mu): fi: WhiteMoves(POS): end: #ReasBMoves(POS): all the reasonable black moves ReasBMoves:=proc(POS) local gu,i,mu: gu:=WinWk(POS,1): if gu[1] then mu:=gu[2]: mu:={seq([2,mu[i][2]],i=1..nops(mu))}: RETURN(mu): fi: BlackMoves(POS): end: #WinWkV(POS,k): Verbose version of WinWk #Does there exist at least one move for Red that leads #to win in <=k moves ( but it is not a win in <=k-1 moves) #followed by the good moves WinWkV:=proc(POS,k) local gu,mu,i,move,POS1,POS2, i1,mu1,k1,pu: #option remember: if k=0 then if WhiteWon(POS)[1] then print(`The position now is`): print(DrawPos(POS)): print(` This is a winning position for Red `): RETURN(true,{}): else RETURN(false,{}): fi: fi: if k>1 and WinAdWk(POS,k-1)[1]<=k-1 then RETURN(false, {}): fi: ###k=1 if k=1 and WinWk(POS,1)[1] then mu:=ReasWMoves(POS): gu:={}: print(DrawPos(POS)): for i from 1 to nops(mu) do move:=mu[i]: POS1:=ExecMove(POS,move): if HopeLessBk(POS1,k-1)[1] then print(`Red can win immediately by moving in column`, move[2]): gu:=gu union {move}: print(`resulting in position`): print(DrawPos(POS1)): fi: od: RETURN(true,gu): fi: ##end k=1 mu:=ReasWMoves(POS): gu:={}: print(DrawPos(POS)): for i from 1 to nops(mu) do move:=mu[i]: POS1:=ExecMove(POS,move): if HopeLessBk(POS1,k-1)[1] then print(`---------------------------------------------------`): print(`Red wins in`, k ,`moves by putting its piece(1) in column`,move[2]): gu:=gu union {move}: print(`resulting in position`): print(DrawPos(POS1)): if k=2 and WinWk(POS1,1)[1] and nops(WinWk(POS1,1)[2])>=2 then pu:=WinWk(POS1,1)[2]: pu:=seq(pu[i1][2],i1=1..nops(pu)): print(`This is double-or-nothing in columns`,pu): else if k=2 and WinWk(POS1,1)[1] and nops(WinWk(POS1,1)[2])=1 then mu1:=WinWk(POS1,1)[2]: mu1:={seq([2,mu1[i1][2]],i1=1..nops(mu1))}: else mu1:=ReasBMoves(POS1): fi: print(`Indeed, the reasonable moves of Black are to place its piece(2) in columns`, seq(mu1[i1][2],i1=1..nops(mu1)) ): for i1 from 1 to nops(mu1) do print(`If Black goes in column`, mu1[i1][2], `then the position is`): POS2:=ExecMove(POS1,mu1[i1]): k1:=WinAdWk(POS2,k-1)[1]: WinWkV(POS2,k1): od: fi: fi: od: if gu<>{} then RETURN(true, gu): else RETURN(false, {}): fi: end: #WinBkV(POS,k): Verbose version of WinBk #Does there exist at least one move for Black that leads #to win in <=k moves ( but it is not a win in <=k-1 moves) #followed by the good moves WinBkV:=proc(POS,k) local gu,mu,i,move,POS1,POS2, i1,mu1,k1,pu: #option remember: if k=0 then if BlackWon(POS)[1] then print(`The position now is`): print(DrawPos(POS)): print(` This is a winning position for Black `): RETURN(true,{}): else RETURN(false,{}): fi: fi: if k>1 and WinAdBk(POS,k-1)[1]<=k-1 then RETURN(false, {}): fi: ###k=1 if k=1 and WinBk(POS,1)[1] then mu:=ReasBMoves(POS): gu:={}: print(DrawPos(POS)): for i from 1 to nops(mu) do move:=mu[i]: POS1:=ExecMove(POS,move): if HopeLessWk(POS1,k-1)[1] then print(`Black can win immediately by moving in column`, move[2]): gu:=gu union {move}: print(`resulting in position`): print(DrawPos(POS1)): fi: od: RETURN(true,gu): fi: ##end k=1 mu:=ReasBMoves(POS): gu:={}: print(DrawPos(POS)): for i from 1 to nops(mu) do move:=mu[i]: POS1:=ExecMove(POS,move): if HopeLessWk(POS1,k-1)[1] then print(`------------------------------------------------------`): print(`Black wins in`, k ,`moves by putting its piece(2) in column`,move[2]): gu:=gu union {move}: print(`resulting in position`): print(DrawPos(POS1)): if k=2 and WinBk(POS1,1)[1] and nops(WinBk(POS1,1)[2])>=2 then pu:=WinBk(POS1,1)[2]: pu:=seq(pu[i1][2],i1=1..nops(pu)): print(`This is double-or-nothing in columns`,pu): else if k=2 and WinBk(POS1,1)[1] and nops(WinBk(POS1,1)[2])=1 then mu1:=WinBk(POS1,1)[2]: mu1:={seq([1,mu1[i1][2]],i1=1..nops(mu1))}: else mu1:=ReasWMoves(POS1): fi: print(`Indeed, the reasonable moves of Red are to place its piece(1) in columns`, seq(mu1[i1][2],i1=1..nops(mu1)) ): for i1 from 1 to nops(mu1) do print(`If Red goes in column`, mu1[i1][2], `then the position is`): POS2:=ExecMove(POS1,mu1[i1]): k1:=WinAdBk(POS2,k-1)[1]: WinBkV(POS2,k1): od: fi: fi: od: if gu<>{} then RETURN(true, gu): else RETURN(false, {}): fi: 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: 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: #MakeProb(m,R,Gvul): Make a problem Red can win in #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: #MakeProb(6,2,20); MakeProb:=proc(m,R, Gvul) local i,gu: for i from 1 to Gvul do gu:=MakeProb1(m,R): if gu<>FAIL then RETURN(gu): fi: od: FAIL: 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,k,gu: P:=RandPos(m): if WhiteWon(P)[1] or BlackWon(P)[1] then RETURN(FAIL): fi: gu:=WinAdWk(P,R): if gu[1]=R+1 then RETURN(FAIL): fi: if gu[1]=R and nops(gu[2])=1 then RETURN(P): else RETURN(FAIL): fi: end: #MakeProbs(m,R,Gvul): Makes a set of problems "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: #MakeProbs(6,2,200); MakeProbs:=proc(m,R,Gvul) local i,gu,mu: mu:={}: for i from 1 to Gvul do gc(): gu:=MakeProb1(m,R): if gu<>FAIL then mu:=mu union {gu}: fi: od: mu: 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: #WhiteUnMoves(P): all the unwhite moves. For example, try: #WhiteUnMoves([[1,0$5],[0$6]$6]); WhiteUnMoves:=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(WhiteUnMoves(gu[i])),i=1..nops(gu))}: for i from 1 to nops(gu) do P1:=gu[i]: if not WinWk(P1,R)[1] and WinWk(P1,R+1)[1] and nops(WinWk(P1,R+1)[2])=1 then RETURN(P1): fi: od: FAIL: end: #MakeProb3(m): makes a problem white wins in 3 moves #with m pieces each. For example, try: #MakeProb3(10); MakeProb3:=proc(m) local P,P1: P:=MakeProb(m+1,2,200): if P=FAIL then RETURN(FAIL): fi: P1:=Upgrade(P,2): end: #MakeProb4(m): makes a problem white wins in 4 moves #with m pieces each. For example, try: #MakeProb4(10); MakeProb4:=proc(m) local P,P1: P:=MakeProb3(m+1): if P=FAIL then RETURN(FAIL): fi: P1:=Upgrade(P,3): end: #MakeProbs3(m,K): makes K problems white wins in 3 moves #with m pieces each. For example, try: #MakeProbs3(10,K); MakeProbs3:=proc(m,K) local gu,i,P: gu:={}: for i from 1 to K do gc(): P:=MakeProb3(m): if P<>FAIL then gu:=gu union {P}: fi: od: gu: end: #MakeProbs4(m,K): makes K problems white wins in 4 moves #with m pieces each. For example, try: #MakeProbs4(10,K); MakeProbs4:=proc(m,K) local gu,i,P: gu:={}: for i from 1 to K do gc(): P:=MakeProb4(m): if P<>FAIL then gu:=gu union {P}: print(gu): fi: od: gu: end: ####################### #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,color=blue): 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: ####Win in Four Moves Pr4:= [[[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, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0 ], [1, 2, 1, 2, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0]], [[2, 2, 0, 0, 0 , 0], [1, 2, 2, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [2, 1, 1, 0, 0, 0]], [[2, 1, 1, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 2, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0]], [[2, 2, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [1, 2, 0, 0, 0, 0]], [[2, 1, 1, 2, 0, 0], [2, 1, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0]], [[ 2, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [2, 1, 2, 0, 0, 0]], [[1, 2, 2, 0, 0, 0 ], [2, 2, 1, 2, 0, 0], [1, 1, 1, 2, 0, 0], [2, 1, 0, 0, 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], [1, 2, 1, 1, 0, 0], [2, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [2, 2, 0, 0, 0, 0]], [[1, 2, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 2, 1, 2, 0, 0], [1, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [1, 1, 2, 2, 0, 0], [2, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0]], [[1, 1, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0]], [[1, 1, 0, 0, 0, 0], [ 2, 1, 2, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 1, 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], [1, 2, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 2, 1, 0, 0, 0]], [[1, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0], [2, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0]], [[1, 2, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 0, 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], [1, 2, 1, 2, 0, 0], [2, 2, 1, 0, 0, 0], [1, 2, 1, 0, 0, 0], [1, 1, 2, 0, 0, 0]], [[2, 2, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [2, 1, 0, 0, 0, 0]], [[2, 1, 2, 0, 0, 0], [1, 1, 2, 0, 0, 0], [ 2, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0], [2, 2, 2, 0, 0, 0], [1, 0, 0, 0, 0, 0]], [[1, 2, 1, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 2, 1, 2, 0, 0 ], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [2, 1, 2, 0, 0, 0]], [[1, 0, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0]], [[1, 2, 2, 0, 0, 0], [1, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [2, 2, 1, 0, 0, 0], [1, 1, 1, 2, 0, 0]], [[1, 1, 2, 2, 0, 0], [1, 2, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 1, 1, 2, 0, 0], [2, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]], [[2, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 1, 0, 0, 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, 1, 2, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0]], [[2, 1, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0] , [2, 1, 1, 2, 0, 0], [1, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0]], [[2, 2, 1, 2, 0, 0], [2, 2, 1, 0, 0, 0], [2, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [1, 2, 1, 0, 0, 0]], [[2, 2, 2, 0, 0, 0], [1, 2, 1, 0, 0, 0], [1, 1, 1, 2, 0, 0], [2, 2, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0]], [[2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0], [2, 2, 1, 1, 0, 0], [2, 1, 2, 0, 0, 0]], [[2, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 1, 1, 2, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0]], [[1, 2, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [1, 2, 0, 0, 0, 0]], [[2, 0, 0, 0, 0, 0], [ 1, 1, 1, 2, 0, 0], [1, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 2, 2, 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], [1, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 1, 2, 0, 0]], [[1, 2, 2, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0]], [[2, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0], [2, 2, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0]], [[1, 2, 1, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 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]], [[1, 2, 2, 0, 0, 0], [2, 1, 2, 1, 0, 0], [2, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]], [[2, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [ 1, 1, 2, 1, 0, 0], [1, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 2, 2, 2, 0, 0]], [[1, 2, 2, 1, 0, 0], [2, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0 ], [1, 1, 1, 2, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0]], [[2, 2, 1, 0, 0, 0], [1, 1, 2, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[1, 2, 2, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0]], [[2, 2, 1, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [2, 1, 0, 0, 0, 0]], [[1, 2, 0, 0, 0, 0], [2, 2, 1, 2, 0, 0], [1, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0]], [[2, 1, 1, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [ 1, 1, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [2, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0] , [1, 2, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0]], [[2, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 1, 1, 0, 0], [1, 2, 1, 2, 0, 0]], [[2, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 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], [1, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 1, 2, 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, 2, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0], [1, 1, 2, 2, 0, 0]]] : ####End Win In Three Moves ####Start Wins in Two Moves Pr2:= {[[1, 2, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0 ], [1, 0, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[1, 2, 2, 0, 0 , 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 2, 0, 0], [2, 2, 1, 0, 0, 0], [1, 2, 1, 0, 0, 0], [1, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0]], [[0, 0, 0, 0, 0, 0], [1, 1, 2, 2, 0, 0], [1, 2, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0], [2, 1, 1, 2, 0, 0]], [[2, 2, 1, 2, 0, 0], [2, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0], [1, 2, 2, 1, 0, 0]], [[1, 1, 2, 0, 0, 0], [1, 2, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 2, 2, 0, 0, 0]], [[ 2, 2, 1, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 2, 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], [2, 1, 1, 0, 0, 0], [2, 2, 1, 1, 0, 0], [2, 2, 1, 0, 0, 0]], [[1, 1, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 1, 2, 1, 0, 0], [2, 2, 1, 2, 0, 0]], [[2, 1, 2, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [2, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0]], [[2, 2, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [2, 2, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [1, 2, 0, 0, 0, 0]], [[1, 2, 2, 0, 0, 0], [2, 2, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0]], [[1, 2, 2, 1, 0, 0], [ 1, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0], [2, 1, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0]], [[1, 1, 2, 2, 0, 0], [2, 0, 0, 0, 0, 0 ], [1, 1, 2, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0]], [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0], [1, 1, 1, 2, 0, 0], [2, 1, 0, 0, 0, 0], [2, 2, 1, 2, 0, 0], [2, 2, 0, 0, 0, 0]], [[1, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 2, 2, 1, 0, 0]], [[1, 2, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0], [2, 2, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 1, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0]], [[2, 1, 1, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 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], [2, 1, 0, 0, 0, 0], [ 2, 1, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0]], [[2, 1, 2, 0, 0, 0], [1, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0 ], [1, 2, 1, 2, 0, 0], [2, 2, 1, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0]], [[2, 0, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 2, 0, 0, 0, 0]], [[2, 2, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0]], [[1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [1, 2, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [2, 2, 1, 0, 0, 0]], [[2, 0, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0], [1, 2, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0], [2, 1, 0, 0, 0, 0]], [[1, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [ 1, 1, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [2, 2, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0]], [[1, 0, 0, 0, 0, 0], [2, 1, 2, 2, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 1, 2, 0, 0] , [2, 0, 0, 0, 0, 0], [2, 2, 1, 1, 0, 0], [1, 0, 0, 0, 0, 0]], [[2, 2, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0]], [[2, 2, 1, 2, 0, 0], [1, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [1, 0, 0, 0, 0, 0], [1, 1, 2, 2, 0, 0], [2, 0, 0, 0, 0, 0]], [[2, 2, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0]], [[2, 1, 1, 0, 0, 0], [2, 2, 1, 0, 0, 0], [2, 1, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0]], [[2, 2, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 1, 2, 0, 0], [1, 1, 2, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0]], [[2, 1, 1, 0, 0, 0], [ 2, 2, 0, 0, 0, 0], [2, 2, 1, 1, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[2, 1, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0 ], [1, 0, 0, 0, 0, 0], [1, 1, 2, 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, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [2, 1, 1, 2, 0, 0], [2, 2, 1, 2, 0, 0], [1, 0, 0, 0, 0, 0]], [[1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 2, 2, 0, 0], [2, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 2, 1, 1, 0, 0], [1, 1, 2, 0, 0, 0]], [[1, 1, 2, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 2, 2, 0, 0], [2, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 1, 2, 0, 0, 0]], [[2, 2, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 2, 1, 0, 0, 0]], [[0, 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, 1, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0]], [[2, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0 ], [2, 2, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0]], [[1, 1, 2, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [2, 2, 1, 0, 0, 0], [1, 2, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0]], [[1, 1, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [2, 0, 0, 0, 0, 0]], [[1, 2, 1, 2, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [2, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0]], [[1, 2, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0], [1, 2, 0, 0, 0, 0]], [[2, 2, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0], [ 1, 1, 2, 2, 0, 0], [1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0]], [[2, 2, 1, 2, 0, 0], [1, 2, 1, 1, 0, 0], [2, 1, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0] , [1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 2, 0, 0]]} : ####End Wins in Two Moves ###Start with problems Red wins in 1 move Pr1:= {[[1, 2, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0], [1, 2, 2, 1, 0, 0 ], [1, 1, 1, 2, 0, 0], [2, 1, 2, 0, 0, 0], [2, 1, 2, 0, 0, 0]], [[1, 1, 2, 0, 0 , 0], [2, 2, 2, 1, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 1, 2, 0, 0], [1, 2, 1, 0, 0, 0]], [[2, 1, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 2, 0, 0, 0], [2, 2, 1, 1, 0, 0], [2, 2, 2, 1, 0, 0], [1, 1, 1, 0, 0, 0], [2, 0, 0, 0, 0, 0]], [[1, 1, 1, 0, 0, 0], [2, 1, 2, 1, 0, 0], [2, 2, 2, 0, 0, 0], [1, 1, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0], [2, 1, 1, 2, 0, 0]], [[1, 2, 2, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 2, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0]], [[ 1, 2, 1, 1, 0, 0], [1, 2, 2, 2, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [2, 1, 1, 1, 0, 0], [1, 0, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0]], [[1, 2, 1, 0, 0, 0 ], [1, 1, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0], [1, 1, 2, 2, 0, 0], [2, 2, 1, 0, 0, 0], [1, 2, 1, 1, 0, 0], [2, 2, 0, 0, 0, 0]], [[1, 2, 1, 0, 0, 0], [2, 1, 1, 1, 0, 0], [1, 2, 2, 1, 0, 0], [1, 2, 2, 2, 0, 0], [2, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0]], [[1, 1, 1, 0, 0, 0], [2, 2, 1, 0, 0, 0], [1, 1, 0, 0, 0, 0], [2, 2, 2, 0, 0, 0], [1, 2, 2, 0, 0, 0], [2, 1, 1, 0, 0, 0], [2, 1, 2, 0, 0, 0]], [[2, 0, 0, 0, 0, 0], [2, 2, 1, 1, 0, 0], [2, 1, 1, 0, 0, 0], [1, 1, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 2, 1, 2, 0, 0]], [[2, 2, 2, 0, 0, 0], [2, 1, 1, 1, 0, 0], [2, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0]], [[1, 0, 0, 0, 0, 0], [ 2, 1, 0, 0, 0, 0], [1, 1, 2, 2, 0, 0], [2, 2, 2, 1, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 1, 1, 0, 0], [2, 2, 1, 2, 0, 0]], [[1, 2, 2, 0, 0, 0], [2, 1, 1, 2, 0, 0 ], [1, 2, 2, 0, 0, 0], [1, 1, 1, 0, 0, 0], [1, 0, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0], [1, 2, 2, 0, 0, 0]], [[2, 1, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 2, 2, 1, 0, 0], [1, 2, 2, 1, 0, 0], [1, 1, 1, 2, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0]], [[1, 1, 1, 0, 0, 0], [1, 2, 2, 2, 0, 0], [1, 2, 1, 2, 0, 0], [2, 1, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0]], [[1, 1, 2, 0, 0, 0], [1, 2, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [2, 2, 2, 1, 0, 0], [2, 1, 0, 0, 0, 0], [1, 1, 1, 2, 0, 0]], [[2, 1, 1, 1, 0, 0], [1, 2, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0], [1, 2, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [2, 1, 0, 0, 0, 0], [2, 2, 0, 0, 0, 0]], [[1, 2, 2, 2, 0, 0], [1, 2, 2, 1, 0, 0], [ 1, 2, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0], [2, 1, 1, 2, 0, 0]], [[0, 0, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0], [2, 0, 0, 0, 0, 0 ], [2, 1, 2, 1, 0, 0], [1, 1, 2, 1, 0, 0], [1, 1, 2, 2, 0, 0], [1, 2, 1, 2, 0, 0]], [[1, 1, 2, 2, 0, 0], [2, 2, 2, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0], [2, 1, 1, 2, 0, 0]], [[1, 2, 1, 1, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [2, 2, 1, 1, 0, 0], [2, 1, 1, 1, 0, 0], [1, 2, 2, 2, 0, 0]], [[1, 2, 1, 1, 0, 0], [2, 2, 2, 1, 0, 0], [1, 2, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 1, 1, 0, 0], [1, 1, 2, 2, 0, 0]], [[2, 2, 0, 0, 0, 0], [1, 1, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 2, 1, 0, 0, 0], [2, 1, 2, 2, 0, 0], [2, 2, 1, 0, 0, 0]], [[1, 2, 1, 0, 0, 0], [2, 1, 1, 0, 0, 0], [1, 2, 1, 0, 0, 0], [ 1, 1, 0, 0, 0, 0], [2, 2, 2, 0, 0, 0], [2, 1, 1, 0, 0, 0], [2, 2, 2, 0, 0, 0]], [[2, 1, 1, 1, 0, 0], [1, 1, 1, 2, 0, 0], [1, 2, 2, 0, 0, 0], [2, 0, 0, 0, 0, 0] , [2, 1, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0], [2, 1, 2, 2, 0, 0]], [[1, 1, 2, 0, 0, 0], [2, 2, 1, 0, 0, 0], [2, 2, 2, 0, 0, 0], [1, 2, 2, 1, 0, 0], [2, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0], [1, 1, 2, 0, 0, 0]], [[2, 2, 2, 1, 0, 0], [2, 1, 2, 1, 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, 2, 0, 0]], [[1, 1, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0], [2, 1, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0], [1, 2, 2, 0, 0, 0], [2, 2, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0]], [[2, 2, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0], [2, 1, 0, 0, 0, 0], [1, 2, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0]] }: ###End problems Red wins in 1 move #SeferP(S,R): Given a set of problems Red to win in #R moves, creates a book of problems SeferP:=proc(S,R) local i,P: print(nops(S), `Problems of Red Wins in`, R, `moves in Connect Four `): print(): for i from 1 to nops(S) do P:=S[i]: print(`Problem Number `, i ): print(): DrawPos(P): print(): od: end: #SeferA(S,R): The answers to the problems in SeferP(S,R) SeferA:=proc(S,R) local i,P,lu: print(nops(S), `Answers to Red Wins in`, R, `moves in Connect Four `): print(): for i from 1 to nops(S) do P:=S[i]: lu:=WinWk(P,R): if lu[1] then print(`Solution to Problem Number `, i, `is: Column`, lu[2][1][2]): print(): fi: od: end: #SeferS(S,R): The detailed solutions to the problems in SeferP(S,R) SeferS:=proc(S,R) local i,P,lu: print(nops(S), `Solutions to Red Wins in`, R, `moves in Connect Four `): print(): for i from 1 to nops(S) do print(`------------------------------------------------`): print(`Detailed Solution to problem number`, i): P:=S[i]: DrawPosV(P): lu:=WinWkV(P,R): od: end: