From f96e0b015eb9bde8752cdb5382e234e63b58f7e5 Mon Sep 17 00:00:00 2001 From: Mathias Bynens Date: Wed, 8 Apr 2015 10:31:29 +0200 Subject: [PATCH 1/3] Clean up in-game time section --- util/memory.lua | 3 +++ util/utils.lua | 27 +++++++++++---------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/util/memory.lua b/util/memory.lua index 68cd4a2..67f99f3 100644 --- a/util/memory.lua +++ b/util/memory.lua @@ -44,6 +44,9 @@ local memoryNames = { frames = 0x1A45, battle = 0x1057, textbox = 0x0FC4, + time_hours = 0x1A41, + time_minutes = 0x1A43, + time_seconds = 0x1A44, }, shop = { transaction_amount = 0x0F96, diff --git a/util/utils.lua b/util/utils.lua index 25d2114..7123edb 100644 --- a/util/utils.lua +++ b/util/utils.lua @@ -67,9 +67,9 @@ end -- TIME function utils.igt() - local secs = memory.raw(0x1A44) - local mins = memory.raw(0x1A43) - local hours = memory.raw(0x1A41) + local secs = memory.value("game", "time_seconds") + local mins = memory.value("game", "time_minutes") + local hours = memory.value("game", "time_hours") return secs + mins * 60 + hours * 3600 end @@ -93,22 +93,17 @@ function utils.timeSince(prevTime) end function utils.elapsedTime() - local secs = memory.raw(0x1A44) - if secs < 10 then - secs = "0"..secs - end - local mins = memory.raw(0x1A43) - if mins < 10 then - mins = "0"..mins - end - return memory.raw(0x1A41)..":"..mins..":"..secs + local secs = memory.value("game", "time_seconds") + local mins = memory.value("game", "time_minutes") + local hours = memory.value("game", "time_hours") + return hours..":"..clockSegment(mins)..":"..clockSegment(secs) end function utils.frames() - local totalFrames = memory.raw(0x1A41) * 60 - totalFrames = (totalFrames + memory.raw(0x1A43)) * 60 - totalFrames = (totalFrames + memory.raw(0x1A44)) * 60 - return totalFrames + memory.raw(0x1A45) + local totalFrames = memory.value("game", "time_hours") * 60 + totalFrames = (totalFrames + memory.value("game", "time_minutes")) * 60 + totalFrames = (totalFrames + memory.value("game", "time_seconds")) * 60 + return totalFrames + memory.value("game", "frames") end return utils From fcf7a8296a7adfb2b0def6b3d55ad6339b5aa5b4 Mon Sep 17 00:00:00 2001 From: Mathias Bynens Date: Wed, 8 Apr 2015 10:37:21 +0200 Subject: [PATCH 2/3] Move time-related constants to `memoryNames.time` --- main.lua | 4 ++-- util/memory.lua | 10 ++++++---- util/utils.lua | 21 +++++++++++---------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/main.lua b/main.lua index 8fe7ed8..f191fe9 100644 --- a/main.lua +++ b/main.lua @@ -210,8 +210,8 @@ while true do end if STREAMING_MODE then - local newSecs = memory.raw(0x1A44) - if newSecs ~= oldSecs and (newSecs > 0 or memory.raw(0x1A45) > 0) then + local newSecs = memory.value("time", "seconds") + if newSecs ~= oldSecs and (newSecs > 0 or memory.value("time", "frames") > 0) then bridge.time(utils.elapsedTime()) oldSecs = newSecs end diff --git a/util/memory.lua b/util/memory.lua index 67f99f3..2e00efe 100644 --- a/util/memory.lua +++ b/util/memory.lua @@ -41,12 +41,14 @@ local memoryNames = { }, game = { map = 0x135E, - frames = 0x1A45, battle = 0x1057, textbox = 0x0FC4, - time_hours = 0x1A41, - time_minutes = 0x1A43, - time_seconds = 0x1A44, + }, + time = { + hours = 0x1A41, + minutes = 0x1A43, + seconds = 0x1A44, + frames = 0x1A45, }, shop = { transaction_amount = 0x0F96, diff --git a/util/utils.lua b/util/utils.lua index 7123edb..5f02b33 100644 --- a/util/utils.lua +++ b/util/utils.lua @@ -67,9 +67,9 @@ end -- TIME function utils.igt() - local secs = memory.value("game", "time_seconds") - local mins = memory.value("game", "time_minutes") - local hours = memory.value("game", "time_hours") + local secs = memory.value("time", "seconds") + local mins = memory.value("time", "minutes") + local hours = memory.value("time", "hours") return secs + mins * 60 + hours * 3600 end @@ -93,17 +93,18 @@ function utils.timeSince(prevTime) end function utils.elapsedTime() - local secs = memory.value("game", "time_seconds") - local mins = memory.value("game", "time_minutes") - local hours = memory.value("game", "time_hours") + local secs = memory.value("time", "seconds") + local mins = memory.value("time", "minutes") + local hours = memory.value("time", "hours") return hours..":"..clockSegment(mins)..":"..clockSegment(secs) end function utils.frames() - local totalFrames = memory.value("game", "time_hours") * 60 - totalFrames = (totalFrames + memory.value("game", "time_minutes")) * 60 - totalFrames = (totalFrames + memory.value("game", "time_seconds")) * 60 - return totalFrames + memory.value("game", "frames") + local totalFrames = memory.value("time", "hours") * 60 + totalFrames = (totalFrames + memory.value("time", "minutes")) * 60 + totalFrames = (totalFrames + memory.value("time", "seconds")) * 60 + totalFrames = totalFrames + memory.value("time", "frames") + return totalFrames end return utils From a0ba20c831afe3ef2e61c9306931813a823dcfa3 Mon Sep 17 00:00:00 2001 From: "Peter K." Date: Fri, 10 Apr 2015 02:46:17 +0200 Subject: [PATCH 3/3] Print seed at the start of a run Since BizHawk seems to have a memory leak, it would be nice to know the seed of runs where the script terminates. This also prints the current pokebot version, since a same seed run won't be consistent between versions. --- main.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/main.lua b/main.lua index 8fe7ed8..8e58abe 100644 --- a/main.lua +++ b/main.lua @@ -91,6 +91,7 @@ local function resetAll() print("RUNNING WITH A FIXED SEED ("..strategies.seed.."), every run will play out identically!") else strategies.seed = os.time() + print("PokeBot version "..VERSION.." starting new run with seed "..strategies.seed..".") end math.randomseed(strategies.seed) end