User File #638548876573099359

Upload All User Files

#638548876573099359 - monopoly_rngvalues_cards.lua

monopoly_rngvalues_cards.lua
Game: Monopoly ( NES, see all files )
33 downloads
Uploaded 6/25/2024 4:47 AM by FractalFusion (see all 87)
Returns initial Chance and Community Chest cards depending on the RNGa value. See the file for a description of what the output file values mean.
console.clear()

--Output as follows:
--RNGa Index, RNGa Value, order of Chance cards from top to bottom, order of CC cards from top to bottom, final RNGa value

--Chance card values: 0 getoutofjailfree 1 adv to go 2 nearestrail 3 back3space 4 repairs 5 poortax 6 boardwalk 7 illinois 8 adv to stcharles 9 nearestrail 10 bankpays$50 11 nearestutil 12 rideonreading 13 buildingmatures$150 14 gotojail 15 chairman

--Community Chest card values: 0 getoutofjailfree 1 inherit$100 2 doctorsfee$50 3 payhospital$100 4 repairs 5 salestock$45 6 schooltax 7 gotojail 8 incometaxrefund$20 9 adv to go 10 receiveservices$25 11 secondprize$10 12 bankerror 13 lifeinsur$100 14 xmasfundmatures$100 15 grandopera

--Note: Chance deck starts at $0472. Community Chest deck starts at $0482. Both are 16 bytes long.


fle=io.open("monopoly_rngvalues.txt","w")

local baserng=0x3E2AD2
local chance={}
local chest={}
local function nextrng(rng,n)

	for i=1,n do
		
		local bool1= ((rng%0x400000)>=0x200000)
		local bool2= ((rng%0x200000)>=0x100000)
		
		if bool1~=bool2 then
		  nextbit=1
		else
		  nextbit=0
		end
	
		rng=2*rng+nextbit
		
		rng=rng%0x1000000
		
	
	end
	
	return rng
	
end

local function xor(a,b)
	
	local pow=1
	local res=0
	for i=0,7 do
		local bool1 = (a%(2*pow)>=pow)
		local bool2 = (b%(2*pow)>=pow)
		if bool1~=bool2 then
			res=res+pow
		end
		
		pow=pow*2
	end
	
	return res

end

local function getcards(inputrng)
	
	local rng=nextrng(inputrng,1)
	for i=0,15 do
		chance[i]=-1
		chest[i]=-1
	end
	
	local cardno=15
	local ramf7=0 --chance
	
	while true do
		rng=nextrng(rng,3)
		local test=rng%256
		test=xor(test,ramf7)
		test=math.floor(test/16)
		
		if chance[test]~=-1 then
			ramf7=ramf7+1
		else
			chance[test]=cardno
			cardno=cardno-1
			if cardno<0 then
				break
			end
		end
	end
	
	cardno=15
	ramf7=16 --chest
	
	while true do
		rng=nextrng(rng,3)
		local test=rng%256
		test=xor(test,ramf7)
		test=math.floor(test/16)
		
		if chest[test]~=-1 then
			ramf7=ramf7+1
		else
			chest[test]=cardno
			cardno=cardno-1
			if cardno<0 then
				break
			end
		end
	end	
	
	fle:write(string.format("%06X:",inputrng))
	fle:write(" Chance: ")
	for i=0,15 do
	  fle:write(string.format("%02d",chance[i])," ")
	end
	fle:write(" Community_chest: ")
	for i=0,15 do
	  fle:write(string.format("%02d",chest[i])," ")
	end	
	
	fle:write(string.format(" FinalRNG: %06X",rng),"\n")
	
end


local prng=baserng
for i=1,5000 do
	fle:write(string.format("%04d: ",i-1))
	getcards(prng)
	prng=nextrng(prng,1)
end

fle:close()