User File #45942285593125145

Upload All User Files

#45942285593125145 - Pictionary Sequence Finder v1.0

pictionary rng.lua
Game: Pictionary ( NES, see all files )
632 downloads
Uploaded 3/23/2018 12:09 AM by warmCabin (see all 30)
Not very user-friendly at the moment, so consider this a readme.
First, you're going to need an initial savestate in slot 1 (Shift+F1) (can these scripts load savestates from a file?). It should be on frame 479, the first frame you can press start to enter a blank name.
test_frame is the sequence to start searching at. That is, the script will press start test_frame frames after the initial savestate (whether you created it correctly or not). You can alter this if you want to continue from where you left off. You'll also need to alter best and worst to reflect the values you found earlier. If this is your first time running the script, just leave them be.
The script automatically increments test_frame and starts over after it's read 6 words. If you want to read more words, alter the magic number on line 111.
local slot0 = savestate.object(1)
local start_frame = 0
local test_frame = 0
local inited = false
local testing = false
local prev = nil
local sum = 0
local index = 0
local lagCheck = true
local freeFrame = 0
local lagsChecked = 0
local best = 123456789
local worst = 0

emu.speedmode("turbo") --It seems to work better when you click turbo from the menu.
emu.setrenderplanes(false,false)
emu.unpause()

local function init()
	
	savestate.load(slot0)
	start_frame = emu.framecount()
	prev = "................"
	sum = 0
	index = 0
	testing = false
	lagCheck = false
	lagsChecked = 0
	freeFrame = 0
	inited = true
	
end

local function spacelessLen(str)
	local ans = 0
	for i=1,#str do
		if str:sub(i,i)~=" " then
			ans = ans + 1
		end
	end
	return ans
end

local function clampRight(str)
	local length = 0
	for i=1,#str do
		if str:sub(i,i) ~= ' ' then
			length = i
		end
	end
	return str:sub(1,length)
end

local function readWord()
	local word = memory.readbyterange(0x0448, 16)
	local ret  = ""
	for i=1,#word do
		local c = word:sub(i,i):byte()
		if c == 0x28 then
			--emu.print(" ")
			ret = ret.." "
		elseif c>=0x0A and c<= 0x23 then
			--emu.print(string.char(c-0x0A+65))
			ret = ret..string.char(c-0x0A+65)
		else
			ret = ret.."." --dot for unknown characters, just like the hex editor
		end
		--emu.print(word:sub(i,i):byte()-0x0A+65)
		--emu.print(word:sub(i,i):byte())
	end
	--emu.print(ret)
	return clampRight(ret)
end

local function post_frame()
	
	if not inited then init() end
	
	if emu.framecount() - start_frame == test_frame then
		emu.print("Testing frame "..emu.framecount().."...")
		testing = true
		joypad.set(1,{start=true})
		return
	end
	
	if not testing then return end
	
	if freeFrame==0 and not lagCheck and emu.lagged() then
		lagCheck = true
		lagsChecked = lagsChecked + 1
	end
	
	if freeFrame==0 and lagCheck and not emu.lagged() then
		lagCheck = false
		if lagsChecked == 5 then
			--emu.print("Escaped lag at frame "..emu.framecount())
			freeFrame = emu.framecount()
		end
	end
	
	if AND(emu.framecount(),1) == 0 then
		joypad.set(1,{start=true})
	end
	
	local word = readWord()
	
	if word ~= prev then
		emu.print(word)
		sum = sum + spacelessLen(word)
		index = index + 1
		if index==6 then
			test_frame = test_frame + 1
			inited = false
			emu.print(sum.." characters + "..(freeFrame-1182).." frames of waiting.")
			if sum < best then
				emu.print("!!BEST SO FAR!!")
				best = sum
			elseif sum > worst then
				emu.print("...WORST SO FAR...")
				worst = sum
			end
			emu.print("________________________")
		end
	end
	
	prev = word
	
end
emu.registerafter(post_frame)