28
CS 4730 Probability and Risk CS 4730 – Computer Game Design Credit: Several slides from Walker White (Cornell)

CS 4730 Probability and Risk CS 4730 – Computer Game Design Credit: Several slides from Walker White (Cornell)

Embed Size (px)

Citation preview

CS 4730

Probability and Risk

CS 4730 – Computer Game Design

Credit: Several slides from Walker White (Cornell)

CS 47302

Quick Recap• The game state is the current positioning/value

of all entities in the game world• Actions a player takes is input into the current

game state• An interaction is a function between game

states as determined by the actions (of both player and world) in generating a new game state

• The Game Loop

CS 47303

The Game Loop• In general:

– Handling time– Gathering player input– Networking– Simulation– Collision detection and response– Object updates– Rendering– Other miscellaneous tasks

CS 47304

In MonoGame• Initialize()

– Network, DB, etc.• LoadContent()

– Graphics and other assets loaded• Update(GameTime)

– Update the game state based on input• Draw(GameTime)

– Refresh the screen

CS 47305

MonoGame• Design doc due Friday

– Follow requirements for Written Word• Prototype due next Friday

– We will expect at least one realized mechanic in the game

– We do NOT expect great art, music, etc.– If you expect controller input later, we expect that

now

CS 47306

It All Start With Numbers• Hope you remember your APMA classes…• Statistics is the study of what HAS happened• Probability predicts what WILL happen• The interesting this is that people are

reasonably good at statistics, but horrible at probability

• “What’s the likelihood it will rain tomorrow?”

CS 47307

Randomness• Computers are actually horrible at being truly

random• Which is both good and bad• Bad for security purposes• Good for networked games to have the same

state without transmitting that state• Probability of any value is written as P(x)

CS 47308

Traditional Randomness• Cards and dice are still used as metaphors for

randomness• (and non-metaphors…)• We still uses these items in both board and

video games for randomness

CS 47309

Cards and Dice• Card notation:

– 4S – 4 of Spades– AH – Ace of Hearts

• Dice notation– xdn, where x is the number of dice to roll and n is

the number of sides on each dice– 2d6 – roll 2 6-sided dice, values will be 2-12– 3d8+4 – roll 3 8-sided dice and add 4 to the result,

values will be 7-28

CS 473010

The Outcome Tree• We can calculate the probability of any random

event by working out the outcome tree and counting the possibility

• Monte Carlo simulations run the function for a large number of times and using that to determine percentages

CS 473011

Combining Probabilities• P(not A) = 1 – P(A)• P(A or B) = P(A) + P(B)• P(A and B) = P(A) * P(B)

CS 473012

Expected Value• The expected value is the average of all the

possibilities of a random variable• Each value is weighted by its probability• E(x) = Sum(k * P(“x=k”)) over the possible

values of k• E(1d2) = 1 * P(“x=1”) + 2 * P(“x=2”)

= 1 * .5 + 2 * .5= 1.5

CS 473013

Dice Expected Values• E(1d4) = 2.5• E(1d6) = 3.5• E(1d8) = 4.5• E(1d10) = 5.5• E(1d12) = 6.5• E(1d20) = 10.5

CS 473014

Variance• What is the distribution of possible values

about the expected value?• Var(x) = E((x – E(x))2)• Uniform (high variance)• Bimodal (low and high variance)• Gaussian (low and high variance)• Zero variance

CS 473015

Compound Expressions• E(x + y) = E(x) + E(y)• E(x + c) = E(x) + c• E(c * x) = c * E(x)• E(x * y) = E(x) * E(y)• Var(x + y) = Var(x) + Var(y)• Var(x + c) = Var(x)• Var(c * x) = c2 * Var(x)

CS 473016

Probabilities of Catan• Let’s look at the math of Catan to figure out

how probabilities play into the game• Quick overview of the rules of Settlers of Catan

– http://www.catan.com/service/game-rules

CS 473017

Settlers of Catan

CS 473018

Probabilities of Catan• It’s actually pretty easy to know what’s the

“best” option– Just add up the dots!

• Probability and randomness plays a HUGE role in Catan working “correctly.”

• What about games in which probability and randomness is the entire game?

CS 473019

Chutes and Ladders

CS 473020

Chutes and Ladders• The game is ALL RANDOM.• But a video game that is ALL SKILL can

eventually get boring!– You’ve learned every pattern– You’ve seen every level and enemy– Nothing varies!

• We need to consider games that have some aspects of both!

CS 473021

Why do people gamble?• Let’s face it – gambling in Vegas is a losing

proposition• Over time, everyone loses money• But in the (very) short term, it’s definitely

possible to win• And besides – risk and uncertainty can be a lot

of fun!

CS 473022

Psychology of Randomness• Player’s like longshots!

– How many times have you gone for the “super move” to win the game?

– Even if it’s a low probability, players will optimize for it!

• Player’s suffer from too much Monte Carlo– “Oh, I’ve gotten bad results for so long… a good

card/good roll has to come up soon!”– Probability does not care what the last roll was, but

players will think the game is “unfair” otherwise!

CS 473023

Psychology of Randomness• But think about it another way – I bet you

remember those big payoff moments• And THAT’S what gets you coming back to a

game!

CS 473024

Other Forms of Risk• Imperfect information can add to the

challenge/risk in a game without as much randomness

• Perhaps you don’t know everything about the game state– Either AI or another player

• Perhaps don’t know about the game might change

CS 473025

Fog of War - Partial

CS 473026

Fog of War - Total

CS 473027

Information Types• Info known to all players• Info known by one player• Info known by the game only

– Some game state information, like next card in the deck

• Info unknown– Next random number to be generated

CS 473028

Difference Between Video and Board• Table top games rely on randomness to work

– Information that the game only knows can be hard to manage

– D&D does this through a Dungeon Master• However, while computers aren’t as good at

randomness, they are fantastic at managing information

• Implementation and adherence to rules also varies greatly