Automated Pattern Deduction for Connect 4 in 2 Moves (version 0.128 2024-12-20)
Step 0. Initial
game.connects4InMoves(player, 2) = true
Step 1. The system substitutes game.connects4InMoves(player, 2) with its predefined equivalence definition <=>
∀ xMove: (Start For All Move Concept)
xMove >= 0 and
xMove < xMax and
game.matrix.yEmpty(xMove) < yMax - 1:
game.afterMove(xMove).connects4InMoves(player, 1) = true
∀end xMove (End For All Move Concept)
Step 2. The system substitutes connects4InMoves(player, 1) with its deduced equivalence definition <=>
∀ xMove: (Start For All Move Concept)
xMove >= 0 and
xMove < xMax and
game.matrix.yEmpty(xMove) < yMax - 1:
game.afterMove(xMove).matrix.reppp(player, 0, rex) = true and
game.afterMove(xMove).toMove = player and
game.afterMove(xMove).matrix.pppp(opponent(player)) = false
∀end xMove (End For All Move Concept)
Step 3. The system substitutes the game.afterMove(xMove).* functions with their deduced equivalence definitions <=>
∀ xMove: (Start For All Move Concept)
xMove >= 0 and
xMove < xMax and
game.matrix.yEmpty(xMove) < yMax - 1:
((xMove = rex and
game.matrix.reppp(player, 1, xMove) = true) or
(xMove != rex and
game.matrix.reppp(player, 0, rex) = true) or
(game.toMove = player and
game.matrix.rerepp(player, 0, xMove, 0, re2x) = true) or
(game.toMove = player and
game.matrix.vrep(player, 1, xMove) = true)) and
game.toMove = opponent(player) and
((game.matrix.reppp(opponent(player), 0, xMove) = false or
game.toMove = player) and
game.matrix.pppp(opponent(player)) = false)
∀end xMove (End For All Move Concept)
Step 4. The system eliminates the ored game.toMove = player rule and anded game.toMove = player containing ored rules, in red above, because it contradicts the absolute game.toMove = opponent(player) rule, in green above. <=>
∀ xMove: (Start For All Move Concept)
xMove >= 0 and
xMove < xMax and
game.matrix.yEmpty(xMove) < yMax - 1:
((xMove = rex and
game.matrix.reppp(player, 1, xMove) = true) or
(xMove != rex and
game.matrix.reppp(player, 0, rex) = true)) and
game.toMove = opponent(player) and
game.matrix.reppp(opponent(player), 0, xMove) = false and
game.matrix.pppp(opponent(player)) = false
∀end xMove (End For All Move Concept)
Step 5. The system exports game.toMove = opponent(player) and game.matrix.pppp(opponent(player)) = false out of the for all move concept since these rules are independent of xMove. The system exports game.matrix.reppp(opponent(player), 0, xMove) = false out of the for all move concept because this rule being false for any unbound rex is equivalent with it being false for all xMove binding this rule via rex. In the latter exported rule the variable name xMove is replaced with the variable name rex to avoid confusion with xMove from the all move concept. <=>
∀ xMove: (Start For All Move Concept)
xMove >= 0 and
xMove < xMax and
game.matrix.yEmpty(xMove) < yMax - 1:
((xMove = rex and
game.matrix.reppp(player, 1, xMove) = true) or
(xMove != rex and
game.matrix.reppp(player, 0, rex) = true))
∀end xMove (End For All Move Concept) and
game.toMove = opponent(player) and
game.matrix.reppp(opponent(player), 0, rex) = false and
game.matrix.pppp(opponent(player)) = false
Step 6. The system splits up the for all move concept into three parts each part being able to realise the for all move concept. The second ored rule (xMove != rex and game.matrix.reppp(player, 0, rex) = true) can realize for all xMove if for every xMove there exists a rex different from xMove with game.matrix.reppp(player, 0, rex) = true. This rule could stay in the for all xMove concept, but further deduction leads to two equivalent more conscise and insightful parts (part two and three) that can be exported out of the for all xMove. Part two is two re0ppp patterns with different rex which ensures for every xMove there exists a re0ppp with its rex different from xMove. Part three is a re1ppp and re0ppp with the same rex, thus on top of eachother. For every xMove different from this common rex the re0ppp realizes the condition. For xMove equal to the common rex the re1ppp pattern transforms into re0ppp realizing the condition. Part one is then the for all xMove itself with the remaining ored rule game.matrix.reppp(player, 1, xMove) = true. To part one the rule game.matrix.reppp(player, 1, rex) is added because at least one re1ppp pattern has to exist. This is the final step of the 4 in 2 moves deduction since its result is a minimal and normalised definition in terms of patterns on game.matrix with all references to game.afterMove(xMove) eliminated. <=>
((∀ xMove: (Start For All Move Concept)
xMove >= 0 and
xMove < xMax and
game.matrix.yEmpty(xMove) < yMax - 1:
game.matrix.reppp(player, 1, xMove) = true
∀end xMove (End For All Move Concept) and
game.matrix.reppp(player, 1, rex) = true) or
(x1 != x2 and
game.matrix.reppp(player, 0, x1) = true and
game.matrix.reppp(player, 0, x2) = true) or
(game.matrix.reppp(player, 1, xs) = true and
game.matrix.reppp(player, 0, xs) = true)) and
game.toMove = opponent(player) and
game.matrix.reppp(opponent(player), 0, rex) = false and
game.matrix.pppp(opponent(player)) = false
Connect Four Classes, Rules, Quantifiers and Predefined and Deduced Pattern Functions
xMax = 7
yMax = 6
conn = 4
opponent(1) = 2
opponent(2) = 1
game.connects4InMoves(player, 1) <=> (Predefined Pattern Function)
Ǝ xMove: (Start Exists Move Concept)
xMove >= 0 and
xMove < xMax:
game.afterMove(xMove).connects4InMoves(player, 0) = true
Ǝend xMove (End Exists Move Concept) and
game.toMove = player and
game.matrix.pppp(opponent(player)) = false
game.connects4InMoves(player, 2) <=> (Predefined Pattern Function)
∀ xMove: (Start For All Move Concept)
xMove >= 0 and
xMove < xMax and
game.matrix.yEmpty(xMove) < yMax - 1:
game.afterMove(xMove).connects4InMoves(player, 1) = true
∀end xMove (End For All Move Concept)
game.connects4InMoves(player, 3) <=> (Predefined Pattern Function)
Ǝ xExistsMove: (Start Exists Move Concept)
xExistsMove >= 0 and
xExistsMove < xMax:
game.afterMove(xExistsMove).connects4InMoves(player, 2) = true
Ǝend xExistsMove (End Exists Move Concept) and
game.connects4InMoves(player, 1) = false
game.connects4InMoves(player, 4) <=> (Predefined Pattern Function)
∀ xAll4Move: (Start For All Move Concept)
xAll4Move >= 0 and
xAll4Move < xMax and
game.matrix.yEmpty(xAll4Move) < yMax - 1:
game.afterMove(xAll4Move).connects4InMoves(player, 3) = true
∀end xAll4Move (End For All Move Concept)
matrix.pppp(player) <=> (Predefined Pattern Function)
Ǝ x0, y0: (Start Vertical Pattern with bottom coordinates x0, y0)
x0 >= 0 and
x0 < xMax and
y0 >= 0 and
y0 < yMax - conn:
∀ extent: (Start All Extent: Connect in a Vertical Row Pattern)
extent >= 0 and
extent < conn:
matrix(x0, y0 + extent) = player
∀end extent (End All Extent: Connect in a Vertical Row Pattern) and
matrix.yEmpty(x0) = y0 + conn
Ǝend x0, y0 (End Vertical Pattern with bottom coordinates x0, y0) or
Ǝ x0, y0: (Start Horizontal Pattern with left coordinates x0, y0)
x0 >= 0 and
x0 < xMax - conn and
y0 >= 0 and
y0 < yMax:
∀ extent: (Start All Extent: Connect in a Horizontal Row Pattern)
extent >= 0 and
extent < conn:
matrix(x0 + extent, y0) = player
∀end extent (End All Extent: Connect in a Horizontal Row Pattern) and
Ǝ pmEx: (Start Exists Previous Move Extent with Empty Position Above)
pmEx >= 0 and
pmEx < conn:
matrix.yEmpty(x0 + pmEx) = y0 + 1
Ǝend pmEx (End Exists Previous Move Extent with Empty Position Above)
Ǝend x0, y0 (End Horizontal Pattern with left coordinates x0, y0) or
Ǝ x0, y0: (Start Diagonal Up Pattern with bottom-left coordinates x0, y0)
x0 >= 0 and
x0 < xMax - conn and
y0 >= 0 and
y0 < yMax - conn:
∀ extent: (Start All Extent: Connect in a Diagonal Up Row Pattern)
extent >= 0 and
extent < conn:
matrix(x0 + extent, y0 + extent) = player
∀end extent (End All Extent: Connect in a Diagonal Up Row Pattern) and
Ǝ pmEx: (Start Exists Previous Move Extent with Empty Position Above)
pmEx >= 0 and
pmEx < conn:
matrix.yEmpty(x0 + pmEx) = y0 + pmEx + 1
Ǝend pmEx (End Exists Previous Move Extent with Empty Position Above)
Ǝend x0, y0 (End Diagonal Up Pattern with bottom-left coordinates x0, y0) or
Ǝ x0, y0: (Start Diagonal Down Pattern with top-left coordinates x0, y0)
x0 >= 0 and
x0 < xMax - conn and
y0 >= conn and
y0 < yMax:
∀ extent: (Start All Extent: Connect in a Diagonal Down Row Pattern)
extent >= 0 and
extent < conn:
matrix(x0 + extent, y0 - extent) = player
∀end extent (End All Extent: Connect in a Diagonal Down Row Pattern) and
Ǝ pmEx: (Start Exists Previous Move Extent with Empty Position Above)
pmEx >= 0 and
pmEx < conn:
matrix.yEmpty(x0 + pmEx) = y0 - pmEx + 1
Ǝend pmEx (End Exists Previous Move Extent with Empty Position Above)
Ǝend x0, y0 (End Diagonal Down Pattern with top-left coordinates x0, y0)
game.connects4InMoves(player, 0) <=> (Predefined Pattern Function)
game.matrix.pppp(player) = true and
game.toMove = opponent(player)
game.afterMove(xMove) <=> (Predefined Pattern Function)
game.matrix.yEmpty(xMove) < yMax - 1 and
game.afterMove(xMove).toMove = opponent(game.toMove) and
game.afterMove(xMove).matrix(xMove, game.matrix.yEmpty(xMove)) = game.toMove and
game.afterMove(xMove).matrix.yEmpty(xMove) = game.matrix.yEmpty(xMove) + 1 and
∀ x, y: (Start Matrix after move equals matrix before move except the new Disk)
x >= 0 and
x < xMax and
y >= 0 and
y < yMax and
(x != xMove or
y != game.matrix.yEmpty(xMove)):
game.afterMove(xMove).matrix(x, y) = game.matrix(x, y)
∀end x, y (End Matrix after move equals matrix before move except the new Disk)
matrix.reppp(player, red, rex) <=> (Predefined Pattern Function)
Ǝ x0, y0: (Start Vertical Pattern with bottom coordinates x0, y0)
x0 >= 0 and
x0 < xMax and
y0 >= 0 and
y0 < yMax - conn:
∀ extent: (Start All Extent: Connect in a Vertical Row Pattern)
extent >= 0 and
extent < conn - 1:
matrix(x0, y0 + extent) = player
∀end extent (End All Extent: Connect in a Vertical Row Pattern) and
matrix.yEmpty(rex) = y0 + conn - 1 - red and
rex = x0
Ǝend x0, y0 (End Vertical Pattern with bottom coordinates x0, y0) or
Ǝ x0, y0: (Start Horizontal Pattern with left coordinates x0, y0)
x0 >= 0 and
x0 < xMax - conn and
y0 >= 0 and
y0 < yMax:
∀ extent: (Start All Extent: Connect in a Horizontal Row Pattern)
extent >= 0 and
extent < conn and
extent != rexEx:
matrix(x0 + extent, y0) = player
∀end extent (End All Extent: Connect in a Horizontal Row Pattern) and
Ǝ rexEx: (Start re0 Extent: Extent of the Rotatable Empty position in the re0ppp Pattern)
rexEx >= 0 and
rexEx < conn:
matrix.yEmpty(rex) = y0 - red and
rex = x0 + rexEx
Ǝend rexEx (End re0 Extent: Extent of the Rotatable Empty position in the re0ppp Pattern)
Ǝend x0, y0 (End Horizontal Pattern with left coordinates x0, y0) or
Ǝ x0, y0: (Start Diagonal Up Pattern with bottom-left coordinates x0, y0)
x0 >= 0 and
x0 < xMax - conn and
y0 >= 0 and
y0 < yMax - conn:
∀ extent: (Start All Extent: Connect in a Diagonal Up Row Pattern)
extent >= 0 and
extent < conn and
extent != rexEx:
matrix(x0 + extent, y0 + extent) = player
∀end extent (End All Extent: Connect in a Diagonal Up Row Pattern) and
Ǝ rexEx: (Start re0 Extent: Extent of the Rotatable Empty position in the re0ppp Pattern)
rexEx >= 0 and
rexEx < conn:
matrix.yEmpty(rex) = y0 + rexEx - red and
rex = x0 + rexEx
Ǝend rexEx (End re0 Extent: Extent of the Rotatable Empty position in the re0ppp Pattern)
Ǝend x0, y0 (End Diagonal Up Pattern with bottom-left coordinates x0, y0) or
Ǝ x0, y0: (Start Diagonal Down Pattern with top-left coordinates x0, y0)
x0 >= 0 and
x0 < xMax - conn and
y0 >= conn and
y0 < yMax:
∀ extent: (Start All Extent: Connect in a Diagonal Down Row Pattern)
extent >= 0 and
extent < conn and
extent != rexEx:
matrix(x0 + extent, y0 - extent) = player
∀end extent (End All Extent: Connect in a Diagonal Down Row Pattern) and
Ǝ rexEx: (Start re0 Extent: Extent of the Rotatable Empty position in the re0ppp Pattern)
rexEx >= 0 and
rexEx < conn:
matrix.yEmpty(rex) = y0 - rexEx - red and
rex = x0 + rexEx
Ǝend rexEx (End re0 Extent: Extent of the Rotatable Empty position in the re0ppp Pattern)
Ǝend x0, y0 (End Diagonal Down Pattern with top-left coordinates x0, y0)
game.connects4InMoves(player, 1) = true <=> (Deduced Pattern)
game.matrix.reppp(player, 0, rex) = true and
game.toMove = player and
game.matrix.pppp(opponent(player)) = false
game.afterMove(xMove).matrix.pppp(player) = true <=> (Deduced Pattern)
((game.matrix.reppp(player, 0, xMove) = true and
game.toMove = player) or
game.matrix.pppp(player) = true)
game.afterMove(xMove).matrix.reppp(player, 0, rex) = true <=> (Deduced Pattern)
((xMove = rex and
game.matrix.reppp(player, 1, xMove) = true) or
(xMove != rex and
game.matrix.reppp(player, 0, rex) = true) or
(game.toMove = player and
game.matrix.rerepp(player, 0, xMove, 0, re2x) = true) or
(game.toMove = player and
game.matrix.vrep(player, 1, xMove) = true))
game.afterMove(xMove).matrix.reppp(player, 1, rex) = true <=> (Deduced Pattern)
((xMove = rex and
game.matrix.reppp(player, 2, xMove) = true) or
(xMove != rex and
game.matrix.reppp(player, 1, rex) = true) or
(game.toMove = player and
game.matrix.rerepp(player, 0, xMove, 1, rex) = true))
game.afterMove(xMove).matrix.reppp(player, 2, rex) = true <=> (Deduced Pattern)
((xMove = rex and
game.matrix.reppp(player, 3, xMove) = true) or
(xMove != rex and
game.matrix.reppp(player, 2, rex) = true) or
(game.toMove = player and
game.matrix.rerepp(player, 0, xMove, 2, rex) = true))
game.afterMove(xMove).matrix.rerepp(player, 0, re1x, 1, re2x) = true <=> (Deduced Pattern)
((xMove = re1x and
game.matrix.rerepp(player, 1, xMove, 1, re2x) = true) or
(xMove = re2x and
game.matrix.rerepp(player, 0, re1x, 2, xMove) = true) or
(xMove != re1x and
xMove != re2x and
game.matrix.rerepp(player, 0, re1x, 1, re2x) = true) or
(game.toMove = player and
game.matrix.rererep(player, 0, xMove, 0, re2x, 1, re3x) = true) or
(game.toMove = player and
game.matrix.rererep(player, 0, re1x, 0, xMove, 1, re3x) = true) or
(game.toMove = player and
game.matrix.vrep(player, 2, xMove) = true))
game.afterMove(xMove).toMove = player <=> (Deduced Pattern)
game.toMove = opponent(player)
game.afterMove(xMove).toMove = opponent(player) <=> (Deduced Pattern)
game.toMove = player
game.connects4InMoves(player, 2) <=> (Deduced Pattern)
((∀ xMove: (Start For All Move Concept)
xMove >= 0 and
xMove < xMax and
game.matrix.yEmpty(xMove) < yMax - 1:
game.matrix.reppp(player, 1, xMove) = true
∀end xMove (End For All Move Concept) and
game.matrix.reppp(player, 1, rex) = true) or
(x1 != x2 and
game.matrix.reppp(player, 0, x1) = true and
game.matrix.reppp(player, 0, x2) = true) or
(game.matrix.reppp(player, 1, xs) = true and
game.matrix.reppp(player, 0, xs) = true)) and
game.toMove = opponent(player) and
game.matrix.reppp(opponent(player), 0, rex) = false and
game.matrix.pppp(opponent(player)) = false
|