Latest / CyberSecurity Summary / Algorithms and Networking for Computer
Transcript
- 0:00Speaker 1: So picture this. You're playing a game and you round
- 0:03Speaker 1: a corner in some dark digital dungeon and boom and
- 0:07Speaker 1: enemy suddenly springs an ambush.
- 0:09Speaker 2: Oh yeah, your heart just completely jumps into your throat.
- 0:11Speaker 1: Right, And in that split second, you know, you're not
- 0:13Speaker 1: thinking about code or like pixels on a screen.
- 0:16Speaker 2: Oh of course not.
- 0:17Speaker 1: You're just thinking, wow, that felt so real. Because we
- 0:20Speaker 1: play these games expecting this organic spontaneity, right, We really
- 0:24Speaker 1: want that digital world to feel alive, we do.
- 0:27Speaker 3: But the truth is that organic feeling is entirely fabricated,
- 0:32Speaker 3: like completely, when you actually step behind the curtain of
- 0:35Speaker 3: game development, all that spontaneity just vanishes. You're looking at
- 0:39Speaker 3: this landscape of cold, hard, purely deterministic code.
- 0:44Speaker 1: Which is so wild to think about.
- 0:46Speaker 3: It is because computers are well, they're rigid machines. You
- 0:49Speaker 3: literally cannot be spontaneous. Everything you feel in that dungeon
- 0:52Speaker 3: is just a meticulously crafted mathematical illusion.
- 0:56Speaker 1: And today we are ripping open that code to see
- 0:59Speaker 1: exactly how developers pull off that trick. We are doing
- 1:02Speaker 1: a deep dive into this brilliant textbook. It's called Algorithms
- 1:07Speaker 1: and Networking for Computer Games by Juni Smed and Harriet Conan.
- 1:11Speaker 2: It's a fascinating read, it really is.
- 1:13Speaker 1: And our mission today is to figure out how programmers
- 1:16Speaker 1: manipulate math and psychology to trick your brain. We're going
- 1:21Speaker 1: to start from the foundational rules of play and go
- 1:23Speaker 1: all the way down to the invisible algorithms that basically
- 1:26Speaker 1: manufacture chaos.
- 1:28Speaker 3: Yeah, and to understand the math, we first have to
- 1:30Speaker 3: agree on what we're actually trying to simulate, right, right,
- 1:33Speaker 3: Because when you strip away the high resolution graphics and
- 1:36Speaker 3: you know, the fancy haptic feedback controllers, Smed and Hakonan
- 1:40Speaker 3: argue that an interactive world requires one specific crucial ingredient
- 1:44Speaker 3: to separate it from just a static puzzle.
- 1:46Speaker 2: And that ingredient unpredictability.
- 1:48Speaker 1: Okay, let's unpack this because the book uses a really
- 1:51Speaker 1: specific word here, which is conflict. Yes, conflict, And when
- 1:54Speaker 1: I hear conflict, my mind immediately goes to like fighting
- 1:58Speaker 1: a digital dragon or racing against a rival car. But
- 2:02Speaker 1: the authors argue it's actually way broader than that, much brighter. Yeah,
- 2:06Speaker 1: because think about a Sunday crossword puzzle, right. It's challenging,
- 2:10Speaker 1: it has rules, it has a goal, but is it
- 2:13Speaker 1: a game.
- 2:13Speaker 3: Well, by the strict definitions used in game architecture, a
- 2:18Speaker 3: standard crossword puzzle is not actually a game. Wait really yeah,
- 2:21Speaker 3: because it lacks non determinism. A crossword puzzle just sits there.
- 2:25Speaker 3: It doesn't fight back, you know, doesn't adapt.
- 2:27Speaker 2: To your choices.
- 2:28Speaker 1: Okay, I see.
- 2:29Speaker 3: So conflict in this specific context means you are facing
- 2:32Speaker 3: an opposing force or some random process that actively obstructs you.
- 2:37Speaker 1: Right, So if you add a ticking timer to that
- 2:39Speaker 1: crossword or I don't know, you're raising a friend to
- 2:41Speaker 1: finish it first.
- 2:42Speaker 3: Suddenly have non determinism. Exactly, You've injected chaos, and now
- 2:45Speaker 3: you have game.
- 2:46Speaker 1: Okay, So in a single player experience, developers have to
- 2:49Speaker 1: artificially inject that chaos. They have to simulate an opposing
- 2:54Speaker 1: force using AI, which the authors call synthetic players.
- 2:57Speaker 2: Right, synthetic players.
- 2:58Speaker 1: But here is the most counter intuitive part of this
- 3:01Speaker 1: whole illusion. For me, to make an AI opponent feel
- 3:04Speaker 1: like a real, living human, developers actually have to break it. Yes,
- 3:09Speaker 1: they have to make the AI significantly worse.
- 3:12Speaker 3: Well, you have to consider what computers are actually capable of, right,
- 3:15Speaker 3: Like a machine can calculate your character's exact coordinates aim
- 3:19Speaker 3: with pixel perfect precision and just eliminate you the exact
- 3:23Speaker 3: millisecond you enter its line of sight.
- 3:24Speaker 1: Right, It's basically the Terminator exactly.
- 3:27Speaker 3: It possesses superhuman perfection, but playing against flawless perfection is
- 3:31Speaker 3: incredibly boring and frustrating. Completely, it feels robotic, and it
- 3:36Speaker 3: instantly shatters that illusion of playing against a living, breathing
- 3:39Speaker 3: entity in a shared space.
- 3:41Speaker 1: So it's all about simulating human flaws. And there is
- 3:44Speaker 1: this amazing specific detail from the text about how developers
- 3:48Speaker 1: engineer this.
- 3:48Speaker 2: Oh the reaction time.
- 3:49Speaker 1: Yes, when you take a synthetic player by surprise, say
- 3:52Speaker 1: you flank an enemy in a shooter game, the programmers
- 3:55Speaker 1: hard code a deliberate zero point two to zero point
- 3:58Speaker 1: four second reaction time delay before the AI is even
- 4:02Speaker 1: allowed to shoot back.
- 4:03Speaker 3: Yeah, and that specific window of time is absolutely no accident.
- 4:07Speaker 3: It simulates the cognitive processing time of a human being.
- 4:11Speaker 3: It basically mimics panic, panick.
- 4:13Speaker 1: Right.
- 4:14Speaker 3: Yeah, So when you surprise an enemy and they freeze
- 4:16Speaker 3: for like a third of a second before scrambling for cover,
- 4:20Speaker 3: your brain subconsciously registers the ODEA.
- 4:23Speaker 1: Loop, the Obie loop.
- 4:24Speaker 3: Yeah, observe orient decide act, you recognize that slight hesitation
- 4:29Speaker 3: as human cognition, and the illusion holds.
- 4:31Speaker 1: Wow. But this introduces a massive headache for the game designers,
- 4:36Speaker 1: doesn't it.
- 4:36Speaker 2: Oh a huge one.
- 4:37Speaker 1: Because if you program these synthetic players to act somewhat unpredictably,
- 4:42Speaker 1: and then you give the actual human player the freedom
- 4:44Speaker 1: to do literally whatever they want, how on earth do
- 4:47Speaker 1: you guarantee the game still tells a cohesive story.
- 4:49Speaker 3: Well, you've hit on what the authors called the narrative paradox.
- 4:52Speaker 3: It is the central tension in all interactive storytelling.
- 4:55Speaker 1: A narrative paradox.
- 4:56Speaker 2: Yeah.
- 4:57Speaker 3: So, on one side of the scale you have plot coherence,
- 4:59Speaker 3: the there's in the designers. They want to deliver a
- 5:02Speaker 3: well paced, dramatic, emotionally resonant story.
- 5:05Speaker 2: Like a movie exactly.
- 5:07Speaker 3: But on the other side you have character believability and
- 5:12Speaker 3: player agency. You need the player and the AI to
- 5:15Speaker 3: have the actual freedom to ma choices.
- 5:17Speaker 1: Because if I have total freedom, I might just decide
- 5:20Speaker 1: to wander off into the woods to pick digital mushrooms
- 5:23Speaker 1: and completely ignore the terrifying dragon that's supposed to be
- 5:26Speaker 1: attacking the castle.
- 5:27Speaker 3: Right, and then the pacing is completely ruined. The story
- 5:29Speaker 3: just grinds.
- 5:30Speaker 2: To a halt.
- 5:31Speaker 1: So how do they fix that?
- 5:32Speaker 3: So the industry generally tackles this tension from two different directions.
- 5:36Speaker 3: The first is a character centric approach. Okay, here, the
- 5:40Speaker 3: AI characters are highly autonomous. They act on their own program, desires,
- 5:45Speaker 3: and needs, and sometimes they even use a hybrid communication system.
- 5:49Speaker 1: Wait, what does that mean.
- 5:50Speaker 3: Well, they speak in character to the player, but simultaneously
- 5:54Speaker 3: they send out of character signals to the game's background
- 5:57Speaker 3: systems to try gently nudge the plot forward organically.
- 6:01Speaker 1: Oh that's clever, it is.
- 6:02Speaker 3: The story basically emerges from the bottom up.
- 6:04Speaker 1: But the problem with the bottom up approach is that
- 6:07Speaker 1: it can quickly turn into the chaos of everyday life. Right,
- 6:10Speaker 1: real life isn't inherently structured like a three act cinematic blockbuster.
- 6:14Speaker 2: No, it definitely isn't.
- 6:16Speaker 1: So the alternative is the author centric approach, which relies
- 6:19Speaker 1: on something called an invisible drama manager.
- 6:22Speaker 3: Yes, the drama manager, which I love.
- 6:24Speaker 1: Think of it like a stage director secretly walking among
- 6:27Speaker 1: the actors, whispering in their ears, completely unseen by the audience.
- 6:32Speaker 2: That's a perfect way to put it.
- 6:33Speaker 3: The drama manager is constantly running math in the background,
- 6:37Speaker 3: monitoring metrics like player tension and pacing.
- 6:40Speaker 1: So that's washing what I do constantly.
- 6:42Speaker 3: If the algorithm's determined you've been wandering the woods picking
- 6:45Speaker 3: mushrooms for way too long and the tension is dropping,
- 6:48Speaker 3: the drama manager whispers to the AI enemies to spawn
- 6:52Speaker 3: an ambush just out of your line of sight.
- 6:54Speaker 1: To get my heart rate back up exactly.
- 6:56Speaker 3: Or conversely, if you are low on health and completely overwhelmed,
- 7:00Speaker 3: it tells the enemies to pull back a bit or
- 7:03Speaker 3: to miss their shots. It subtly manipulates the parameters of
- 7:06Speaker 3: the world to push you toward the intended emotional beats.
- 7:09Speaker 1: But even with a brilliant invisible director, the developers still
- 7:13Speaker 1: have to physically build the paths the story can take.
- 7:16Speaker 1: Right they do, and the text maps out game stories
- 7:19Speaker 1: using these geometrical graphs. The most basic one is just
- 7:22Speaker 1: a linear story. Episode A always leads to episode B,
- 7:26Speaker 1: which leads to episode C. It's just a straight line.
- 7:28Speaker 3: Yeah, and linear development is incredibly cost effective, but it
- 7:32Speaker 3: offers almost zero agency. You're essentially just walking through a movie, right.
- 7:36Speaker 3: The theoretical opposite of that is a fully branching structure
- 7:40Speaker 3: where every single choice you make leads to a completely different,
- 7:44Speaker 3: unique continuation of the game.
- 7:46Speaker 1: Which sounds like the holy grail of gaming until you
- 7:49Speaker 1: actually do the math on the combinatorial explosion.
- 7:52Speaker 2: Oh, the math is terrifying.
- 7:53Speaker 1: It really is. Let's say you have a scene with
- 7:55Speaker 1: three dialogue choices, and each of those choices leads to
- 7:59Speaker 1: three entirely new scenarios. By the time you reach the
- 8:02Speaker 1: fourth major decision point in the game, you aren't programming
- 8:05Speaker 1: one game anymore. You're programming eighty one completely different games.
- 8:09Speaker 1: You'd have studio spending twelve years and half a billion
- 8:12Speaker 1: dollars just to make a five hour campaign.
- 8:15Speaker 3: It's completely unsustainable. So developers rely on a highly calculated
- 8:19Speaker 3: compromise called parallel pass. Parallel pad right, the story branch
- 8:24Speaker 3: is out for a while, allowing you to make choices,
- 8:26Speaker 3: take different routes, and express your agency. This provides that
- 8:30Speaker 3: crucial illusion of free will ah illusion. But eventually all
- 8:35Speaker 3: those diverged branches are forced to converge back into major,
- 8:39Speaker 3: unavoidable story nodes.
- 8:40Speaker 1: So I might use diplomacy to talk my way past
- 8:43Speaker 1: the guards, and you might just kick the door down
- 8:44Speaker 1: with explosives typical exactly, but thirty minutes later, we both
- 8:49Speaker 1: end up standing in the exact same throne room for
- 8:51Speaker 1: the exact same final boss fight.
- 8:53Speaker 3: Yes, the game just acknowledges are different methods in the dialogue.
- 8:57Speaker 3: It keeps the studio from going bankrupt while letting us
- 9:00Speaker 3: feel like we are the actual authors of our own fate.
- 9:03Speaker 1: So the illusion of free will is maintained by carefully
- 9:06Speaker 1: hidden constraints exactly, And that reliance on nondeterminism, you know,
- 9:10Speaker 1: on generating a feeling of unpredictable chaos within strict mathematical limits,
- 9:15Speaker 1: brings us to the very bedrock of how a computer operates.
- 9:20Speaker 1: And here's where it gets really interesting for me, oh
- 9:22Speaker 1: for sure, Because whether we are talking about parallel story branches,
- 9:26Speaker 1: or that zero point three second reaction delay for the AI,
- 9:30Speaker 1: or even simulating a dice roll, games need randomness to function.
- 9:34Speaker 2: They desperately need it.
- 9:35Speaker 1: But a computer processor is a purely deterministic machine. It
- 9:39Speaker 1: only executes the exact logic gits it is fed. It
- 9:43Speaker 1: cannot flip a coin. True randomness in a computer is
- 9:46Speaker 1: a total myth.
- 9:46Speaker 3: It is developers literally have to fake it. Yeah, they
- 9:50Speaker 3: use algorithms to produce sequences of numbers that just behave unpredictably,
- 9:54Speaker 3: and these fall into two main categories, which are quasi
- 9:57Speaker 3: random and pseudorandom.
- 9:58Speaker 1: Oh hey, let's break this down well.
- 9:59Speaker 3: Quasi random numbers are sequences that actually have a hidden
- 10:02Speaker 3: structural rule, but they just appear random to a naive observer.
- 10:06Speaker 1: Right, So, think of a sequence that alternates strictly between
- 10:08Speaker 1: even and odd numbers, but the numbers themselves jump wildly
- 10:12Speaker 1: across a massive range. Good example, if you just look
- 10:15Speaker 1: at a short sample of that, it feels totally chaotic,
- 10:18Speaker 1: but there's a rigid skeleton holding it together to ensure
- 10:21Speaker 1: an even spread of events over time.
- 10:23Speaker 3: Yeah, and that even spread is really useful for certain
- 10:26Speaker 3: visual rendering tasks. But when we need numbers that pass
- 10:30Speaker 3: rigorous statistical tests for actual chaotic unpredictability, we need pseudorandom
- 10:37Speaker 3: number generators.
- 10:38Speaker 1: Pseudorandom.
- 10:39Speaker 3: Yes, and the foundational algorithm detailed by Smed and hecanin
- 10:43Speaker 3: is the linear congruential method or the LCM.
- 10:47Speaker 1: The LCM now it sounds like high level calculus, but
- 10:49Speaker 1: it's really just a simple mathematical loop built on four parameters.
- 10:53Speaker 2: Right. It is surprisingly simple.
- 10:54Speaker 1: You have the modulus, which we'll call M. You have
- 10:56Speaker 1: the multiplier A, the increment C, and a starting value
- 11:00Speaker 1: which is known as the.
- 11:00Speaker 3: Seed exactly, and the operation itself is just basic arithmetic.
- 11:05Speaker 3: So the algorithm takes your seed value and it multiplies
- 11:08Speaker 3: it by.
- 11:08Speaker 2: A, and then it adds C.
- 11:09Speaker 1: Okay, easy enough, right, But then it.
- 11:11Speaker 3: Divides that total by the modulus M and whatever the
- 11:14Speaker 3: remainder of that division is. That remainder becomes your first
- 11:17Speaker 3: random number, the remainder, right, yeah, Then the algorithm takes
- 11:21Speaker 3: that brand new number, plugs it back into the start
- 11:24Speaker 3: of the formula is the new seed, and runs the
- 11:26Speaker 3: entire loop again.
- 11:27Speaker 1: So picture a clock face. Let's say our modulus is twelve,
- 11:31Speaker 1: so we have a standard twelve hour clock. No matter
- 11:34Speaker 1: how wildly you multiply or add numbers together, when you
- 11:37Speaker 1: divide by twelve and take the remainder, the answer is
- 11:40Speaker 1: just spinning around the dial, right, that's right. It will
- 11:42Speaker 1: always land on a notch between one and twelve.
- 11:45Speaker 3: It's a really elegant way to constrain infinite math into
- 11:48Speaker 3: a usable range. But because it's a closed mathematical loop
- 11:52Speaker 3: operating within that fixed clock face, the sequence of numbers
- 11:57Speaker 3: will eventually run out of unique combinations, it starts repeating
- 12:00Speaker 3: itself exactly.
- 12:01Speaker 1: Oh wow.
- 12:02Speaker 3: The length of this unique sequence before it finally loops
- 12:05Speaker 3: is called the period. So if your modulus is twelve,
- 12:08Speaker 3: the absolute maximum period you can achieve is twelve numbers.
- 12:12Speaker 1: And a repeating loop is the death of unpredictability. Like
- 12:16Speaker 1: if I'm playing a digital card game and I realize
- 12:18Speaker 1: the deck is dealing me the exact same sequence of
- 12:21Speaker 1: hands every twelve rounds, the illusion completely shatters. It does
- 12:25Speaker 1: I can predict the future. The game is basically broken
- 12:27Speaker 1: at that point.
- 12:28Speaker 3: So to prevent the player from ever seeing the loop,
- 12:31Speaker 3: developers use unimaginably massive numbers for the modulus. But you
- 12:37Speaker 3: can't just pick any large number.
- 12:38Speaker 1: Why not?
- 12:39Speaker 3: You want a very specific mathematical structure, ideally a prime number. Specifically,
- 12:44Speaker 3: developers often use Mrsenne primes.
- 12:47Speaker 1: Okay, wait, so why a prime number? If I just
- 12:49Speaker 1: pick a huge round number like a billion, doesn't that
- 12:52Speaker 1: just give me a billion notches on my clock? Face?
- 12:54Speaker 3: It does, but it introduces this problem of coprimality to primality. Yeah,
- 12:59Speaker 3: your modulus clod phase shares a common divisor with your multiplier,
- 13:03Speaker 3: the math will start skipping notches.
- 13:05Speaker 1: Oh I think I see.
- 13:06Speaker 3: Imagine a twelve hour clock and your multiplier forces you
- 13:09Speaker 3: to jump by threes. You hit three, six, nine, twelve,
- 13:13Speaker 3: and then you're right back where you started.
- 13:15Speaker 1: You only generated four unique numbers, even though your clock
- 13:18Speaker 1: has twelve spaces.
- 13:19Speaker 3: Exactly, by using a massive prime number for the modulus,
- 13:23Speaker 3: you guarantee it shares no divisors with your other parameters.
- 13:26Speaker 3: It forces the algorithm to step on every single unique
- 13:29Speaker 3: notch before it's ever allowed to loop.
- 13:32Speaker 1: That is genuinely brilliant, and the text mentions a common
- 13:36Speaker 1: Mersen prime used is two to the thirty first power
- 13:40Speaker 1: minus one, which is over two point one billion massive.
- 13:44Speaker 1: So the clockface has two point one billion unique notches,
- 13:48Speaker 1: and because it's prime, we hit every single one. The
- 13:51Speaker 1: sequence still repeats eventually, but the period is so incomprehensibly
- 13:56Speaker 1: long that a human playing the game will literally never
- 13:59Speaker 1: live long enough to notice the pattern.
- 14:01Speaker 3: True, but there is a huge vulnerability in this closed loop.
- 14:05Speaker 1: Wait really, because I'm looking at this formula, MA and
- 14:07Speaker 1: C are hard coded by the developer. The only variable
- 14:11Speaker 1: that starts the whole chain reaction is the seed exactly.
- 14:14Speaker 1: So if I turn on my console, boot up the game,
- 14:16Speaker 1: and the default seed value is just the number one
- 14:18Speaker 1: every single time. Wouldn't the math just spit out the
- 14:21Speaker 1: exact same sequence of random events every time I play yes?
- 14:25Speaker 3: The game would play out exactly the same way. The
- 14:27Speaker 3: ambush that terrified you in your first playthrough would happen
- 14:30Speaker 3: at the exact same millisecond in your second play through.
- 14:33Speaker 3: That ruins everything, right, So to fix this, developers have
- 14:36Speaker 3: to inject a tiny spark of real world physical chaos
- 14:41Speaker 3: to kickstart the math. They will program the game to
- 14:44Speaker 3: fetch its starting seed from highly variable, totally unpredictable sources
- 14:49Speaker 3: from outside the game's.
- 14:51Speaker 1: Code, like grabbing the computer's internal clock time down to
- 14:55Speaker 1: the microscopic millisecond of the exact moment you press start
- 14:59Speaker 1: yes exactly, or pulling data from the tiny erratic temperature
- 15:02Speaker 1: fluctuations of the CPU, or even the microscopic tremor of
- 15:06Speaker 1: your hand on the computer mounts. They literally capture a
- 15:09Speaker 1: fraction of physical reality to see the digital illusion.
- 15:14Speaker 2: That is amazing, it's really cool.
- 15:16Speaker 3: But once you've seeded the algorithm and it's churning out
- 15:18Speaker 3: billions of numbers, you still have a massive problem. Another one, Yeah,
- 15:22Speaker 3: how do you actually know the illusion works, you have
- 15:23Speaker 3: to test it rigorously, right, and the text outlines several
- 15:27Speaker 3: empirical tests, like the poker test, where yougroup the generator's
- 15:30Speaker 3: output into hands of five and see if they match
- 15:33Speaker 3: the real world statistical probability of drawing a full house
- 15:36Speaker 3: or a flush. That makes sense, But the most revealing
- 15:39Speaker 3: diagnostic for the linear congruential method is called the spectral test.
- 15:44Speaker 1: The spectral test, Okay, it sounds like ghost hunting.
- 15:46Speaker 3: It does, but it's actually a highly visual geometric test.
- 15:49Speaker 3: So imagine taking the sequence of number your algorithm produces, yeah,
- 15:53Speaker 3: grouping them into pairs, and plotting those pairs as x
- 15:57Speaker 3: and y coordinates on a massive two.
- 16:00Speaker 1: Okay, I'm picturing it.
- 16:01Speaker 3: If your generator is producing true chaotic randomness, that graph
- 16:06Speaker 3: should look like pure uniform television static. There should be
- 16:10Speaker 3: absolutely no pattern.
- 16:11Speaker 1: But the LCM isn't true chaos. It's built on fixed
- 16:15Speaker 1: multiplication and addition.
- 16:16Speaker 3: Exactly because of that linear mathematical relationship. If you zoom
- 16:20Speaker 3: out and look at that TV static, you will realize
- 16:22Speaker 3: that dots aren't actually random at all. They align to
- 16:25Speaker 3: form a lattice of perfectly parallel lines. Wow, they are
- 16:28Speaker 3: mathematically tethered together. And if you group the numbers into
- 16:31Speaker 3: triplets and plot them in a three D space, those
- 16:34Speaker 3: lines become parallel planes.
- 16:35Speaker 1: So the illusion has literal seams in it. The randomness
- 16:38Speaker 1: is basically stacked in layers.
- 16:40Speaker 3: Yes, the spectral test measures the distance between those parallel planes.
- 16:46Speaker 3: If the planes are too far apart, it means there
- 16:48Speaker 3: are massive predictable gaps in your random spread, and you
- 16:52Speaker 3: don't want that. No, So a high quality algorithm uses
- 16:55Speaker 3: parameters carefully calibrated to push those planes as tightly together
- 17:00Speaker 3: as possible, basically blurring the lines until the human eye
- 17:04Speaker 3: and statistical analysis only sees pure static.
- 17:07Speaker 1: Okay, So let's say our math past the spectral test.
- 17:10Speaker 1: The algorithm is incredibly robust, and it just generated a
- 17:14Speaker 1: massive pseudo random number, let's say one point eight billion. Okay,
- 17:18Speaker 1: but I'm playing a digital board game and my character
- 17:21Speaker 1: just needs to roll a standard six sided die. How
- 17:24Speaker 1: does the code shrink a massive one point eight billion
- 17:27Speaker 1: output down to a tiny interval of one to six
- 17:30Speaker 1: without destroying the delicate randomness we just engineered.
- 17:33Speaker 3: Well, if you take the lazy route, you absolutely ruin
- 17:36Speaker 3: the die.
- 17:36Speaker 2: Yeah.
- 17:36Speaker 3: Most basic approach, which the text calls the Monte Carlo
- 17:39Speaker 3: method is to just divide your massive random number by six.
- 17:42Speaker 1: And take the remainder like the clock face right.
- 17:44Speaker 2: But this warps the distribution.
- 17:45Speaker 1: Because the maximum limit of your huge random number generator
- 17:49Speaker 1: probably isn't perfectly divisible.
- 17:51Speaker 2: By six exactly.
- 17:52Speaker 1: Think of it like having a pizza with twenty slices
- 17:55Speaker 1: and you need to divide it evenly among six people.
- 17:58Speaker 1: Everyone gets three slices, but you have two slices left.
- 18:01Speaker 2: Over, yep, the remainder.
- 18:03Speaker 1: And if you just hand those remaining slices out to
- 18:05Speaker 1: whoever is closest, two people end up with more pizza.
- 18:09Speaker 1: In the code. That means the numbers one and two
- 18:12Speaker 1: end up with slightly more mathematical real estate than three, four, five,
- 18:16Speaker 1: or six.
- 18:16Speaker 3: Which means the digital die becomes mathematically loaded. Over the
- 18:19Speaker 3: course of thousands of roles, the player will absolutely notice
- 18:22Speaker 3: that they are rolling ones in twos more often.
- 18:25Speaker 1: And it feels completely unfair it does.
- 18:27Speaker 3: So to solve this, developers use something called the Las
- 18:30Speaker 3: Vegas method.
- 18:31Speaker 1: I love the Las Vegas method because it's so uncompromising.
- 18:34Speaker 1: It essentially guarantees a perfectly uniform distribution by simply throwing
- 18:39Speaker 1: the excess pizza slices directly into the trash.
- 18:43Speaker 3: That's pretty much it in terms of the code. If
- 18:46Speaker 3: the algorithm generates a huge number that happens to fall
- 18:49Speaker 3: into that uneven remainder zone at the very top of
- 18:51Speaker 3: its range, the code literally intercepts it.
- 18:55Speaker 1: It just catches it.
- 18:56Speaker 3: Yeah, it discards the number silently and goes right back
- 18:59Speaker 3: to the start of the loop reroll.
- 19:01Speaker 2: It repeats this.
- 19:02Speaker 3: Invisible process in a fraction of a millisecond until it
- 19:06Speaker 3: generates a number that falls cleanly into the perfectly divisible range.
- 19:09Speaker 1: And only then does it show the die roll to
- 19:12Speaker 1: the player.
- 19:12Speaker 3: Yes, it sacrifices precious computing power and time purely to
- 19:16Speaker 3: guarantee absolute fairness.
- 19:18Speaker 1: It's beautiful. But so many game mechanics have nothing to
- 19:21Speaker 1: do with rolling dice, right. They are about managing time
- 19:24Speaker 1: and flow, like when does the next wave of zombies attack?
- 19:27Speaker 1: Or when does a rainstorm start?
- 19:29Speaker 2: Get pacing?
- 19:30Speaker 1: Yeah, how do you pace the game so the player
- 19:32Speaker 1: doesn't get bored but also it doesn't get completely overwhelmed?
- 19:35Speaker 3: Well, translating raw randomness into organic feeling events over time
- 19:39Speaker 3: requires discrete probability distribution, okay, and The most vital one
- 19:43Speaker 3: detailed by Smet and Hacona is the Poisson distribution.
- 19:46Speaker 1: Right, and the book has this fantastic example of an
- 19:49Speaker 1: asteroid mining colony in a strategy game. The designers want
- 19:53Speaker 1: the spaceport to feel like a bustling, living economy, so
- 19:56Speaker 1: they determine that, on average, the colony should receive seven
- 20:00Speaker 1: cargo haulers every single rotation period.
- 20:03Speaker 3: Now, if the code just spawns exactly seven haulers, evenly
- 20:06Speaker 3: spaced out every single rotation, well, if the spaceport just
- 20:10Speaker 3: feels like a sterile assembly.
- 20:11Speaker 1: Line, it doesn't feel alive, not at all.
- 20:14Speaker 3: But the developers don't just program seven haulers. They feed
- 20:18Speaker 3: that target average of seven into the poison distribution algorithm.
- 20:21Speaker 1: And what does that do.
- 20:23Speaker 3: What this math does is translate a flat average into
- 20:25Speaker 3: a dynamic curve of likelihoods for any number of events.
- 20:29Speaker 3: So on most rotations you might get six or eight hollars.
- 20:32Speaker 3: It feels pretty normal, right, but the math allows for outliers.
- 20:35Speaker 3: Suddenly you have a rotation where only two haulers show up,
- 20:38Speaker 3: and your economy slows down. That ek sets in, and
- 20:40Speaker 3: then without warning, the Poisson curve hits a rare probability
- 20:44Speaker 3: and fourteen haulers arrive at the exact same time.
- 20:47Speaker 1: The sirens go off. Your spaceport thrown into total logistical chaos,
- 20:51Speaker 1: and you are just scrambling to manage the influx.
- 20:54Speaker 3: Yes, the Poisson distribution guarantees that if you average it
- 20:58Speaker 3: out over a thousand rotations will equal exactly seven. But
- 21:02Speaker 3: minute to minute, it generates these organic lulls and terrifying
- 21:05Speaker 3: spikes of activity.
- 21:07Speaker 1: It creates the actual pulse of the game. That feeling
- 21:10Speaker 1: of panic when those fourteen hollars arrive, that rush of adrenaline,
- 21:13Speaker 1: when you barely manage the crisis. You know you are
- 21:16Speaker 1: having a genuine emotional reaction to a probability curve.
- 21:20Speaker 3: You are reacting to an engineered ilusion. And really, that
- 21:23Speaker 3: is the ultimate takeaway from Smed and Hakonan's work. The
- 21:26Speaker 3: magic of a digital world isn't magic at all.
- 21:29Speaker 1: No, it's not the Next time you are playing a
- 21:31Speaker 1: game and you find yourself marveling at how a synthetic
- 21:34Speaker 1: player panicked and missed a shot, or how the narrative
- 21:36Speaker 1: seamlessly adapted to a chaotic decision you made, or how
- 21:39Speaker 1: a sudden rainstorm perfectly matched the dramatic tension of the scene.
- 21:43Speaker 1: Just remember the math churning beneath the surface.
- 21:46Speaker 2: It's all math.
- 21:47Speaker 1: It is the intricate, silent work of invisible drama managers
- 21:51Speaker 1: keeping the narrative paradox in check. It is the uncompromising
- 21:54Speaker 1: fairness of the Las Vegas method, silently discarding uneven numbers.
- 21:58Speaker 1: And it's the linear congrential method spinning a massive prime
- 22:02Speaker 1: numbered clock face, generating chaos from a single seed of
- 22:06Speaker 1: physical reality.
- 22:07Speaker 3: It is entirely deterministic architecture masquerating flawlessly as wild living unpredictability,
- 22:14Speaker 3: which actually leaves us with a rather profound implication to
- 22:17Speaker 3: consider long after you take your headphones off.
- 22:19Speaker 1: Ooh, laid on us.
- 22:20Speaker 3: Well, think about it. If human developers working with just
- 22:23Speaker 3: basic processors can use deterministic loops, prime numbers, and hidden
- 22:27Speaker 3: distribution curves to create such a convincing, unbreakable illusion of
- 22:31Speaker 3: random chance, chaos, and free will inside a digital box, well,
- 22:34Speaker 3: how do we know our own universes supposedly random events
- 22:38Speaker 3: aren't doing the exact same thing? Oh wow, how do
- 22:40Speaker 3: we know the quantum physics of our reality like the
- 22:42Speaker 3: very fabric of chance in our universe isn't just a
- 22:45Speaker 3: cosmic linear congruential method running on an unfathomably large prime.
- 22:49Speaker 1: Modulus that is heavy. So the next time you're walking
- 22:52Speaker 1: in the woods and a twig snap's unexpectedly, maybe ask
- 22:55Speaker 1: yourself what the seed value was. Thanks for joining us
- 22:58Speaker 1: on this deep dive. Keep questioning a code