codepad
[
create a new paste
]
login
|
about
Language:
C
C++
D
Haskell
Lua
OCaml
PHP
Perl
Plain Text
Python
Ruby
Scheme
Tcl
cubes = {} widthcubes = 6 heightcubes = 12 newheight = 12 newwidth = 6 pstr = "" rows = {} taken = 0 z = 0 zstr = "|" math.randomseed(os.time()) function newgrid() for i2 = 1, newwidth do cubes[i2] = {} for i = 1, newheight do cubes[i2][i] = {} end end for i = 1,newheight do for i2 = 1,newwidth do --cubes[i2] = {} colv = math.random(1,3) cubes[i2][i] = colv --colorv = colorv .. cubes[i][i2] end end widthcubes = newwidth heightcubes = newheight --draw out values zstr = "|" zstra = {} print("--CUBES COLOR VALUES:---") for i = 1,newheight do for i2 = 1,newwidth do zstr = zstr .. cubes[i2][i] .. "|" zstra[i] = zstr end --print(zstr) zstr = "|" end x = newheight for i = 1,newheight do print(zstra[x]) x = x - 1 end print("-------------------------------") print(" ") print("--BEGIN CHECKING:---") end function checkmatches() taken = 1 takingx = {} takingy = {} rows[1] = 0 pstr = "" z = 1 for cubey = 1, heightcubes do for cubex = 1, widthcubes do if (cubes[cubex][cubey] ~= 0) then checkingcol = cubes[cubex][cubey] --use dx and dy variables to simulate the directions to be checked for dx = -1,1 do -- (down, right, downleft, and downright) for dy = 0,1 do --special cases that don;t need to be checked if not (dx==0 and dy == 0) and not (dx == -1 and dy == 0) then local rowsize = 1 --how many of this color are in a straight line so far rows[z] = "start: " .. cubex rows[z] = rows[z] .. "," .. cubey while true do --find the cube that is, rowsize untis away in direction dx,dy local tempx,tempy = cubex+dx*rowsize,cubey+dy*rowsize --if out of range, stop now if tempx < 1 or tempy < 1 or tempx > #cubes or tempy > #cubes[1] then z = 1 break end --if same color ,add 1 to rowsize and keep going if cubes[tempx][tempy] == checkingcol then if ( z == 1 ) then print("Start new check: checking for " .. checkingcol) --rows[z] = "start: " .. cubex .. "," .. cubey rows[z] = cubex .. "," .. cubey z = z + 1 rows[z] = tempx .. "," .. tempy else rows[z] = tempx .. "," .. tempy --print(tempx,tempy) end rowsize = rowsize + 1 takingx[z] = tempx takingy[z] = tempy --rows[z] = rows[z] .. " : " .. takingx[z] .. "," .. takingy[z] print("Checked: " .. z) z = z + 1 taken = taken + 1 --if different color, stop now else --print(rows[z]) z = 1 break end end if rowsize >= 3 then print("Greater than 3: ") for i = 1, rowsize do print(rows[i]) end --found a row of 3 or more items of the same color! --if takingx[1] ~= "" then --do stuff here --for z2 = 1, rowsize do --print(rows[z])//////////////////////////////// --pstr = pstr .. takingx[zx] .. "," .. takingy[zx] .. " : " --end --z = 0 --end end end end end end end end print("-------------------------------") end newgrid() checkmatches() print(pstr)
Private
[
?
]
Run code
Submit