Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require"bot"
- math.randomseed(os.time())
- local moves = {[0]='','','',['-']='',['=']=''}
- local team1 = {}
- local team2 = {}
- for i=1, 9 do
- team1[#team1+1] = bot.new()
- team2[#team2+1] = bot.new()
- end
- local games = 100000
- local p = print
- function print() end
- for i=1, games do
- for k,v in pairs(team1) do
- v.wins = 0
- end
- for k,v in pairs(team2) do
- v.wins = 0
- end
- for _,bot1 in pairs(team1) do
- for _,bot2 in pairs(team2) do
- -- New game.
- local ammo1 = 0
- local ammo2 = 0
- local n = 0
- local b1Dead = false
- local b2Dead = false
- while true do
- local move1 = bot1.try(ammo1,ammo2)
- local move2 = bot2.try(ammo2,ammo1)
- if i == games then print(move1,move2) end
- if not moves[move1] then
- b1Dead = true
- end
- if not moves[move2] then
- b2Dead = true
- end
- if b1Dead or b2Dead then
- print((b1Dead and "B1 has thrown an invalid move and lost.\n" or "")..
- (b2Dead and "B2 has thrown an invalid move and lost." or ""))
- break
- end
- -- Move type 1, Increase ammo.
- if move1 == 0 then
- ammo1 = ammo1 + 1
- end
- if move2 == 0 then
- ammo2 = ammo2 + 1
- end
- -- Move type 2. Fire boolet.
- if move1 == 1 then
- if ammo1 < 1 then
- b1Dead = true
- elseif (move2 ~= "-" and move2 ~= "2" and move2 ~= "1") then
- b2Dead = true
- end
- ammo1 = ammo1 - 1
- end
- if move2 == 1 then
- if ammo2 < 1 then
- b2Dead = true
- elseif (move1 ~= "-" and move1 ~= "2" and move1 ~= "1") then
- b1Dead = true
- end
- ammo2 = ammo2 - 1
- end
- -- Move type 3. Fire Plasmaaaah.
- if move1 == 2 then
- if ammo1 < 2 then
- b1Dead = true
- elseif (move2 ~= "=" and move2 ~= "2") then
- b2Dead = true
- end
- ammo1 = ammo1 - 2
- end
- if move2 == 2 then
- if ammo2 < 2 then
- b2Dead = true
- elseif (move1 ~= "=" and move1 ~= "2") then
- b1Dead = true
- end
- ammo2 = ammo2 - 2
- end
- if b1Dead or b2Dead then
- print((b1Dead and "B1 has failed to survive.\n" or "")..
- (b2Dead and "B2 has failed to survive." or ""))
- break
- end
- n = n + 1
- if n>=10 then
- print("Both B1 and B2 are really tired, and have gone home.")
- b1Dead = true
- b2Dead = true
- break
- end
- end
- -- To the victor goes the spoils. <s>Yes, a draw is rewarded.</s> REWARDING DRAWS IS STUPID AND I'M STUPID.
- if not b1Dead then bot1.wins = bot1.wins + 1 end
- if not b2Dead then bot2.wins = bot2.wins + 1 end
- end
- end
- for k,v in pairs(team1) do
- if v.wins > 4 then
- v.reward()
- else
- v.punish()
- end
- v.lifetimeScore = v.lifetimeScore + v.wins
- end
- for k,v in pairs(team2) do
- if v.wins > 4 then
- v.reward()
- else
- v.punish()
- end
- v.lifetimeScore = v.lifetimeScore + v.wins
- end
- end
- p("TEAM 1 WAS:")
- for k,v in pairs(team1) do
- p(v.tostring())
- end
- p()
- p("TEAM 2 WAS:")
- for k,v in pairs(team2) do
- p(v.tostring())
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement