User File #638476644230880216

Upload All User Files

#638476644230880216 - GBA Chutes and Ladders lua script

chutesandladders-search.lua
System: Game Boy Advance
41 downloads
Uploaded 4/2/2024 2:20 PM by Winslinator (see all 25)
Helps determine what title screen start frames yield the best RNG for a TAS.
--start tells the game what frame to press "Start" on the main menu; t is the frame after which the game is considered taking too long to play out and the next start frame should be tested
start = 1924
t = 9620

while true do

	--read the current position of both players (a number between 1 and 100—the number of spaces on a Chutes & Ladders board)
	memory.usememorydomain("EWRAM")
	p1 = memory.read_u8(0x00431C)
	p2 = memory.read_u8(0x004330)
	
	--save a state every time the current start frame is encountered
	if emu.framecount() == start
	then
		savestate.saveslot(2)		
	end
	
	--The below just signals a bunch of inputs to register at specific frames to navigate through all the menus
	if (emu.framecount() == 477) or (emu.framecount() == start) or (emu.framecount() == start+40) or (emu.framecount() == start+41)
	then
		joypad.set({["Start"]=true})
	end
	if (emu.framecount() == 513) or (emu.framecount() == start+1) or (emu.framecount() == start+39) or (emu.framecount() == start+76) or (emu.framecount() == start+77) or (emu.framecount() == start+150) or (emu.framecount() == start+152) or (emu.framecount() == start+154) or (emu.framecount() == start+190) or (emu.framecount() == start+192) or (emu.framecount() == start+194) or (emu.framecount() == start+196)
	then
		joypad.set({["A"]=true})
	end
	if (emu.framecount() == start+113) or (emu.framecount() == start+114) or (emu.framecount() == start+153) or (emu.framecount() == start+155)
	then
		joypad.set({["Right"]=true})
	end
	if (emu.framecount() == start+38)
	then
		joypad.set({["Down"]=true})
	end
	
	--If either player has not reached the end by a certain time, reset and test the next start frame
	if emu.framecount() > t + 1080
	then
		--If the position value still reads 0, that means "Chutes & Ladders" failed to initialize. There is therefore a problem with our menu navigation input sequence above; output the start frame and the text "FAIL" to signal that it needs to be fixed.
		if (p1 == 0) or (p2 == 0)
		then
			console.log(start,"FAIL")
		end
		start = start + 1
		savestate.loadslot(2)
	end
	
	--if any player reaches the final space, output the start frame and current frame, as it warrants further investigation
	if (p1 == 100) or (p2 == 100)
	then
		t = emu.framecount()
		console.log(start,t)
		start = start + 1
		savestate.loadslot(2)
	end
	
	emu.frameadvance()
end