Entropy42 wrote:I have a 3 dimensional array with sequentially numbered keys, and the for loop is always grabbing the first key. On every iteration k=1 and pattern is always the 7x2 array in the patterns[1] definition.
Code: Select all
patterns := Object()
patterns[1] := [ [-2,0] , [-1,0] , [1,0] , [2,0] , [0,-1] , [0,-2] , [0,1] ] ; check for 8 gem Ts (only possible from cascades)
patterns[2] := [ [0,-2] , [0,-1] , [0,-1] , [0,-2] , [-1,0] , [-2,0] , [1,0] ]
patterns[3] := [ [-2,0] , [-1,0] , [1,0] , [2,0] , [0,1] , [0,2] , [0,-1] ]
patterns[4] := [ [0,1] , [0,2] , [0,-1] , [0,-2] , [1,0] , [2,0] , [-1,0] ]
patterns[5] := [ [-2,0] , [-1,0] , [1,0] , [2,0] , [0,-1] , [0,-2] ] ; check for 7 gem Ts
patterns[6] := [ [0,-2] , [0,-1] , [0,-1] , [0,-2] , [-1,0] , [-2,0] ]
patterns[7] := [ [-2,0] , [-1,0] , [1,0] , [2,0] , [0,1] , [0,2] ]
patterns[8] := [ [0,1] , [0,2] , [0,-1] , [0,-2] , [1,0] , [2,0] ]
while patternMatch(board, results, patterns)
{
resolveCascades(board) ; found matches resulting from the previous moves, move gems down and check again
clipboard = % clipboard "`r`n" "Board after cascades:`r`n" . printBoard(board)
}
patternMatch(board, results, patterns)
{
matchFound := false
for k, pattern in patterns ; For each pattern, starting with the biggest, loop through the whole grid and try to find it
{
Loop, 8
{
y := A_Index
Loop, 8
{
x := A_Index
col := board[x,y]
if (col = 0) ; If we are checking an empty square, go to the next square and check no patterns
continue
}
}
}
return matchFound
}
"
for k, pattern in patterns" <-- This loops through patterns 1-8. Then inside the loop you make no mention of
pattern.
To loop over each element:
Code: Select all
patterns := []
patterns[1] := [ [-2,0], [-1,0], [1, 0], [2, 0], [0,-1], [0,-2], [0, 1] ]
patterns[2] := [ [0,-2], [0,-1], [0,-1], [0,-2], [-1,0], [-2,0], [1, 0] ]
patterns[3] := [ [-2,0], [-1,0], [1, 0], [2, 0], [0, 1], [0, 2], [0,-1] ]
patterns[4] := [ [0, 1], [0, 2], [0,-1], [0,-2], [1, 0], [2, 0], [-1,0] ]
patterns[5] := [ [-2,0], [-1,0], [1, 0], [2, 0], [0,-1], [0,-2] ]
patterns[6] := [ [0,-2], [0,-1], [0,-1], [0,-2], [-1,0], [-2,0] ]
patterns[7] := [ [-2,0], [-1,0], [1, 0], [2, 0], [0, 1], [0, 2] ]
patterns[8] := [ [0, 1], [0, 2], [0,-1], [0,-2], [1, 0], [2, 0] ]
for PatternNumber, Pattern in Patterns
{
for OffsetNumber, Offset in Pattern
{
MsgBox, % "PatternNumber: " PatternNumber "`n"
. "OffsetNumber: " OffsetNumber "`n"
. "Offset 1: " Offset[1] "`n"
. "Offset 2: " Offset[2]
}
}
Entropy42 wrote:After posting this, I replaced the "for k, pattern in patterns" with "Loop, % patterns.MaxIndex()", and the A_index value wasn't incrementing either.
I think you are misunderstanding. I would be interested to see some actual code. Descriptions of code only tell us what you
think is happening.
Loop, % patterns.MaxIndex() is (basically) just a less-elegant way or writing a for-loop.
Code: Select all
patterns := []
patterns[1] := [ [-2,0], [-1,0], [1, 0], [2, 0], [0,-1], [0,-2], [0, 1] ]
patterns[2] := [ [0,-2], [0,-1], [0,-1], [0,-2], [-1,0], [-2,0], [1, 0] ]
patterns[3] := [ [-2,0], [-1,0], [1, 0], [2, 0], [0, 1], [0, 2], [0,-1] ]
patterns[4] := [ [0, 1], [0, 2], [0,-1], [0,-2], [1, 0], [2, 0], [-1,0] ]
patterns[5] := [ [-2,0], [-1,0], [1, 0], [2, 0], [0,-1], [0,-2] ]
patterns[6] := [ [0,-2], [0,-1], [0,-1], [0,-2], [-1,0], [-2,0] ]
patterns[7] := [ [-2,0], [-1,0], [1, 0], [2, 0], [0, 1], [0, 2] ]
patterns[8] := [ [0, 1], [0, 2], [0,-1], [0,-2], [1, 0], [2, 0] ]
Loop, % patterns.MaxIndex()
{
PatternNumber := A_Index
Loop, % patterns[A_Index].MaxIndex()
{
MsgBox, % "PatternNumber: " PatternNumber "`n"
. "OffsetNumber: " A_Index "`n"
. "Offset 1: " patterns[PatternNumber, A_Index, 1] "`n"
. "Offset 2: " patterns[PatternNumber, A_Index, 2]
}
}