Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function board.check()
- local cont = {hor_right = 1,ver_up = 1,dia_up_dec = 1,dia_up_inc = 1};
- local completed = true;
- local s = "";
- for j = 1, board.depth do
- cont = {hor_right = 1,ver_up = 1,dia_up_dec = 1,dia_up_inc = 1}; --Reset it for every depth
- for y = board.height , 1,-1 do
- for x = 1, board.width do
- if board.table[j][y][x] == "" then completed = false; end --board completed
- if board.table[j][y][x] != "" then
- s = board.table[j][y][x]
- for i = 1, board.row-1 do --check all directions, horizontal, vertical and diagonal
- if board.inside(x+i,y) and board.table[j][y][x+i] == s then cont.hor_right = cont.hor_right+1 end
- if board.inside(x,y-i) and board.table[j][y-i][x] == s then cont.ver_up = cont.ver_up+1 end
- 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
- 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
- end
- if cont.hor_right >= board.row then return s,x,y,j,"right" end cont.hor_right = 1;
- if cont.ver_up >= board.row then return s,x,y,j,"up" end cont.ver_up = 1;
- if cont.dia_up_inc >= board.row then return s,x,y,j,"up_inc" end cont.dia_up_inc = 1;
- if cont.dia_up_dec >= board.row then return s,x,y,j,"up_dec" end cont.dia_up_dec = 1;
- end
- end
- end
- end
- if completed then return "tie" else return false end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement