Advertisement
xerpi

3DnRaya best IA

Jul 10th, 2011
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. IA = {}
  2.  
  3. function IA.play(str,mode)
  4. local x;
  5. local y;
  6. local d;
  7. if str == "easy" then  -- Easy mode, everything is random
  8.     if mode == "3D" then
  9.         y = math.random(1,board.height)
  10.         x = math.random(1,board.width)
  11.         d = math.random(1,board.depth)
  12.         while true do
  13.             y = math.random(1,board.height)
  14.             x = math.random(1,board.width)
  15.             d = math.random(1,board.depth)
  16.             if board.table[d][y][x] == "" then
  17.                 board.table[d][y][x] = board.player[board.turn].st
  18.                 return true;
  19.             end
  20.         end
  21.     elseif mode == "C4" then
  22.         y = board.height
  23.         d = math.random(1,board.depth)
  24.         x = math.random(1,board.width)
  25.         while true do
  26.             d = math.random(1,board.depth)
  27.             x = math.random(1,board.width)
  28.             for i = board.height, 1, -1 do
  29.                 if board.table[d][i][x] == "" then
  30.                     board.table[d][i][x] = board.player[board.turn].st
  31.                     return true;
  32.                 end
  33.             end
  34.         end
  35.     end
  36.    
  37. elseif str == "medium" then
  38.         local cont = {horizontal = 1,vertical = 1,dia_up = 1,dia_down = 1};
  39.         local t = "";
  40.         for n = board.row-1, 1, -1 do
  41.             for d = 1, board.depth do
  42.                 for y = 1,board.height do
  43.                     for x = 1, board.width do
  44.                         cont = {horizontal = 1,vertical = 1,dia_up = 1,dia_down = 1};
  45.                         t = board.table[d][y][x]
  46.                         if t != "" then --The current chip is not empty.
  47.                             for r = 1, n do
  48.                                 if board.inside(x+r,y) and board.table[d][y][x+r] == t then cont.horizontal = cont.horizontal +1 end    --Horizontal
  49.                                 if board.inside(x,y+r) and board.table[d][y+r][x] == t then cont.vertical = cont.vertical +1 end    --Vertical
  50.                                 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
  51.                                 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            
  52.                             end
  53.                             if cont.horizontal >= n then --Horizontal
  54.                                     if board.inside(x+n,y) and board.table[d][y][x+n] == "" then
  55.                                         board.table[d][y][x+n] = board.player[board.turn].st
  56.                                         return true
  57.                                     end
  58.                                     if board.inside(x-1,y) and board.table[d][y][x-1] == "" then
  59.                                         board.table[d][y][x-1] = board.player[board.turn].st
  60.                                         return true
  61.                                     end
  62.                             end                    
  63.                             if cont.vertical >= n then --Vertical
  64.                                     if board.inside(x,y+n) and board.table[d][y+n][x] == "" then
  65.                                         board.table[d][y+n][x] = board.player[board.turn].st
  66.                                         return true
  67.                                     end
  68.                                     if board.inside(x,y-1) and board.table[d][y-1][x] == "" then
  69.                                         board.table[d][y-1][x] = board.player[board.turn].st
  70.                                         return true
  71.                                     end
  72.                             end
  73.                             if cont.dia_up >= n then --Diagonal up
  74.                                     if board.inside(x+n,y-n) and board.table[d][y-n][x+n] == "" then
  75.                                         board.table[d][y-n][x+n] = board.player[board.turn].st
  76.                                         return true
  77.                                     end
  78.                                     if board.inside(x-1,y+1) and board.table[d][y+1][x-1] == "" then
  79.                                         board.table[d][y+1][x-1] = board.player[board.turn].st
  80.                                         return true
  81.                                     end
  82.                             end
  83.                             if cont.dia_down >= n then  --Diagonal down
  84.                                     if board.inside(x+n,y+n) and board.table[d][y+n][x+n] == "" then
  85.                                         board.table[d][y+n][x+n] = board.player[board.turn].st
  86.                                         return true
  87.                                     end
  88.                                     if board.inside(x-1,y-1) and board.table[d][y-1][x-1] == "" then
  89.                                         board.table[d][y-1][x-1] = board.player[board.turn].st
  90.                                         return true
  91.                                     end                                                    
  92.                             end
  93.                         end
  94.                     end
  95.                 end
  96.             end
  97.         end
  98. elseif str == "hard" then
  99.     --
  100. end
  101. return false;
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement