How to find matches in a 2D array?

Hi,

I am building a small brick game and I need some hints on how to find matching pairs.

For example:

0 0 0
1 0 0
1 1 0

or this example

1 1 1
0 0 0
0 0 0

I do need some hints on how to approach this. I want a function that returns all matches. The array is 2D.

Joakim [import]uid: 81188 topic_id: 16373 reply_id: 316373[/import]

I know I know, 2-dimensional… just thinking loudly:

local t1 = {0,0,0,0,0,0,1,1,1}  
local combo = {1,1,1}  
  
function checkCombo (theCombo)  
 local comboTable = theCombo  
 for i, theVal in pairs(t1) do  
 if t1[i] == comboTable [1] and t1[i+1] == comboTable [2] and t1[i+2] == comboTable [3] then  
 print ("combo found at "..i)   
 end   
 end  
end  
  
checkCombo (combo)  

far from perfect and not precisely what you asked for, but maybe you get the idea… and code a better one :slight_smile:

-finefin [import]uid: 70635 topic_id: 16373 reply_id: 61081[/import]