Advertisement
Guest User

Untitled

a guest
Dec 28th, 2016
687
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.02 KB | None | 0 0
  1. require"bot"
  2. math.randomseed(os.time())
  3.  
  4. local moves = {[0]='','','',['-']='',['=']=''}
  5.  
  6. local team1 = {}
  7. local team2 = {}
  8.  
  9. for i=1, 9 do
  10.     team1[#team1+1] = bot.new()
  11.     team2[#team2+1] = bot.new()
  12. end
  13.  
  14. local games = 100000
  15.  
  16. local p = print
  17. function print() end
  18. for i=1, games do
  19.  
  20.     for k,v in pairs(team1) do
  21.         v.wins = 0
  22.     end
  23.  
  24.     for k,v in pairs(team2) do
  25.         v.wins = 0
  26.     end
  27.  
  28.     for _,bot1 in pairs(team1) do
  29.         for _,bot2 in pairs(team2) do
  30.             -- New game.
  31.             local ammo1 = 0
  32.             local ammo2 = 0
  33.  
  34.             local n = 0
  35.  
  36.             local b1Dead = false
  37.             local b2Dead = false
  38.             while true do
  39.  
  40.                 local move1 = bot1.try(ammo1,ammo2)
  41.                 local move2 = bot2.try(ammo2,ammo1)
  42.  
  43.                 if i == games then print(move1,move2) end
  44.  
  45.                 if not moves[move1] then
  46.                     b1Dead = true
  47.                 end
  48.                 if not moves[move2] then
  49.                     b2Dead = true
  50.                 end
  51.  
  52.                 if b1Dead or b2Dead then
  53.                     print((b1Dead and "B1 has thrown an invalid move and lost.\n" or "")..
  54.                           (b2Dead and "B2 has thrown an invalid move and lost." or ""))
  55.                     break
  56.                 end
  57.  
  58.                 -- Move type 1, Increase ammo.
  59.                 if move1 == 0 then
  60.                     ammo1 = ammo1 + 1
  61.                 end
  62.                 if move2 == 0 then
  63.                     ammo2 = ammo2 + 1
  64.                 end
  65.  
  66.                 -- Move type 2. Fire boolet.
  67.                 if move1 == 1 then
  68.                     if ammo1 < 1 then
  69.                         b1Dead = true
  70.                     elseif (move2 ~= "-" and move2 ~= "2" and move2 ~= "1") then
  71.                         b2Dead = true
  72.                     end
  73.                     ammo1 = ammo1 - 1
  74.                 end
  75.                 if move2 == 1 then
  76.                     if ammo2 < 1 then
  77.                         b2Dead = true
  78.                     elseif (move1 ~= "-" and move1 ~= "2" and move1 ~= "1") then
  79.                         b1Dead = true
  80.                     end
  81.                     ammo2 = ammo2 - 1
  82.                 end
  83.  
  84.                 -- Move type 3. Fire Plasmaaaah.
  85.                 if move1 == 2 then
  86.                     if ammo1 < 2 then
  87.                         b1Dead = true
  88.                     elseif (move2 ~= "=" and move2 ~= "2") then
  89.                         b2Dead = true
  90.                     end
  91.                     ammo1 = ammo1 - 2
  92.                 end
  93.                 if move2 == 2 then
  94.                     if ammo2 < 2 then
  95.                         b2Dead = true
  96.                     elseif (move1 ~= "=" and move1 ~= "2") then
  97.                         b1Dead = true
  98.                     end
  99.                     ammo2 = ammo2 - 2
  100.                 end
  101.  
  102.                 if b1Dead or b2Dead then
  103.                     print((b1Dead and "B1 has failed to survive.\n" or "")..
  104.                           (b2Dead and "B2 has failed to survive." or ""))
  105.                     break
  106.                 end
  107.  
  108.                 n = n + 1
  109.                 if n>=10 then
  110.                     print("Both B1 and B2 are really tired, and have gone home.")
  111.                     b1Dead = true
  112.                     b2Dead = true
  113.                     break
  114.                 end
  115.  
  116.             end
  117.  
  118.             -- To the victor goes the spoils. <s>Yes, a draw is rewarded.</s> REWARDING DRAWS IS STUPID AND I'M STUPID.
  119.             if not b1Dead then bot1.wins = bot1.wins + 1 end
  120.             if not b2Dead then bot2.wins = bot2.wins + 1 end
  121.         end
  122.     end
  123.  
  124.     for k,v in pairs(team1) do
  125.         if v.wins > 4 then
  126.             v.reward()
  127.         else
  128.             v.punish()
  129.         end
  130.         v.lifetimeScore = v.lifetimeScore + v.wins
  131.     end
  132.     for k,v in pairs(team2) do
  133.         if v.wins > 4 then
  134.             v.reward()
  135.         else
  136.             v.punish()
  137.         end
  138.         v.lifetimeScore = v.lifetimeScore + v.wins
  139.     end
  140.  
  141. end
  142.  
  143. p("TEAM 1 WAS:")
  144. for k,v in pairs(team1) do
  145.     p(v.tostring())
  146. end
  147.  
  148. p()
  149. p("TEAM 2 WAS:")
  150. for k,v in pairs(team2) do
  151.     p(v.tostring())
  152. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement