Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IA = {}
- function IA.play(str,mode)
- local x;
- local y;
- local d;
- if str == "easy" then -- Easy mode, everything is random
- if mode == "3D" then
- y = math.random(1,board.height)
- x = math.random(1,board.width)
- d = math.random(1,board.depth)
- while true do
- y = math.random(1,board.height)
- x = math.random(1,board.width)
- d = math.random(1,board.depth)
- if board.table[d][y][x] == "" then
- board.table[d][y][x] = board.player[board.turn].st
- return true;
- end
- end
- elseif mode == "C4" then
- y = board.height
- d = math.random(1,board.depth)
- x = math.random(1,board.width)
- while true do
- d = math.random(1,board.depth)
- x = math.random(1,board.width)
- for i = board.height, 1, -1 do
- if board.table[d][i][x] == "" then
- board.table[d][i][x] = board.player[board.turn].st
- return true;
- end
- end
- end
- end
- elseif str == "medium" then
- local cont = {horizontal = 1,vertical = 1,dia_up = 1,dia_down = 1};
- local t = "";
- for n = board.row-1, 1, -1 do
- for d = 1, board.depth do
- for y = 1,board.height do
- for x = 1, board.width do
- cont = {horizontal = 1,vertical = 1,dia_up = 1,dia_down = 1};
- t = board.table[d][y][x]
- if t != "" then --The current chip is not empty.
- for r = 1, n do
- if board.inside(x+r,y) and board.table[d][y][x+r] == t then cont.horizontal = cont.horizontal +1 end --Horizontal
- if board.inside(x,y+r) and board.table[d][y+r][x] == t then cont.vertical = cont.vertical +1 end --Vertical
- if board.inside(x+r,y-r) and board.table[d][y-r][x+r] == t then cont.dia_up = cont.dia_up +1 end --Diagonal up
- if board.inside(x+r,y+r) and board.table[d][y+r][x+r] == t then cont.dia_down = cont.dia_down +1 end --Diagonal down
- end
- if cont.horizontal >= n then --Horizontal
- if board.inside(x+n,y) and board.table[d][y][x+n] == "" then
- board.table[d][y][x+n] = board.player[board.turn].st
- return true
- end
- if board.inside(x-1,y) and board.table[d][y][x-1] == "" then
- board.table[d][y][x-1] = board.player[board.turn].st
- return true
- end
- end
- if cont.vertical >= n then --Vertical
- if board.inside(x,y+n) and board.table[d][y+n][x] == "" then
- board.table[d][y+n][x] = board.player[board.turn].st
- return true
- end
- if board.inside(x,y-1) and board.table[d][y-1][x] == "" then
- board.table[d][y-1][x] = board.player[board.turn].st
- return true
- end
- end
- if cont.dia_up >= n then --Diagonal up
- if board.inside(x+n,y-n) and board.table[d][y-n][x+n] == "" then
- board.table[d][y-n][x+n] = board.player[board.turn].st
- return true
- end
- if board.inside(x-1,y+1) and board.table[d][y+1][x-1] == "" then
- board.table[d][y+1][x-1] = board.player[board.turn].st
- return true
- end
- end
- if cont.dia_down >= n then --Diagonal down
- if board.inside(x+n,y+n) and board.table[d][y+n][x+n] == "" then
- board.table[d][y+n][x+n] = board.player[board.turn].st
- return true
- end
- if board.inside(x-1,y-1) and board.table[d][y-1][x-1] == "" then
- board.table[d][y-1][x-1] = board.player[board.turn].st
- return true
- end
- end
- end
- end
- end
- end
- end
- elseif str == "hard" then
- --
- end
- return false;
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement