Author Topic: "Random" Encounters, When do they occur?  (Read 12197 times)

BrutalAl

  • *
  • Posts: 17
    • View Profile
"Random" Encounters, When do they occur?
« on: 2007-01-28 00:25:57 »
Have anyone ever fully mapped and documented how the game determines when to give you a random encounter? Tried finding something (on this board), but no luck.

I did find something Terence wrote on the issue a long time ago. It offered a good but unfortunately not full explanation :/

Cyberman

  • *
  • Posts: 1572
    • View Profile
Re: "Random" Encounters, When do they occur?
« Reply #1 on: 2007-01-28 21:40:16 »
Well for the field areas it's in the FIELD location data in both the PS1 and PC variant. For the world, it's in the world map data. 
For the PS1 the data is in the DAT files, it's not in the wiki however yet.

What are you trying to do?

Cyb

BrutalAl

  • *
  • Posts: 17
    • View Profile
Re: "Random" Encounters, When do they occur?
« Reply #2 on: 2007-01-28 23:35:13 »
Well, partly because I want to find out what (if something) went wrong with the randomness in Field encounters, seeing how they aren't very random at all but instead most predictable.

But mostly for in-game reasons. With full knowledge of when they occur I would, simply by walking a specific way, be able to alternate the random encounter pattern, and thus (hopefully) reduce the frequency of random battles. I've already managed this to some extent already, but so far I'm just fooling around in the dark till I get something concrete to work with.

Cyberman

  • *
  • Posts: 1572
    • View Profile
Re: "Random" Encounters, When do they occur?
« Reply #3 on: 2007-01-28 23:58:53 »
Hmmm so you are thinking about how the random encounter thing is come by?
I believe you should try GameFAQS->Playstation->Final Fantasy 7 and look at the 3 FAQs by Terrance there.  I believe it's a combination of the number of steps and 4 probabilities from each battle. There are roughly 1000 possible battle scenes in FF7 each field location has one battle scene ID but may have quite a few different possible encounters.  Since I don't know the specifics that are in the DAT file I can't speculate on that at all. SCENE.BIN contains all the possible battles (1000 of them), however which battles are possible in Field locations are in the associated .DAT file.  Ehhh I'm being redundant :D

Anyhow Check out the 3 files on GameFAQs

Cyb

BrutalAl

  • *
  • Posts: 17
    • View Profile
Re: "Random" Encounters, When do they occur?
« Reply #4 on: 2007-01-29 00:22:50 »
I'm already familiar with those FAQs, that was what I were referring to when I mentioned Terence in the opening post.
I'm not at all interested in the battles them selfs really, just exactly how the game determines when to give you any one of them (Field only).

Terence explanation seems fairly accurate but he mentions a random variable being involved, but since the battles are all but random that cant really be it.
Furthermore I've located one variable that is increased by 2 for each battle check and is looped back to 0 when it reaches 256 that in some way is involved in determining when to allow a "random" battle, but there is no mentioning about this variable in his FAQ.

So, I stand blind... still

Akari

  • *
  • Posts: 766
    • View Profile
Re: "Random" Encounters, When do they occur?
« Reply #5 on: 2007-01-29 02:45:53 »
Furthermore I've located one variable that is increased by 2 for each battle check and is looped back to 0 when it reaches 256 that in some way is involved in determining when to allow a "random" battle, but there is no mentioning about this variable in his FAQ.

This called Danger Counter in Terrence FAQ. He gave complete description of random encounter, what else you need?
Format of how values for each battle encounter stores? or what?

BrutalAl

  • *
  • Posts: 17
    • View Profile
Re: "Random" Encounters, When do they occur?
« Reply #6 on: 2007-01-29 10:22:58 »
This called Danger Counter in Terrence FAQ. He gave complete description of random encounter, what else you need?

No I'm not talking about the danger counter, that would be another variable (one that isn't looped back to 0 when it reaches 256), but yeah I'm already aware of that one.
As stated though, he mentions a random variable, but the encounters are not random at all so that can't be it. Also,if you're close to get a battle while saving, load up and that battle will be skipped (but this will only be the case if you were close enough to it), seeing how there is no mentioning about this in his FAQ the description it's definitely not complete.

But apart from that random variable (which really cant be random) I believe he got most of the mechanics correct. So i guess my actually interest is that "random" one and its actual behavior.

Cyberman

  • *
  • Posts: 1572
    • View Profile
Re: "Random" Encounters, When do they occur?
« Reply #7 on: 2007-01-29 16:08:00 »
There is a random number generator in FF7 that returns between 0 and 255.  This is of course a psuedo random number generator and is part of the kernel of the system.  (FF7 is actually a RTOS application in that it has it's own kernel that sits a top the bios and allows for multithreaded access to the disk etc.)

That random number generator might be what you are looking for in any case.

BrutalAl

  • *
  • Posts: 17
    • View Profile
Re: "Random" Encounters, When do they occur?
« Reply #8 on: 2007-01-29 21:00:44 »
That random number generator might be what you are looking for in any case.

That random number generator might have been what the programmers intended to use for Field random encounters, but seeing how there's nothing random about these encounters I simply doubt the final product does.
According to Terence the World Map random encounter mechanics uses a random variable (as well) and I have no reason to doubt him on that one, because World Map encounters are, unlike Field encounters, actually random (as random as can be).

That what was supposed to be random isn't. What and the behavior of whatever replaced it is what I'd like to know. Looks like I'll have to pioneer the dmn thing :/

BrutalAl

  • *
  • Posts: 17
    • View Profile
Re: "Random" Encounters, When do they occur?
« Reply #9 on: 2007-02-04 20:51:14 »
Ok, I've manage to find (what really seems to be the only) 3 variables that are involved in giving you an encounter. But this is about as far as I will get :/

#1. the so called Danger Counter
Same one that Terence mentions, increases by a number per battle check depending on the current Field and if you're walking or running.

#2. a Battle Check (bcheck) Counter
This counter increases by 2 per battle check regardless of if you're running or walking. 1 byte in size.

#3. Battle Check Loop (bcloop) Counter
Each time the battle check Counter is looped back to 0 this one increases by 13. Also 1 byte in size.


All I know is that depending on the value of the bcheck and bcloop counters a danger limit is set. If, during a battle check, the danger counter equals or exceeds this limit you will get an encounter.

E.g.
bcheck = 76
bcloop = 0
sets;
limit = 1024

The behavior of this limit seems next to hard coded if u ask me >_<.

These are the variables addresses in the PSX memory (hope it's of any help);
8007173c - danger counter
8009C540 - bcheck counter
8009AD2C - bcloop counter

Anyway, I probably approached this thing from the wrong angle to begin with and really do need help finishing it (I've hardly ever studied and/or interpreted the game disc data). The "only" thing that's left to find out is if the limit is hard coded or is a function of bcheck and bcloop and if so what does it look like.
« Last Edit: 2007-02-04 20:59:35 by BrutalAl »

Terence Fergusson

  • *
  • Posts: 262
    • View Profile
Re: "Random" Encounters, When do they occur?
« Reply #10 on: 2007-02-05 01:41:33 »
But apart from that random variable (which really cant be random) I believe he got most of the mechanics correct. So i guess my actually interest is that "random" one and its actual behavior.

http://en.wikipedia.org/wiki/Pseudorandom_number_generator

It is a "random" variable... for a given meaning of random.  However, just because they used a fancy algorithm doesn't mean it's a *GOOD* random number generator.  In fact, it's a pretty crap random number generator.  *All* of FF7's generators are crap.  The only reason you're noticing *this* one is because only a few things call it, as opposed to other generators in the game that are called almost all the time, muddying the results.

Your 2nd variable is the seed, from 0 to 255.  This is used to look up a table containing 256 numbers already distributed from 0 to 255 in a seemingly random manner... which is pretty much how FF7 gets almost all its random numbers.  Every time it wants a "random" number, it increments the seed by 1 and gets the next "random" value in the table.

Your 3rd variable is the offset, which is an extra little thing FF7 is doing to further muddy the waters.  Once it gets its "random" value, it subtracts this offset from the value.  And there it has a "random" number.

So for your example, with a seed of 76 and an offset of 0, it'd look up the 77th number in the table, which happens to be 3, and then subtract 0 from that.  So it returned the "random" number of 3.  This has to be less than [Danger Counter * Enemy Lure Value / 256].  A Danger Counter value of 1023, when divided by 256, would return [3.996] = 3.  So no battle, since the "random" number is not less than that.  But if it were 1024, that would return 4.  Since 3 < 4, well, there's your battle.

You noticed that it actually incremented the seed by *2* per Battle Check... the first of those is actually it comparing the first "random" value it picks to the Pre-Emptive chance, to see if you get a Pre-Emptive battle.  Yes, it does this each time, even before it knows whether you'll be getting a battle or not.  There's also a bunch of other things that also use this seed, as well as a couple of things during the Battle Check that use the same random table but with a different seed (like an even *simple* PRNG that decides what battle you'll get next), but it all gets kinda immaterial after that.

 ===

The bottom line is this.  Yes, it's not *truly* random.  It's not even a good use of a pseudo-random number generator - it's among the crappiest I've seen, really, seeing how it's a bad random number generator (strike 1) that's used in a terrible manner (strike 2).  (Of course, even good random number generators used in a terrible manner can suck: just take a look at Golden Sun for an example there)

However, without actually doing the maths every time you want to check something, there is absolutely no way to predict when and where you'll battle beforehand.  The rules may be simple, but they produce complex results and the only way to know what you'll be battling is to run through the numbers.  So there is no benefit to knowing how this works, and as such, I will likely never cover it in any of my guides seeing how it's far too technical.

Do you remember why I continually recommend to people doing Chocobo Breeding, that when they continually keep getting the same Chocobo when they really want a different one, they should run in and out of the barn a few times to 'generate' new random numbers instead of just resetting and reloading?  It may be a different random generator, but it's the same principle here: it's a pseudo-random number generator that doesn't have its seed updated every millisecond, and the only way to have things happen differently than before is to have more "random" things happen that depend on that generator.

So if you're going to do any analyzing, I'd suggest you focus on what is actually happening in the game, rather than on the numbers behind it... because with a 256 order seed with 256 possible values for the offset... that gives you a sequence of 65536 random numbers before it repeats.  There's also a few uses of that particular seed that increments the seed by 1 but *doesn't* increase the offset if it overflows, which can *further* complicate this whole mess.  Given different Area Encounter Values, whether you're walking or running, and how many other things update the seed, I don't think you're going to get any useful information out of the mechanics behind it all.

halkun

  • Global moderator
  • *
  • Posts: 2097
  • NicoNico :)
    • View Profile
    • Q-Gears Homepage
Re: "Random" Encounters, When do they occur?
« Reply #11 on: 2007-02-05 02:37:47 »
Terence, your're like an oracle, you know that....

You should of ended with "...and now I shall sleep for another 1000 years. Behold the prophecy shall begin again!" or something like that.

BrutalAl

  • *
  • Posts: 17
    • View Profile
Re: "Random" Encounters, When do they occur?
« Reply #12 on: 2007-02-05 14:43:12 »
This is used to look up a table containing 256 numbers already distributed from 0 to 255 in a seemingly random manner
/.../
So if you're going to do any analyzing, I'd suggest you focus on what is actually happening in the game, rather than on the numbers behind it

Got ya, still interested in that Table though.  :|