It looks like you're new here. If you want to get involved, click one of these buttons!
---create an rand rows * columns array filled with 1,2,3 in num cells local function randarray(rows, columns, num) math.randomseed(os.time()) local array = {} local tmp = {} for i = 1, rows do tmp[i] = {} array[i] = {} for j = 1, columns do tmp[i][j] = {i, j} array[i][j] = 0 end end for k = 1, num do local r = math.random(#tmp) local c = math.random(#tmp[r]) --print(r..'|'..c) local r1, c1 = tmp[r][c][1], tmp[r][c][2], table.remove(tmp[r], c) if #tmp[r] == 0 then table.remove(tmp, r) end array[r1][c1] = math.random(3) end for i = 1, #array do print(unpack(array[i])) end end randarray(10, 10, 80) |
Comments
To do that - run over the array and then for each cell, check it's (potentially) four neighbours, the easiest way is to call a function that just moves along the array in the given direction returning the number of continuous matches, if they are >= 3 then you have to change the value (ideally pick one that isn't one of the four neighbours) and start again at the beginning.
Obviously when you can process the entire table and each function returns < 3 matches your job is done.
It may take a few dozen iterations to get right to the end of the table, but considering the speed of Gideros you won't notice it.
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
May be any clever way can do.
https://sites.google.com/site/xraystudiogame
https://sites.google.com/site/xraystudiogame
https://sites.google.com/site/xraystudiogame