Advertisement
xerpi

ESE ROBER !!!!!

Jul 9th, 2011
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.57 KB | None | 0 0
  1.                 function board.check()
  2.                         local cont = {hor_right = 1,ver_up = 1,dia_up_dec = 1,dia_up_inc = 1};
  3.                         local completed = true;
  4.                         local s = "";
  5.                         for j = 1, board.depth do
  6.                             cont = {hor_right = 1,ver_up = 1,dia_up_dec = 1,dia_up_inc = 1}; --Reset it for every depth
  7.                             for y = board.height , 1,-1 do
  8.                                 for x = 1, board.width do
  9.                                     if board.table[j][y][x] == "" then completed = false; end --board completed
  10.                                     if board.table[j][y][x] != "" then             
  11.                                         s = board.table[j][y][x]
  12.                                         for i = 1, board.row-1 do --check all directions, horizontal, vertical and diagonal
  13.                                             if board.inside(x+i,y) and board.table[j][y][x+i] == s then cont.hor_right = cont.hor_right+1 end
  14.                                             if board.inside(x,y-i) and board.table[j][y-i][x] == s then cont.ver_up = cont.ver_up+1 end
  15.                                             if board.inside(x+i,y-i) and board.table[j][y-i][x+i] == s then cont.dia_up_dec = cont.dia_up_dec + 1 end
  16.                                             if board.inside(x-i,y-i) and board.table[j][y-i][x-i] == s then cont.dia_up_inc = cont.dia_up_inc + 1 end          
  17.                                         end
  18.                                         if cont.hor_right >= board.row then return s,x,y,j,"right" end cont.hor_right = 1;
  19.                                         if cont.ver_up >= board.row then return s,x,y,j,"up" end cont.ver_up = 1;
  20.                                         if cont.dia_up_inc >= board.row then return s,x,y,j,"up_inc" end cont.dia_up_inc = 1;              
  21.                                         if cont.dia_up_dec >= board.row then return s,x,y,j,"up_dec" end cont.dia_up_dec = 1;              
  22.                                     end
  23.                                 end
  24.                             end
  25.                         end
  26.                         if completed then return "tie" else return false end                           
  27.                 end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement