xerpi

wfrwqq

Jul 1st, 2011
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | None | 0 0
  1. function functions.check(array)
  2.     local cont = {hor_right = 1,hor_left = 1,ver_up = 1,ver_down = 1,dia_up_inc = 1,dia_up_dec = 1,dia_down_inc = 1,dia_down_dec = 1};
  3.     local completed = true;
  4.     local s = "";
  5.     for y = #array.table , 1,-1 do
  6.         for x = 1, #array.table[y] do
  7.             if array.table[y][x] == "" then completed = false; end --board completed
  8.             if array.table[y][x] != "" then            
  9.                 s = array.table[y][x]
  10.                 for i = 1, array.n-1 do
  11.                     if fb(array,x+i,y) and array.table[y][x+i] == s then cont.hor_right = cont.hor_right+1 end
  12.                     if fb(array,x,y+i) and array.table[y+i][x] == s then cont.ver_down = cont.ver_down+1 end
  13.                     if fb(array,x-i,y) and array.table[y][x-i] == s then cont.hor_left = cont.hor_left+1 end
  14.                     if fb(array,x,y-i) and array.table[y-i][x] == s then cont.ver_up = cont.ver_up+1 end
  15.                     if fb(array,x+i,y-i) and array.table[y-i][x+i] == s then cont.dia_up_dec = cont.dia_up_dec + 1 end
  16.                     if fb(array,x-i,y-i) and array.table[y-i][x-i] == s then cont.dia_up_inc = cont.dia_up_inc + 1 end
  17.                     if fb(array,x+i,y+i) and array.table[y+i][x+i] == s then cont.dia_down_inc = cont.dia_down_inc + 1 end
  18.                     if fb(array,x-i,y+i) and array.table[y+i][x-i] == s then cont.dia_down_dec = cont.dia_down_dec+1 end                   
  19.                 end
  20.                 if cont.hor_right >= array.n then return s end cont.hor_right = 1;
  21.                 if cont.hor_left >= array.n then return s end cont.hor_left = 1;                   
  22.                 if cont.ver_up >= array.n then return s end cont.ver_up = 1;
  23.                 if cont.ver_down >= array.n then return s end cont.ver_down = 1;                   
  24.                 if cont.dia_up_inc >= array.n then return s end cont.dia_up_inc = 1;               
  25.                 if cont.dia_down_inc >= array.n then return s end cont.dia_down_inc = 1;   
  26.                 if cont.dia_up_dec >= array.n then return s end cont.dia_up_dec = 1;               
  27.                 if cont.dia_down_dec >= array.n then return s end cont.dia_down_dec = 1;
  28.                 cont = {hor_right = 1,hor_left = 1,ver_up = 1,ver_down = 1,dia_up_inc = 1,dia_up_dec = 1,dia_down_inc = 1,dia_down_dec = 1};
  29.                
  30.             end
  31.         end
  32.     end
  33.     return completed;
  34. end
Add Comment
Please, Sign In to add comment