Seed or RNG?
4 years ago
Texas, USA

I've mentioned this to a few of you previously, but I'm curious to see if anyone has noticed solid patterns within Any% thus far. I have been working on collecting data in my runs because I have a sneaking suspicion that we're looking at seed instead of RNG. Case in point being a strong coloration between the start of R1 (duck, fish, duck, rabbit vs fish, rabbit, duck duck duck) and the cat spawn rate in R3.

Do you have any knowledge about the Sega Master System having seeds in games? I haven't found anything online thus far (most likely because of the age of the system and popularity) so I'd love to hear what you've experienced.

AntBlueR piace questo
North Carolina, USA

That's an interesting question, unfortunately I'm not as familiar with the inner workings of Master System as I am with other game consoles, but I will def look into it (from my decidedly amateur perspective, obviously).

Either way, it might be possible to do some rng manipulation the way they do in Gen 1 Pokemon speedruns. but that's a discussion for way down the line.

Edit: A quick Googleing has yielded some results.

This link: https://www.copetti.org/projects/consoles/master-system/ is a good breakdown of the master system hardware including how the cpu addresses memory and sprite collision/detection, and there are some 'further reading' links at the bottom of the page that I just don't have time to delve into at the moment.

Hope this helps!

Modificato da l'autore 4 years ago
AntBlueR e Greystone848 ti piace questo
Toronto, ON, Canada

Thanks for the link MagicPokey! yeah I could tell there is a bit of a pattern for the first level (lake level?). for the Forest Level it's a bit predictable, like the bear spawn. during the christmas break I will try to look around the game's memory using the emulator, I will post if I found something interesting

AntBlueR, Greystone848, e MagicPokey ti piace questo
North Carolina, USA

arnaud33200 Awesome, I was NOT looking forward to doing memory map breakdowns. I will tell you that when it comes to computers, ESPECIALLY older models like the Master System (and the MOS 6502 [Commodore 64], which I am more familiar with) there is no such thing as true random number generation. There is always a seed and a series of mathematical operations are done on that seed number to generate a random value.

This is going to get kinda technical.

For most games this seed is taken from a series of variables like time of day, the uptime of the cpu (in cycles), which inputs and when they were received, and possibly some variables from the cartrige rom. The seed constantly changes, and the generation of the random number calls the seed and then performs a series of maths operations. We might think the seed generation would be done on the cartridge (well, in system RAM), but since the z80 processor has its own rng function, I think Safari Hunt might just use the built in rng instead. From wikipedia "the refresh register, R, increments each time the CPU fetches an opcode (or opcode prefix) and has no simple relationship with program execution. This has sometimes been used to generate pseudorandom numbers in games, and also in software protection schemes"

In practice we can assume that Safari Hunt, made in 1986, well into the lifecycle of the z80, probably just uses a random number generated from the z80 itself since the programmers would have likely been familiar with the z80 and why waste precious bytes on the cartridge with a software rng when a hardware one is available and you can just write a call to that in your assembler code. This isnt always the case but if it is then manipulating the rng becomes possible, since I/O functions will increment the 'R' register and we can add inputs.

Note, I said it was (probably) POSSIBLE, not that I would even BEGIN to know how to figure out the correct inputs without a ton of trial and error. But I am almost POSITIVE there are smarter people than me who could figure it out. Heck, I could be wrong about all of this, this is all a lattice of guesswork and wikipedia research based on educated guesses and what I remember about how the 6502 functions. One starting place I would look into though is the original Pac Man arcade boards. They use the exact same CPU as the SMS and I am sure there is way more documentation about how that was coded than Safari hunt.

AntBlueR, arnaud33200, e Greystone848 ti piace questo
Toronto, ON, Canada

I'm starting to work on TAS and I can confirm this is RNG. Depending on the frame when the target is killed, the next target will be another animal and/or another location. but stuff are constant, I will keep you updated when I'm done a good progress

Modificato da l'autore 4 years ago
MagicPokey e AntBlueR ti piace questo
Toronto, ON, Canada

I made a script to register all the target spawn. every line is a full level 1 game without shooting anything. for the next time I start the level 1 frame after to have a different RNG. Looks like the first 4 targets would always be duck --> fish --> duck --> rabbit

https://i.ibb.co/dQjRJ6W/Screen-Shot-2021-02-22-at-11-23-38-PM.png

Next I will try to figure how the RNG can be manipulated. I know that shooting can change the target's spawn location, I think it can also change the next target type. Probably there might be a rule that prevent to have only duck spawn since the ratio would be 50%, maybe there is a count somewhere

Modificato da l'autore 4 years ago
MagicPokey e AntBlueR ti piace questo
Toronto, ON, Canada

So I think I figure out how it works! there are 2 variables (or memory address) for the next spawn index and time. every frame the time decrease by one, when it reaches 0, the index value increase by 1 and the next time is populated. the index loops between 0 and 9 and the order will always be the same

For the first round (lake) it looks like that: https://i.ibb.co/yfhPpqj/Screen-Shot-2021-03-05-at-11-31-39-PM.png

So where is the RNG in it? randomly, the game will decide to spawn or not the next target. For example: 0, 1, 2 spawn, 3 is skipped, then 4, 5 spawn, then 6 is skipped, and 7, 8, 9 spawn. depending on the target, a spawn would be skipped if there is already too much target on the screen. For example only one rabbit at the time on the screen, so it would be skipped if the previous rabbit is still here.

This RNG can be manipulated with shot actions. Working on a TAS, I was able to avoid any skip and get all the spawn at every index. I think next I will check where in the memory is the RNG, I might need to look at the code itself :O

Modificato da l'autore 4 years ago
MagicPokey e AntBlueR ti piace questo
Toronto, ON, Canada

also this is what the TAS looks like for now. The first round has all the spawn, the second I had only 1 spawn skipped:

MagicPokey e AntBlueR ti piace questo
North Carolina, USA

Dude this is awesome work so far! I'm sorry I've been awol for a bit but feel free to email me (same username at gmail) if you want some input or a second set of eyes on the TAS!

arnaud33200 piace questo
Toronto, ON, Canada

Thanks! I'm gonna submit a TAS to tasvideos.org soon, I could get a 1:05 on my lastest TAS:

Here is a link for my submission comments, I'm still working on it. it's formatted with the markdown used in tasvideos submission: https://docs.google.com/document/d/19j3Tj7itGhKTgI5_YFLpXXISLQX_3CypwlLJ49Gc5IM/edit?usp=sharing

Modificato da l'autore 4 years ago
Toronto, ON, Canada

Also I actually looked at the code itself! I found a very nice decompiler & debugger called Emulicious: https://emulicious.net/

I've learned a lot about the game, especially spawn and shot actions. I've updated my LUA script to display the target hit box, I will post that soon, maybe better to have another thread.

Next time I will work on that, I will check in details how the RNG works, the shot location will influence the RNG for some situation

Statistiche del gioco
Follower
9
Runs
11
Giocatori
5
Giocate recenti
Discussioni recenti
Pubblicato 4 years ago
0 risposte
Pubblicato 4 years ago
10 risposte
Pubblicato 4 years ago
0 risposte