I am working on my second game (anxiously waiting for app store approval on first)
Basically the game will have a 3X3 grid of shuffled cards and I need to detect any vertically or horizontally adjacent 3 or more of a kind, sequences of 3 or more of any suit, sequences of 3 or more of the same suit.
Please look at: http://dl.dropbox.com/u/11235/cards.png for a diagram
I am having a heck of a time coming up with the logic to do that. Is there a good resource for figuring out this kind of logic. Here is the code I started to write. Right now it only checks for single matches and its getting very convoluted. There has to be a better way!
[code]
local c11, c21, c31, c12, c22, c32, c13, c23, c33
local row1, row2, row3, col1, col2, col3
–create deck
local cards = {}
for b = 1, 4 do
for i=1,14 do
local myCard = {b,i}
table.insert ( cards, myCard )
end
end
–shuffle deck
local shuffledCards = {}
while #cards > 0 do
randNum =math.random(1,#cards)
randPick = cards[randNum]
table.insert ( shuffledCards, randPick )
table.remove ( cards, randNum )
end
– put first 9 into grid cels
c11 = {shuffledCards[1]}
c21 = {shuffledCards[2]}
c31 = {shuffledCards[3]}
c12 ={shuffledCards[4]}
c22 ={shuffledCards[5]}
c32 = {shuffledCards[6]}
c13 = {shuffledCards[7]}
c23 = {shuffledCards[8]}
c33 = {shuffledCards[9]}
–put cells into row arrays
row1 = {c11, c21, c31}
row2 = {c12,c22,c32}
row3 = {c13,c23,c33}
–put cells into collums arrays
col1 = {c11, c12, c13}
col2 = {c21, c22, c23}
col2 = {c31, c32, c33}
–find matches
if row1[1][1][2] == row1[2][1][2] then print(“match on row 1!”)end
if row1[2][1][2] == row1[3][1][2] then print(“match! on row 1!”)end
if row2[1][1][2] == row2[2][1][2] then print(“match on row 2!”)end
if row2[2][1][2] == row2[3][1][2] then print(“match on row 2!”)end
if row3[1][1][2] == row3[2][1][2] then print(“match on row 3!”)end
if row3[2][1][2] == row3[3][1][2] then print(“match on row 3!”)end
if row1[1][1][2] == row2[1][1][2] then print(“match on col1!”)end
if row2[1][1][2] == row3[1][1][2] then print(“match on col1!”)end
if row1[2][1][2] == row2[2][1][2] then print(“match on col1!”)end
if row2[2][1][2] == row3[2][1][2] then print(“match on col1!”)end
if row1[3][1][2] == row2[3][1][2] then print(“match on col1!”)end
if row2[3][1][2] == row3[3][1][2] then print(“match on col1!”)end
[/code] [import]uid: 6310 topic_id: 15684 reply_id: 315684[/import]
[import]uid: 3826 topic_id: 15684 reply_id: 58185[/import]