Advertisement
alestane

Loop reduction

Apr 18th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.78 KB | None | 0 0
  1. local function checkForMatch(circle)
  2.     local game = circle.parent
  3.     local circles = game.circles
  4.     local matches = {}
  5.     matches.number = 1
  6.     matches[circle] = circle
  7.     local function recurse(circle)
  8.         for i, circle2 in pairs(circles) do
  9.             if isMatch(circle, circle2) and not matches[circle2] then
  10.                 matches[circle2] = circle2
  11.                 matches.number = matches.number + 1
  12.                 recurse(circle2)
  13.             end
  14.         end
  15.     end
  16.     recurse(circle)
  17.     if matches.number > 2 then
  18.         for i, circle in pairs(matches) do
  19.             local i2 = table.indexOf(circles, circle)
  20.             if i2 then
  21.                 table.remove(circles, i2)
  22.             end
  23.             circle:removeSelf()
  24.         end
  25.     end
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement