Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2

Author Topic: math of non-random chaos for use in video games?  (Read 2341 times)

malimbar04

  • Bay Watcher
    • View Profile
math of non-random chaos for use in video games?
« on: March 12, 2011, 09:16:05 am »

Alright, the title sucks, but I'm not sure how to make a better one.

Simply put, I don't like how much video games rely on randomness. If you do things a specific way, they should have relatively consistent or predictable results. A 5% chance to do double damage should not exist when you're fightnig a dragon (and for that matter they shouldn't have hit points).

I do like the idea of chaos though. Two worlds that start with close but not identical seed values should develop similarly for a time and then break away as the difference in values becomes more pronounced.

But the problem is that I have no idea where to find the math of chaos. How could I set up a system that doesn't rely on random numbers but does produce procedural a believable results?

I'm not sure if I'm looking for some procedural programming work, or if I'm looking for websites on the math of chaos.
Logged
No! No! I will not massacre my children. Instead, I'll make them corpulent on crappy mass-produced quarry bush biscuits and questionably grown mushroom alcohol, and then send them into the military when they turn 12...

olemars

  • Bay Watcher
    • View Profile
Re: math of non-random chaos for use in video games?
« Reply #1 on: March 12, 2011, 09:25:37 am »

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

Probably not quite what you're looking for, but it's an interesting starting point for nonlinear dynamics and chaos.
Logged

rarborman

  • Bay Watcher
  • Penguin Dungonmaster
    • View Profile
    • dice
Re: math of non-random chaos for use in video games?
« Reply #2 on: March 12, 2011, 09:31:36 am »

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

Probably not quite what you're looking for, but it's an interesting starting point for nonlinear dynamics and chaos.
thats more as a proof that small actions do have impact on probability.

If man knew the math of chaos then the world would be much better, and random things would never suprise us...

Problem is although there are mathematical equations to simulate chaos, chaos is just to damn chaotic to be quantified by a cute little mathematical proof or all the math in the world, that one can plug into a computer and estamate events.

Chaos is named thus for that reason.

So just accept RNG and suck it up.
Logged
"But to that second circle of sad hell, Where ‘mid the gust, the whirlwind, and the flaw Of rain and hail-stones, lovers need not tell Their sorrows. Pale were the sweet lips I saw, Pale were the lips I kiss’d, and fair the form I floated with, about that melancholy storm."

PsyberianHusky

  • Bay Watcher
  • The best at being the worst at video games.
    • View Profile
Re: math of non-random chaos for use in video games?
« Reply #3 on: March 12, 2011, 11:34:20 am »

I think Physics games do it well, by simply having so many variables, the result is both consistent and chaotic.
Logged
Thank you based dwarf.

Lord Dullard

  • Bay Watcher
  • Indubitably.
    • View Profile
    • Cult: Awakening of the Old Ones
Re: math of non-random chaos for use in video games?
« Reply #4 on: March 12, 2011, 12:53:47 pm »

I think Physics games do it well, by simply having so many variables, the result is both consistent and chaotic.

Agreed.

In an RPG or a game that depends more on overall strategy rather than player skill (and consequential correlation between such skill and the occasional production of fantastic or unusual results), the '5% chance of double damage' makes complete sense. You're taking away the requirement for a player with quick reflexes and making success dependent on the use of strategy and logical approach by making the assumption that the character (rather than the player) has the skill. It's a bit like putting a player in the role of a general instead of a soldier on the front lines.

However, in the spirit of the OP, I can respect the desire for more 'sensible chaos'. % chances for random success/failure in traditional games work for most people because it puts them in that 'general' role, but clearly that's not what the OP wants. OP, I think you will find games in the action/RPG genre more to your taste. Something like the Gothic series would fit your definition pretty well. There's still calculated random damage in Gothic but overall ability to survive depends much more heavily on player skill in such a game.

Alternatively, you could change the traditional RPG-approach into something more rock-paper-scissors like, to at least provide a better explanation as to why the 'random double damage' occurs. Attack the enemy with your sword or whatever and give the enemy a chance to select from a range of actions rather than having a chance of any one of those actions take place; for example, choosing to try to dodge might avoid damage entirely but will incur (probably massive) damage if it fails, whereas blocking or parrying an attack has a better success rate but more of a chance for reduced damage to occur. Forcing a character to select a specific action like this would probably produce more meaningful results than the passive chance to block/dodge/etc. seen in most platform-style RPG engines.

I think URW uses a system somewhat like that, actually.
Logged

Ari Rahikkala

  • Bay Watcher
    • View Profile
Re: math of non-random chaos for use in video games?
« Reply #5 on: March 12, 2011, 03:21:28 pm »

It does. You get to choose how to defend against any attack that you see coming, and get to choose how to attack each time. There's also a key for "attack the same way you did last time", the number of options is fairly small, and fights where you actually have to make harder decisions than just mash enter at the dialogs are rare and dangerous enough, that the system doesn't really drag the game's pace down. It's a fairly good design IMO.

Quote
I'm not sure if I'm looking for some procedural programming work, or if I'm looking for websites on the math of chaos.

The general answer to this question is that it depends. If all you know about a system is that it dynamically evolves based on some initial state, you can't yet tell whether it will be easy or difficult for a human to determine how it will behave and whether it'll behave "similarly" for "similar" inputs. For instance the same physics engine, varying for numeric precision, might either completely ignore some difference between initial states, or blow it up into making the system evolve completely differently.

So, as rarborman said, just accept RNG and suck it up. If you don't want there to be a 5% chance to do double damage when you're fighting a dragon, make a game rule saying that dragons ignore/don't cause double damage effects. Or, even better, design the game so that playing it is fun even if the player loses a game to a bullshit 5% chance double damage attack from a dragon :)
Logged

Nivim

  • Bay Watcher
  • Has the asylum forgotten? Are they still the same?
    • View Profile
Re: math of non-random chaos for use in video games?
« Reply #6 on: March 12, 2011, 04:17:45 pm »

 I'm don't think that's quite what he's asking for, since this has less to do with strategy-versus-skill, and more to do with sensible cause and effect, sometimes called "realness", "depth", or "determinism". For each thing that happens in the game, there should be a number of specific causes. The question "why?" should have a deep and interesting answer (to which "because the dice rolled that way" is the opposite), and the game should be able to give that answer through testing, investigation, and/or contextual clues. And of course, each effect should also be a cause for future effects; that being the greatest part of what makes those effects meaningful.
 Dwarf Fortress gets ever closer to an ideal state of this, as more and more of the numbers and details in the game relate to each other, but it is not there yet, and it's nice to have some variety.
 At the moment, I would recommend The King of Dragon Pass since just about all of your choices have lasting results, and the elements of randomness only give way to more choices. But it is still working with chances; not yet a completely deterministic system that has reached a level of complexity that could convince you it is random. Supposedly Tension (The Void) did well in that regard, but that might be because of how difficult it was to experiment with reliably.
 Reading this thread, it sounds like the Creatures series might also be what you're looking for.
Logged
Imagine a cool peice of sky-blue and milk-white marble about 3cm by 2cm and by 0.5cm, containing a tiny 2mm malacolite crystal. Now imagine the miles of metamorphic rock it's embedded in that no pick or chisel will ever touch. Then, imagine that those miles will melt back into their mantle long before any telescope even refracts an image of their planet. The watchers will be so excited to have that image too.

Starver

  • Bay Watcher
    • View Profile
Re: math of non-random chaos for use in video games?
« Reply #7 on: March 12, 2011, 05:14:10 pm »

I'm not really sure what the OP is actually asking for, so I'll tap away and if anything makes sense, take note, and if it doesn't apply you can ignore it.

You can make a game which can repeat a deterministic path each time[1].  Much as per DF world history and geology generation, start it off with a seed for a pseudo-random number generator.  Could be as simple as a hashing algorithm taking the last result (or seed, if there was none) and outputting a new result.

At each decision time, the PRNG rolls out a new number.  Identical every time.  Of course, the player could 'trick' it if they got a handle on how it works, so that instead of something like entering a cave, trying to hit monster (fails) and trying to hit monster again (wins), and losing some HP in the process, they could re-run the situation and this time search for treasure (fails), enter a cave, try to hit monster (wins), with no loss of HP.

The most trivial way of avoiding this is to make each action query the PRNG, or otherwise manipulate it, or poke it, with an 'encounter number', thus disrupting the predictability.  A game's designer could even exploit this fact to ensure that a particular path through a segment (over which they must control the entry point of the PRNG, perhaps by re-seeding it) has an idealised route that works well in a particular manner (not easily discoverable even by decompiling) by poking in values that support said path.  Of course, if that particular entry-point does not have a limitation on how the PRNG is initially configured, it'll only work when the lead-up is as the designer intended (and tested for).

For an actual varied plotline, even with the same intention, let go of the control of the PRNG.  Indeed, most inbuilt randomising functions will self-initialise with something like current setting of the clock or (if there's not something like that available) the time passed since the program started which (if the player has to "Press Enter to Start" prior to the PRNG first being called/initialised) has a distinct degree of variance.


And if, despite all the above, the whole point is that essentially have a "Roll a D20 to see how much defence you have for an attack, but roll a 20 and you survive anything, even a nuclear bomb" situation, then the answer is not to have super-save rolls in the first place.  Or reduce the likelihood down to the odds you're actually expect for the nuclear bomb not to explode.  (In dragon terms, it might have tripped up just as it was about to lunge at you or something.)


Does that help?  Not sure.



[1] When I was first introduced to a higher-level programming language, the first practical graphics program was a "fly this space-ship through a random cave system".  The cave ceiling and floor undulations were dictated to by a rnd() call of whatever kind that language had, and yet cave 1 always looked the same, cave 2 always looked the same, cave 3 also... etc, etc, etc.  Then I realised that the "srand()" equivalent function was obviously being seeded exactly the same every time.  Among many 'improvements' I made (along with changing the characteristics of the space-ship so it was thrust upwards and thrust downwards, rather than go upwards and downwards, meaning it was now a second order (and, later, for fun, third order) derivative motion on the y-axis) was making it seed more randomly.  But whereas the original version was a level playing field (the level 6 cave might be the one that always arises with a very tricky pinch, which together with an asymptotic narrowing of each successive cave meant it was a reasonably easy manner to know that getting further meant you were better at it), it was now quite possible for the first cave to have a bad pinch to ruin the player's day right from the start, and no guarantee that someone else got co-operatively easy caves from shear randomness (albeit that they still narrowed down, to the limit of the space-ship's actual height where perfect play was needed even on a forgiving cave).
Logged

IronyOwl

  • Bay Watcher
  • Nope~
    • View Profile
Re: math of non-random chaos for use in video games?
« Reply #8 on: March 12, 2011, 06:10:04 pm »

"Chaos" and "randomness" are closely linked. The only way to have the chaos of an RNG without it being actually random is to make the game so hideously complex that even though the data exists, nobody is able to figure out exactly what it's doing and why. This is no small feat, especially if it's just a pet peeve.

In terms of world generation, you can rely on error propagation to make two similar starting points result in different outcomes- essentially, you just give the generator a lot of steps, and base the steps on the results of the previous step.


Anything allowing player input, on the other hand, tends to break down using this sort of system, because the player can exploit anything they can understand. This tends to result in one of two things.

The first is that something that was intended to be random becomes more of an ideal- perhaps not happening every time, but certainly tried for whenever plausible, and thus frequently occurring. Headshots in FPS's are a good example. This isn't necessarily a bad thing, but it requires a much, much more complex assessment of the impact and strength of certain features than assigning them a 5% chance does.

The second is that it ends up being random anyway, because nobody can really tell what anything does. This somewhat voids the point of not just using an RNG, because the result is still the same: "There's an X% chance of Y happening and I don't know why."

It's obviously possible for things to fall somewhere between these extremes, but usually that just means starting as the second before someone figures out the pattern, at which point is becomes the first.
Logged
Quote from: Radio Controlled (Discord)
A hand, a hand, my kingdom for a hot hand!
The kitchenette mold free, you move on to the pantry. it's nasty in there. The bacon is grazing on the lettuce. The ham is having an illicit affair with the prime rib, The potatoes see all, know all. A rat in boxer shorts smoking a foul smelling cigar is banging on a cabinet shouting about rent money.

Starver

  • Bay Watcher
    • View Profile
Re: math of non-random chaos for use in video games?
« Reply #9 on: March 12, 2011, 06:52:18 pm »

I'd like to agree that "Chaos" and "Pseudo-Randomness" are linked, with that minor change.

And as an example for such pseudo-randomness being exploited, there's one on-line game where I'm astonished to find this, but fairly sure that the PRNG for whether an action succeeds is based directly off of the clock.  If I click a certain action and it succeeds, I can usually slowly count to five then click again and succeed again.  And again.  And again.  And if I don't succeed, I count to seven, because it seems like I tend more to rush the count, and my impression is that this has given me a win most of the time.  I certainly seem to be getting significantly higher-than-stated success rates with this.  At, say, a rate of 50% hit, with two wounds per successful hit, I should be inflicting one wound per action, but seem to be getting more than that.

And I've no idea if that's actually what is happening, or if I'm falling for some form of placibo effect from my own best wishes being reinforced when it happens and putting it down to "being on the wrong cycle" when it doesn't (a kind of reverse on Murphy's Law and that of all other queues shrinking faster than ones own).

Anyway, I'm all for unpredictability through obscurity (or downright obfuscation) of the background process, from a player POV.  Which is not to say that the developer can't himself exploit purposeful control over the random process (which he or she should have a good understanding of, and influence over) to make for intended exceptions to the purely random rule.  If the designer deliberately puts in a +10% chance of hitting on the birthdate of the character (unofficially, probably never noticed by the players if done subtly and rarely enough), I don't see why not.

But look at The Kingdom Of Loathing for a very large player-base who usually manage to analyse hitherto unknown probabilities behind various new 'adventures' within a day of them appearing.  (Indeed, 'that day only' special adventures are often tied down well before they disappear from the screens again.)  On the other hand, I don't scrutinise the respective wiki enough to spot if there are any similar "count to five" opportunities that have been found.  I think KOL's system of chance is a bit more robust than that.  (BICBW)
Logged

malimbar04

  • Bay Watcher
    • View Profile
Re: math of non-random chaos for use in video games?
« Reply #10 on: March 12, 2011, 07:20:56 pm »

<snip>
Nivm has my main annoyance pegged down I think. When two characters attack each other and one wins, I feel a need to say why they won.

The games I'm thinking of have little to do with player skill or reflexes - NWN and DF come to mind (which is why I posted here). However, I'm pretty sure that both use random numbers in combat extensively. (why did he bash the skull of that kitten in? because the random number god didn't want him to unsheath his sword and stab it).

I like the idea of actions tweaking modifiers, but I'd like not to be tweaking a seed to a PRNG. Is there something else to tweak seeds for if not a PRNG?

As I understand it, winning is generally a comparison of numbers from the two opponents compared. The higher number (after modifiers) always wins. If I included modifiers from a bunch of previous actions, say... age, steps walked per last 1000 frames, whether the dominate arm was thrusted in the last action, and the total mood of the character, I could use these to determine what happens in the next action with determinism.

But as I am thinking right now, I'd need a huge If/else structure, and one person would probably always dominate the other person 100% of the time. I'd need a justifiable way to give the looser a way out, choose to use different skills,  or somehow pull a victory/draw out of their ass.

Ideally the only random number I'd ever use would be on things that don't need a reason to be the way they are - like parts of world generation and civilization generation.

I really like the idea of error propagation (I don't understand the math so much on wikipedia though). How would I actually use that in a program? Wouldn't the end result still be a direct result of a pre-determined steps on a pre-determined number? I don't mind if a player exploits the system by the way, as long as the exploit is by doing something that is believable for the world. Imagine danger rooms or dwarven water reactors.
Logged
No! No! I will not massacre my children. Instead, I'll make them corpulent on crappy mass-produced quarry bush biscuits and questionably grown mushroom alcohol, and then send them into the military when they turn 12...

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: math of non-random chaos for use in video games?
« Reply #11 on: March 12, 2011, 07:25:38 pm »

tl;dr version: Instead of making it random so people can't predict what is going to happen for sure, make it too complex for people to be able to predict what is going to happen.

IronyOwl

  • Bay Watcher
  • Nope~
    • View Profile
Re: math of non-random chaos for use in video games?
« Reply #12 on: March 12, 2011, 08:44:29 pm »

<snip>
Nivm has my main annoyance pegged down I think. When two characters attack each other and one wins, I feel a need to say why they won.
The simplest way to accomplish this is through either coming up with an excuse after the fact, or randomly generating one along with the numbers. Why did he bash that kitten's skull in? Because he saw an opening, or the kitten slipped, or he was on his heels initially and thus didn't have time to draw his sword. The only other options are that he bashed the kitten's skull in because it's the best attack, and will therefore happen every time, or that the game has systems to account for openings in defenses, ground slipperyness and stance, or general balance and position. This is almost never worth it just so you can say he cut they guy's head off authentically.

As I understand it, winning is generally a comparison of numbers from the two opponents compared. The higher number (after modifiers) always wins. If I included modifiers from a bunch of previous actions, say... age, steps walked per last 1000 frames, whether the dominate arm was thrusted in the last action, and the total mood of the character, I could use these to determine what happens in the next action with determinism.
Indeed. As I mentioned in Option 1, this isn't really any better than an RNG, because the explanation for "why did he cut my head off?" is either "I don't know he just does," which is essentially random, or "because your number of steps before fighting him was evenly divisible by 3," which is asinine.

But as I am thinking right now, I'd need a huge If/else structure, and one person would probably always dominate the other person 100% of the time. I'd need a justifiable way to give the looser a way out, choose to use different skills,  or somehow pull a victory/draw out of their ass.
A rock-paper-scissors arrangement could potentially do this, but you'd still need some sort of RNG to figure out what decisions the AI would make. It'll also slow the game down somewhat, so it's not to be added without careful thought.

I really like the idea of error propagation (I don't understand the math so much on wikipedia though). How would I actually use that in a program? Wouldn't the end result still be a direct result of a pre-determined steps on a pre-determined number? I don't mind if a player exploits the system by the way, as long as the exploit is by doing something that is believable for the world. Imagine danger rooms or dwarven water reactors.
It varies depending on exactly what you'd want to do, but the basic theory is simply to feed a result of the last action into the next one, for a long time. A very simple example might look something like this:

Get the Seed.
Number of Islands = Seed x2.
Size of Largest Island = Number of Islands +3.
Depth of Ocean = Size of Largest Island / 4.
Number of Volcanoes = Depth of Ocean +2.

And so on and so on. The more stuff you do to the original number, the further it deviates from the result of a slightly different number, especially with regards to multiplication.

Yes, it's completely pre-determined; that's what avoiding randomness means. The only way to make it chaotic, as I've said, is to make it so complex that it looks random.
Logged
Quote from: Radio Controlled (Discord)
A hand, a hand, my kingdom for a hot hand!
The kitchenette mold free, you move on to the pantry. it's nasty in there. The bacon is grazing on the lettuce. The ham is having an illicit affair with the prime rib, The potatoes see all, know all. A rat in boxer shorts smoking a foul smelling cigar is banging on a cabinet shouting about rent money.

qwertyuiopas

  • Bay Watcher
  • Photoshop is for elves who cannot use MSPaint.
    • View Profile
    • uristqwerty.ca, my current (barren) site.
Re: math of non-random chaos for use in video games?
« Reply #13 on: March 12, 2011, 09:26:26 pm »

One thing to think about is if each creature kept a number, internally, between 0 and 255, inclusive. Each action of that creature is subtly affected by that number, and each action also changed that number in a constant but unknown way (different actions having different effects). In that way, the outcome of an interaction is constant unless the player directly affects one of the participants in that interaction (throw a stone at the knight. The knight misses the dragon at a critical moment rather than striking it down. The player can rationalize it as them distracting him. Alternatively, it makes the knight get an especially effective first strike. The player can still rationalize it, though less obviously (made him more alert?). Whether the player walked 299, 300, or 301 steps and did or did not loot that nearby chest will not affect the fight between the knight and the dragon (unless in a routine, one of them checks up on the chest, allowing the chest to alter their internal procedural-random number differently whether it is looted or not, before they have the fight that the player sees the outcome of). Better than a global RNG with a saved seed, where taking a detour around an insignificant decal on the ground could affect it in an unknown way, completely changing the outcome of everything else that happens instantly from that point onwards).

Often the outcome of an action will depend mainly on skill, plus a very small random factor added for variety, so if damage is calculated as attacker's attack stat minus the defender's defense, it would actually be more like (attack + (randomly chosen number between -1 and 2)) - (defense + (randomly chosen number between -1 and 2)), perhaps with a "luck" stat that affects the range. That way, the 999 attack warrior can kill a 0 defense chicken, with no chance of failure, but in a more equal match, the random portion of it can mean the difference between victory and defeat.
Logged
Eh?
Eh!

eerr

  • Bay Watcher
    • View Profile
Re: math of non-random chaos for use in video games?
« Reply #14 on: March 13, 2011, 02:17:13 am »

So you want one thing to depend on another?

Start with a seed, say, a map you drew some interesting shapes on.
Then add creatures that have interactions. There isn't any need to have more than Basic AI for the chaos to appear.

the herbivores eat the grass, the predators eat the herbivores.
And they all make babies, and grow.

no genetics are required, no gen, necessary.
Just a seed on the world, with the most basic of AI's and minor interactions.


You want a chaotic system? Start with something that already exists.

Logged
Pages: [1] 2