Algorithms and Networking for Computer - podcast episode cover

Algorithms and Networking for Computer

Jun 21, 202623 min
--:--
--:--
Download Metacast podcast app
Listen to this episode in Metacast mobile app
Don't just listen to podcasts. Learn from them with transcripts, summaries, and chapters for every episode. Skim, search, and bookmark insights. Learn more

Episode description

A comprehensive technical guide written by Jouni Smed and Harri Hakonen. This textbook defines the fundamental components of games, such as rules, goals, and conflict, while exploring the mathematical and computational structures necessary to build them. The authors utilize the Model-View-Controller architectural pattern to describe the anatomy of a computer game and outline the various professional disciplines and phases involved in modern game development. Extensive tables of contents reveal that the book covers specialized topics including procedural generation, pathfinding, and decision-making alongside networking challenges like latency compensation and anti-cheating measures. Ultimately, the source serves as a bridge between academic computer science and the practical requirements of the entertainment industry.

You can listen and download our episodes for free on more than 10 different platforms:
https://linktr.ee/cyber_security_summary

Get the Book now from Amazon:
https://www.amazon.com/Algorithms-Networking-Computer-Games-Jouni-ebook/dp/B07MGL8JZW?&linkCode=ll2&tag=cvthunderx-20&linkId=f5eaccfd713f30c5b39627db874cbf19&language=en_US&ref_=as_li_ss_tl

Discover our free courses in tech and cybersecurity, Start learning today:
https://linktr.ee/cybercode_academy

Transcript

Speaker 1

So picture this. You're playing a game and you round a corner in some dark digital dungeon and boom and enemy suddenly springs an ambush.

Speaker 2

Oh yeah, your heart just completely jumps into your throat.

Speaker 1

Right, And in that split second, you know, you're not thinking about code or like pixels on a screen.

Speaker 2

Oh of course not.

Speaker 1

You're just thinking, wow, that felt so real. Because we play these games expecting this organic spontaneity, right, We really want that digital world to feel alive, we do.

Speaker 3

But the truth is that organic feeling is entirely fabricated, like completely, when you actually step behind the curtain of game development, all that spontaneity just vanishes. You're looking at this landscape of cold, hard, purely deterministic code.

Speaker 1

Which is so wild to think about.

Speaker 3

It is because computers are well, they're rigid machines. You literally cannot be spontaneous. Everything you feel in that dungeon is just a meticulously crafted mathematical illusion.

Speaker 1

And today we are ripping open that code to see exactly how developers pull off that trick. We are doing a deep dive into this brilliant textbook. It's called Algorithms and Networking for Computer Games by Juni Smed and Harriet Conan.

Speaker 2

It's a fascinating read, it really is.

Speaker 1

And our mission today is to figure out how programmers manipulate math and psychology to trick your brain. We're going to start from the foundational rules of play and go all the way down to the invisible algorithms that basically manufacture chaos.

Speaker 3

Yeah, and to understand the math, we first have to agree on what we're actually trying to simulate, right, right, Because when you strip away the high resolution graphics and you know, the fancy haptic feedback controllers, Smed and Hakonan argue that an interactive world requires one specific crucial ingredient to separate it from just a static puzzle.

Speaker 2

And that ingredient unpredictability.

Speaker 1

Okay, let's unpack this because the book uses a really specific word here, which is conflict. Yes, conflict, And when I hear conflict, my mind immediately goes to like fighting a digital dragon or racing against a rival car. But the authors argue it's actually way broader than that, much brighter. Yeah, because think about a Sunday crossword puzzle, right. It's challenging, it has rules, it has a goal, but is it a game.

Speaker 3

Well, by the strict definitions used in game architecture, a standard crossword puzzle is not actually a game. Wait really yeah, because it lacks non determinism. A crossword puzzle just sits there. It doesn't fight back, you know, doesn't adapt.

Speaker 2

To your choices.

Speaker 1

Okay, I see.

Speaker 3

So conflict in this specific context means you are facing an opposing force or some random process that actively obstructs you.

Speaker 1

Right, So if you add a ticking timer to that crossword or I don't know, you're raising a friend to finish it first.

Speaker 3

Suddenly have non determinism. Exactly, You've injected chaos, and now you have game.

Speaker 1

Okay, So in a single player experience, developers have to artificially inject that chaos. They have to simulate an opposing force using AI, which the authors call synthetic players.

Speaker 2

Right, synthetic players.

Speaker 1

But here is the most counter intuitive part of this whole illusion. For me, to make an AI opponent feel like a real, living human, developers actually have to break it. Yes, they have to make the AI significantly worse.

Speaker 3

Well, you have to consider what computers are actually capable of, right, Like a machine can calculate your character's exact coordinates aim with pixel perfect precision and just eliminate you the exact millisecond you enter its line of sight.

Speaker 1

Right, It's basically the Terminator exactly.

Speaker 3

It possesses superhuman perfection, but playing against flawless perfection is incredibly boring and frustrating. Completely, it feels robotic, and it instantly shatters that illusion of playing against a living, breathing entity in a shared space.

Speaker 1

So it's all about simulating human flaws. And there is this amazing specific detail from the text about how developers engineer this.

Speaker 2

Oh the reaction time.

Speaker 1

Yes, when you take a synthetic player by surprise, say you flank an enemy in a shooter game, the programmers hard code a deliberate zero point two to zero point four second reaction time delay before the AI is even allowed to shoot back.

Speaker 3

Yeah, and that specific window of time is absolutely no accident. It simulates the cognitive processing time of a human being. It basically mimics panic, panick.

Speaker 1

Right.

Speaker 3

Yeah, So when you surprise an enemy and they freeze for like a third of a second before scrambling for cover, your brain subconsciously registers the ODEA.

Speaker 1

Loop, the Obie loop.

Speaker 3

Yeah, observe orient decide act, you recognize that slight hesitation as human cognition, and the illusion holds.

Speaker 1

Wow. But this introduces a massive headache for the game designers, doesn't it.

Speaker 2

Oh a huge one.

Speaker 1

Because if you program these synthetic players to act somewhat unpredictably, and then you give the actual human player the freedom to do literally whatever they want, how on earth do you guarantee the game still tells a cohesive story.

Speaker 3

Well, you've hit on what the authors called the narrative paradox. It is the central tension in all interactive storytelling.

Speaker 1

A narrative paradox.

Speaker 2

Yeah.

Speaker 3

So, on one side of the scale you have plot coherence, the there's in the designers. They want to deliver a well paced, dramatic, emotionally resonant story.

Speaker 2

Like a movie exactly.

Speaker 3

But on the other side you have character believability and player agency. You need the player and the AI to have the actual freedom to ma choices.

Speaker 1

Because if I have total freedom, I might just decide to wander off into the woods to pick digital mushrooms and completely ignore the terrifying dragon that's supposed to be attacking the castle.

Speaker 3

Right, and then the pacing is completely ruined. The story just grinds.

Speaker 2

To a halt.

Speaker 1

So how do they fix that?

Speaker 3

So the industry generally tackles this tension from two different directions. The first is a character centric approach. Okay, here, the AI characters are highly autonomous. They act on their own program, desires, and needs, and sometimes they even use a hybrid communication system.

Speaker 1

Wait, what does that mean.

Speaker 3

Well, they speak in character to the player, but simultaneously they send out of character signals to the game's background systems to try gently nudge the plot forward organically.

Speaker 1

Oh that's clever, it is.

Speaker 3

The story basically emerges from the bottom up.

Speaker 1

But the problem with the bottom up approach is that it can quickly turn into the chaos of everyday life. Right, real life isn't inherently structured like a three act cinematic blockbuster.

Speaker 2

No, it definitely isn't.

Speaker 1

So the alternative is the author centric approach, which relies on something called an invisible drama manager.

Speaker 3

Yes, the drama manager, which I love.

Speaker 1

Think of it like a stage director secretly walking among the actors, whispering in their ears, completely unseen by the audience.

Speaker 2

That's a perfect way to put it.

Speaker 3

The drama manager is constantly running math in the background, monitoring metrics like player tension and pacing.

Speaker 1

So that's washing what I do constantly.

Speaker 3

If the algorithm's determined you've been wandering the woods picking mushrooms for way too long and the tension is dropping, the drama manager whispers to the AI enemies to spawn an ambush just out of your line of sight.

Speaker 1

To get my heart rate back up exactly.

Speaker 3

Or conversely, if you are low on health and completely overwhelmed, it tells the enemies to pull back a bit or to miss their shots. It subtly manipulates the parameters of the world to push you toward the intended emotional beats.

Speaker 1

But even with a brilliant invisible director, the developers still have to physically build the paths the story can take. Right they do, and the text maps out game stories using these geometrical graphs. The most basic one is just a linear story. Episode A always leads to episode B, which leads to episode C. It's just a straight line.

Speaker 3

Yeah, and linear development is incredibly cost effective, but it offers almost zero agency. You're essentially just walking through a movie, right. The theoretical opposite of that is a fully branching structure where every single choice you make leads to a completely different, unique continuation of the game.

Speaker 1

Which sounds like the holy grail of gaming until you actually do the math on the combinatorial explosion.

Speaker 2

Oh, the math is terrifying.

Speaker 1

It really is. Let's say you have a scene with three dialogue choices, and each of those choices leads to three entirely new scenarios. By the time you reach the fourth major decision point in the game, you aren't programming one game anymore. You're programming eighty one completely different games. You'd have studio spending twelve years and half a billion dollars just to make a five hour campaign.

Speaker 3

It's completely unsustainable. So developers rely on a highly calculated compromise called parallel pass. Parallel pad right, the story branch is out for a while, allowing you to make choices, take different routes, and express your agency. This provides that crucial illusion of free will ah illusion. But eventually all those diverged branches are forced to converge back into major, unavoidable story nodes.

Speaker 1

So I might use diplomacy to talk my way past the guards, and you might just kick the door down with explosives typical exactly, but thirty minutes later, we both end up standing in the exact same throne room for the exact same final boss fight.

Speaker 3

Yes, the game just acknowledges are different methods in the dialogue. It keeps the studio from going bankrupt while letting us feel like we are the actual authors of our own fate.

Speaker 1

So the illusion of free will is maintained by carefully hidden constraints exactly, And that reliance on nondeterminism, you know, on generating a feeling of unpredictable chaos within strict mathematical limits, brings us to the very bedrock of how a computer operates.

And here's where it gets really interesting for me, oh for sure, Because whether we are talking about parallel story branches, or that zero point three second reaction delay for the AI, or even simulating a dice roll, games need randomness to function.

Speaker 2

They desperately need it.

Speaker 1

But a computer processor is a purely deterministic machine. It only executes the exact logic gits it is fed. It cannot flip a coin. True randomness in a computer is a total myth.

Speaker 3

It is developers literally have to fake it. Yeah, they use algorithms to produce sequences of numbers that just behave unpredictably, and these fall into two main categories, which are quasi random and pseudorandom.

Speaker 1

Oh hey, let's break this down well.

Speaker 3

Quasi random numbers are sequences that actually have a hidden structural rule, but they just appear random to a naive observer.

Speaker 1

Right, So, think of a sequence that alternates strictly between even and odd numbers, but the numbers themselves jump wildly across a massive range. Good example, if you just look at a short sample of that, it feels totally chaotic, but there's a rigid skeleton holding it together to ensure an even spread of events over time.

Speaker 3

Yeah, and that even spread is really useful for certain visual rendering tasks. But when we need numbers that pass rigorous statistical tests for actual chaotic unpredictability, we need pseudorandom number generators.

Speaker 1

Pseudorandom.

Speaker 3

Yes, and the foundational algorithm detailed by Smed and hecanin is the linear congruential method or the LCM.

Speaker 1

The LCM now it sounds like high level calculus, but it's really just a simple mathematical loop built on four parameters.

Speaker 2

Right. It is surprisingly simple.

Speaker 1

You have the modulus, which we'll call M. You have the multiplier A, the increment C, and a starting value which is known as the.

Speaker 3

Seed exactly, and the operation itself is just basic arithmetic. So the algorithm takes your seed value and it multiplies it by.

Speaker 2

A, and then it adds C.

Speaker 1

Okay, easy enough, right, But then it.

Speaker 3

Divides that total by the modulus M and whatever the remainder of that division is. That remainder becomes your first random number, the remainder, right, yeah, Then the algorithm takes that brand new number, plugs it back into the start of the formula is the new seed, and runs the entire loop again.

Speaker 1

So picture a clock face. Let's say our modulus is twelve, so we have a standard twelve hour clock. No matter how wildly you multiply or add numbers together, when you divide by twelve and take the remainder, the answer is just spinning around the dial, right, that's right. It will always land on a notch between one and twelve.

Speaker 3

It's a really elegant way to constrain infinite math into a usable range. But because it's a closed mathematical loop operating within that fixed clock face, the sequence of numbers will eventually run out of unique combinations, it starts repeating itself exactly.

Speaker 1

Oh wow.

Speaker 3

The length of this unique sequence before it finally loops is called the period. So if your modulus is twelve, the absolute maximum period you can achieve is twelve numbers.

Speaker 1

And a repeating loop is the death of unpredictability. Like if I'm playing a digital card game and I realize the deck is dealing me the exact same sequence of hands every twelve rounds, the illusion completely shatters. It does I can predict the future. The game is basically broken at that point.

Speaker 3

So to prevent the player from ever seeing the loop, developers use unimaginably massive numbers for the modulus. But you can't just pick any large number.

Speaker 1

Why not?

Speaker 3

You want a very specific mathematical structure, ideally a prime number. Specifically, developers often use Mrsenne primes.

Speaker 1

Okay, wait, so why a prime number? If I just pick a huge round number like a billion, doesn't that just give me a billion notches on my clock? Face?

Speaker 3

It does, but it introduces this problem of coprimality to primality. Yeah, your modulus clod phase shares a common divisor with your multiplier, the math will start skipping notches.

Speaker 1

Oh I think I see.

Speaker 3

Imagine a twelve hour clock and your multiplier forces you to jump by threes. You hit three, six, nine, twelve, and then you're right back where you started.

Speaker 1

You only generated four unique numbers, even though your clock has twelve spaces.

Speaker 3

Exactly, by using a massive prime number for the modulus, you guarantee it shares no divisors with your other parameters. It forces the algorithm to step on every single unique notch before it's ever allowed to loop.

Speaker 1

That is genuinely brilliant, and the text mentions a common Mersen prime used is two to the thirty first power minus one, which is over two point one billion massive. So the clockface has two point one billion unique notches, and because it's prime, we hit every single one. The sequence still repeats eventually, but the period is so incomprehensibly long that a human playing the game will literally never live long enough to notice the pattern.

Speaker 3

True, but there is a huge vulnerability in this closed loop.

Speaker 1

Wait really, because I'm looking at this formula, MA and C are hard coded by the developer. The only variable that starts the whole chain reaction is the seed exactly. So if I turn on my console, boot up the game, and the default seed value is just the number one every single time. Wouldn't the math just spit out the exact same sequence of random events every time I play yes?

Speaker 3

The game would play out exactly the same way. The ambush that terrified you in your first playthrough would happen at the exact same millisecond in your second play through. That ruins everything, right, So to fix this, developers have to inject a tiny spark of real world physical chaos to kickstart the math. They will program the game to fetch its starting seed from highly variable, totally unpredictable sources from outside the game's.

Speaker 1

Code, like grabbing the computer's internal clock time down to the microscopic millisecond of the exact moment you press start yes exactly, or pulling data from the tiny erratic temperature fluctuations of the CPU, or even the microscopic tremor of your hand on the computer mounts. They literally capture a fraction of physical reality to see the digital illusion.

Speaker 2

That is amazing, it's really cool.

Speaker 3

But once you've seeded the algorithm and it's churning out billions of numbers, you still have a massive problem. Another one, Yeah, how do you actually know the illusion works, you have to test it rigorously, right, and the text outlines several empirical tests, like the poker test, where yougroup the generator's output into hands of five and see if they match the real world statistical probability of drawing a full house

or a flush. That makes sense, But the most revealing diagnostic for the linear congruential method is called the spectral test.

Speaker 1

The spectral test, Okay, it sounds like ghost hunting.

Speaker 3

It does, but it's actually a highly visual geometric test. So imagine taking the sequence of number your algorithm produces, yeah, grouping them into pairs, and plotting those pairs as x and y coordinates on a massive two.

Speaker 1

Okay, I'm picturing it.

Speaker 3

If your generator is producing true chaotic randomness, that graph should look like pure uniform television static. There should be absolutely no pattern.

Speaker 1

But the LCM isn't true chaos. It's built on fixed multiplication and addition.

Speaker 3

Exactly because of that linear mathematical relationship. If you zoom out and look at that TV static, you will realize that dots aren't actually random at all. They align to form a lattice of perfectly parallel lines. Wow, they are mathematically tethered together. And if you group the numbers into triplets and plot them in a three D space, those lines become parallel planes.

Speaker 1

So the illusion has literal seams in it. The randomness is basically stacked in layers.

Speaker 3

Yes, the spectral test measures the distance between those parallel planes. If the planes are too far apart, it means there are massive predictable gaps in your random spread, and you don't want that. No, So a high quality algorithm uses parameters carefully calibrated to push those planes as tightly together as possible, basically blurring the lines until the human eye and statistical analysis only sees pure static.

Speaker 1

Okay, So let's say our math past the spectral test. The algorithm is incredibly robust, and it just generated a massive pseudo random number, let's say one point eight billion. Okay, but I'm playing a digital board game and my character just needs to roll a standard six sided die. How does the code shrink a massive one point eight billion output down to a tiny interval of one to six without destroying the delicate randomness we just engineered.

Speaker 3

Well, if you take the lazy route, you absolutely ruin the die.

Speaker 2

Yeah.

Speaker 3

Most basic approach, which the text calls the Monte Carlo method is to just divide your massive random number by six.

Speaker 1

And take the remainder like the clock face right.

Speaker 2

But this warps the distribution.

Speaker 1

Because the maximum limit of your huge random number generator probably isn't perfectly divisible.

Speaker 2

By six exactly.

Speaker 1

Think of it like having a pizza with twenty slices and you need to divide it evenly among six people. Everyone gets three slices, but you have two slices left.

Speaker 2

Over, yep, the remainder.

Speaker 1

And if you just hand those remaining slices out to whoever is closest, two people end up with more pizza. In the code. That means the numbers one and two end up with slightly more mathematical real estate than three, four, five, or six.

Speaker 3

Which means the digital die becomes mathematically loaded. Over the course of thousands of roles, the player will absolutely notice that they are rolling ones in twos more often.

Speaker 1

And it feels completely unfair it does.

Speaker 3

So to solve this, developers use something called the Las Vegas method.

Speaker 1

I love the Las Vegas method because it's so uncompromising. It essentially guarantees a perfectly uniform distribution by simply throwing the excess pizza slices directly into the trash.

Speaker 3

That's pretty much it in terms of the code. If the algorithm generates a huge number that happens to fall into that uneven remainder zone at the very top of its range, the code literally intercepts it.

Speaker 1

It just catches it.

Speaker 3

Yeah, it discards the number silently and goes right back to the start of the loop reroll.

Speaker 2

It repeats this.

Speaker 3

Invisible process in a fraction of a millisecond until it generates a number that falls cleanly into the perfectly divisible range.

Speaker 1

And only then does it show the die roll to the player.

Speaker 3

Yes, it sacrifices precious computing power and time purely to guarantee absolute fairness.

Speaker 1

It's beautiful. But so many game mechanics have nothing to do with rolling dice, right. They are about managing time and flow, like when does the next wave of zombies attack? Or when does a rainstorm start?

Speaker 2

Get pacing?

Speaker 1

Yeah, how do you pace the game so the player doesn't get bored but also it doesn't get completely overwhelmed?

Speaker 3

Well, translating raw randomness into organic feeling events over time requires discrete probability distribution, okay, and The most vital one detailed by Smet and Hacona is the Poisson distribution.

Speaker 1

Right, and the book has this fantastic example of an asteroid mining colony in a strategy game. The designers want the spaceport to feel like a bustling, living economy, so they determine that, on average, the colony should receive seven cargo haulers every single rotation period.

Speaker 3

Now, if the code just spawns exactly seven haulers, evenly spaced out every single rotation, well, if the spaceport just feels like a sterile assembly.

Speaker 1

Line, it doesn't feel alive, not at all.

Speaker 3

But the developers don't just program seven haulers. They feed that target average of seven into the poison distribution algorithm.

Speaker 1

And what does that do.

Speaker 3

What this math does is translate a flat average into a dynamic curve of likelihoods for any number of events. So on most rotations you might get six or eight hollars. It feels pretty normal, right, but the math allows for outliers. Suddenly you have a rotation where only two haulers show up, and your economy slows down. That ek sets in, and then without warning, the Poisson curve hits a rare probability and fourteen haulers arrive at the exact same time.

Speaker 1

The sirens go off. Your spaceport thrown into total logistical chaos, and you are just scrambling to manage the influx.

Speaker 3

Yes, the Poisson distribution guarantees that if you average it out over a thousand rotations will equal exactly seven. But minute to minute, it generates these organic lulls and terrifying spikes of activity.

Speaker 1

It creates the actual pulse of the game. That feeling of panic when those fourteen hollars arrive, that rush of adrenaline, when you barely manage the crisis. You know you are having a genuine emotional reaction to a probability curve.

Speaker 3

You are reacting to an engineered ilusion. And really, that is the ultimate takeaway from Smed and Hakonan's work. The magic of a digital world isn't magic at all.

Speaker 1

No, it's not the Next time you are playing a game and you find yourself marveling at how a synthetic player panicked and missed a shot, or how the narrative seamlessly adapted to a chaotic decision you made, or how a sudden rainstorm perfectly matched the dramatic tension of the scene. Just remember the math churning beneath the surface.

Speaker 2

It's all math.

Speaker 1

It is the intricate, silent work of invisible drama managers keeping the narrative paradox in check. It is the uncompromising fairness of the Las Vegas method, silently discarding uneven numbers. And it's the linear congrential method spinning a massive prime numbered clock face, generating chaos from a single seed of physical reality.

Speaker 3

It is entirely deterministic architecture masquerating flawlessly as wild living unpredictability, which actually leaves us with a rather profound implication to consider long after you take your headphones off.

Speaker 1

Ooh, laid on us.

Speaker 3

Well, think about it. If human developers working with just basic processors can use deterministic loops, prime numbers, and hidden distribution curves to create such a convincing, unbreakable illusion of random chance, chaos, and free will inside a digital box, well, how do we know our own universes supposedly random events

aren't doing the exact same thing? Oh wow, how do we know the quantum physics of our reality like the very fabric of chance in our universe isn't just a cosmic linear congruential method running on an unfathomably large prime.

Speaker 1

Modulus that is heavy. So the next time you're walking in the woods and a twig snap's unexpectedly, maybe ask yourself what the seed value was. Thanks for joining us on this deep dive. Keep questioning a code

Transcript source: Provided by creator in RSS feed: download file
For the best experience, listen in Metacast app for iOS or Android