Skip to content

Instantly share code, notes, and snippets.

@yagamuu
Last active June 23, 2021 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yagamuu/d115b77103638979c60ff804cfb26b0d to your computer and use it in GitHub Desktop.
Save yagamuu/d115b77103638979c60ff804cfb26b0d to your computer and use it in GitHub Desktop.
AMG 戦闘結果集計Bot
local resultsFilePath = "amg2_bot_results_1.txt"
local count = 100
local result1P = 0x1E6C8C
local result2P = 0x1E6C8E
local turn = 0x1E6AC8
local ignoreDraw = true
-- Main Function --
function main()
emu.speedmode("maximum")
local i = 0
local battleEndFlag = false
local WinCount1P = 0
local WinCount2P = 0
local drawCount = 0
tempsave = savestate.create()
print("Bot Start")
while i < count do
savestate.load(tempsave)
wait(2)
savestate.save(tempsave)
wait(2)
joypad.set(1, {circle=1})
wait(2)
battleEndFlag = false
while battleEndFlag == false do
joypad.set(1, {circle=1})
wait(2)
local Win1P = memory.readbyte(result1P)
local Win2P = memory.readbyte(result2P)
local nowTurn = memory.readbyte(turn)
if (Win1P == 1) then
WinCount1P = WinCount1P + 1
i = i + 1
battleEndFlag = true
print("1P Win")
elseif (Win2P == 1) then
WinCount2P = WinCount2P + 1
i = i + 1
battleEndFlag = true
print("2P Win")
elseif (nowTurn == 21) then
drawCount = drawCount + 1
battleEndFlag = true
print("Draw")
if (ignoreDraw == true) then
i = i + 1
end
end
end
end
print("Bot End")
local resultsFile, err = io.open(resultsFilePath, "a")
if err then
print("Could not write results " .. err)
else
resultsFile:write("count : " .. (WinCount1P + WinCount2P + drawCount) .. "\n")
resultsFile:write("1P Win : " .. WinCount1P .. "\n")
resultsFile:write("2P Win : " .. WinCount2P .. "\n")
resultsFile:write("Draw : " .. drawCount .. "\n\n")
resultsFile:close()
end
emu.speedmode("normal")
gui.popup("End", "OK")
end
function wait(f)
local i = 0
while i < f do
emu.frameadvance();
i = i + 1
end
end
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment