Last active
June 23, 2021 08:37
-
-
Save yagamuu/d115b77103638979c60ff804cfb26b0d to your computer and use it in GitHub Desktop.
AMG 戦闘結果集計Bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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