1 / 29

Probability and Bayesian Theory for Games

Probability and Bayesian Theory for Games. What is Probability? . Using Probability in Games. Hit probabilities Damage probabilities Personality (e.g. chance of attack, run, etc.) ???

joshwa
Download Presentation

Probability and Bayesian Theory for Games

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Probability and Bayesian Theory for Games

  2. What is Probability?

  3. Using Probability in Games • Hit probabilities • Damage probabilities • Personality (e.g. chance of attack, run, etc.) • ??? • Probabilities are used to add a little uncertainty into the game AI in terms of decision making (most of the time), strategy and tactics, and even spawn occurrences • We look at some examples…

  4. 1. Randomness • Generation of random numbers • Common practice  Seeding random numbers • Random numbers can be fed into various game AI – movement, decision-making , strategy to provide a sense of randomness • May not reflect behaviors intelligently

  5. 2. Hit Probabilities • Representing a character’s chances of hitting and opponent in combat or battle • Typically, a game developer defines several probabilities (RPG game e.g.) • Moderate dexterity – 60% prob. of striking with knife in melee • High dexterity – 90% prob. of striking with knife • Probabilities can be adjusted given other factors (High dex e.g.) • 95% -- in possession of “Dagger of Speed” • 85% -- opponent has magic armour

  6. Hit Probabilities • Design hit probability tables to calculate the appropriate probability given the occurrence or non-occurrence of any number of events or conditions

  7. 3. Character Abilities • Define abilities of character classes using probabilities

  8. Character Abilities • In practice, these probabilities can be further conditioned on the overall class level • A first-level wizard might have only 10% chance of using magic • The idea here is that as the player earns levels, his proficiency in the craft increases (reflected by the probabilities) • On the computer-side of the game AI, other characters in the world can have their own set of probability tables…

  9. 4. State Transitions • Combine probabilities with state transitions in a FSM

  10. State Transitions • Instead of deterministically selecting a state to move to, assign certain probabilities to each transition • 50% chance of attacking, 20% chance of fleeing, 10% chance of hiding • For even more variability, assign different probabilities to different types of characters, making some more aggressive than others, etc. • A step further  distinct personalities?

  11. State Transitions • How do we implement this efficiently?

  12. 5. Adaptability • Update certain game probabilities as the game is played to facilitate computer-controlled AI learning and adapting (Non-deterministic AI) • E.g. Collect statistics on the number and outcome of fights between different characters • Probability of encounters resulting in a win (or death) can be calculated real-time • Use this change of probabilities to make future decisions on whether to engage in battle or avoid certain characters or flee battle, etc.

  13. Probability • 3 common interpretations of probability • Classical Probability • Frequency Interpretation • Subjective Interpretation

  14. Classical Probability • Refers to events and possibilities, or possible outcomes • Given an event E, which can occur in n ways out of a total of N possible outcomes, the probability p of occurrence of the event is: p = P(E) = n/N • P(E): Probability of success of the event • Probability of failure of the event: 1-P(E)

  15. Classical Probability • E.g. Rolling a six-sided dice, the probability that a 4 would show up is…? • Consider two six-sided dice, both rolled at the same time, what is the probability that the sum of the numbers that show up equal to 5?

  16. Frequency Interpretation • Also known as relative frequency or objective probability • Considers events and samples or experiments • If an experiment is conducted N times and some event E occurs n times, the probability of E occurring is: P(E) = n/N as N • For finite number of experiments, the resulting probability will be approximate or empirical  derived statistically

  17. Frequency Interpretation • Frequentist approach: Coin tossed 1000 times • Experimentally, the results could come to getting heads 510 times (e.g.), so the probability of getting heads is P(heads) = 0.51 or 51% • Should “approach” 0.5 if number of experiments increase… • Approximation by experiment

  18. Subjective Interpretation • A measure, on a scale from zero to one, of a person’s degree of belief that a particular event will occur given their knowledge, experience or judgment. • Useful when the event in question is not repeatable (therefore, can’t use frequentist approach)

  19. Subjective Interpretation • “It probably will rain tomorrow”, “I have a good chance of passing this subject” • More empirical e.g. “I have a 75% chance of passing this subject” • If you later did better in the next homework/assignment, you might revise you belief that you have a 90% chance of passing the subject • Bayesian theory • Allows us to update our belief of some event given the availability of new information

  20. Subjective Interpretation Odds • Common in betting scenarios • If we say the odds in favour of success of some event E, are “a to b” (3 to 1 odds, e.g.), the probability of success of that event, P(E) P(E) = a / (a+b) • Can work the opposite direction, given the probability  work out the odds

  21. Subjective Interpretation Expectation • Expected value of some discrete random variable X that can take on any values, x0, x1,…xnwith probabilities p0, p1,…pncan be determined as: • For such a distribution, you can think of expectation as an average value • Measure of central tendency, measure of payoff

  22. Subjective Interpretation Expectation • E.g. Online RPG – monitoring the number of players who gather at a local tavern/inn each evening – collecting intelligence • Table shows the probabilities of no. of players each evening • In this case, what is the expected number of players in the tavern in the evening? • What use is this information?

  23. Subjective Interpretation • Difficult to pin down subjective probabilities to a specific method or number • Fine-tuning or “hacks” can be used

  24. Conditional Probability • When events are not independent, they are “conditional” • E.g. if you find your lawn wet, what is the probability that it rained while you were at work? Is it possible that someone turned on your sprinklers while you were at work? • Outcome of your grass being wet is “conditional” upon whether it rained, or whether someone turned on your sprinkler. • Bayesian analysis

  25. Bayes’ rule • If event A depends on whether event B occurred, we can’t use typical probability calculations P(A|B) • Probability of A occurring given B has occurred: P(A|B) • Probability of B occurring given A has occurred: P(B|A) P(A|B)  P(B|A)

  26. Bayes’ rule • To find the compound probability of both A and B occurring, we say P(A  B) = P(A) P(B|A) • But usually we are interested in the probability of an event given some other event has occurred P(B|A) = P(A  B)/P(A) = P(B) P(A|B) / P(A) • Posterior = likelihood * prior --------------- marginal likelihood

  27. Bayes’ rule – Game examples • Example 1: A melee attack by a wizard character, with additional magical aid • To determine the probability of a melee hit given magical aid P(hit) = 0.9, P(~hit) = 0.1 P(magic|hit) = 0.85 P(magic|~hit) = 0.15 P(hit|magic) = (0.9)(0.85) / [(0.9)(0.85)+(0.1)(0.15)] = 0.765/0.78 = 0.981 Indicating stronger probability of hitting given magical aid

  28. Bayes’ rule – Game examples • Example 2: A 1-on-1 fight between a warrior (fighting ability) and a wizard (magic ability) • To determine the attacking (hit) probability of the warrior given the wizard’s magical ward defense C1: P(A) = 0.8, P(~A) = 0.2 C2: P(D|A) = 0.3 P(D|~A) = 0.7 P(A|D) = (0.8)(0.3) / [(0.8)(0.3)+(0.2)(0.7)] = 0.24/0.38 = 0.632 Indicating weaker warrior attack probability given magic defense from wizard

  29. More Bayesian techniques • Bayesian inference, Bayesian networks for adding uncertainty to decision making (refer to textbook Chapter 13)

More Related