24
Introduction to Game AI © CSSE CITS4242 Game Design and Multi-Media

Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

Introduction to Game AI

© CSSE CITS4242 Game Design and Multi-Media

Page 2: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

Expectations and Reality

• AI is an enormous topic, so don't expect to come away from this unit an expert.

• But you will have learned the skills necessary to create entertaining and challenging AI for the majority of action game genres.

• Furthermore, you will have a sound understanding of the key areas of game AI, providing a solid base for any further learning you undertake.

Page 3: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

Academic AI

• Academic research is split into two camps: strong AI and weak AI. – Strong AI concerns itself with trying to create systems that mimic

human thought processes.– Weak AI (more popular nowadays) with applying AI technologies to

the solution of real-world problems.• However, both of these fields tend to focus on solving a problem

optimally, with less emphasis on hardware or time limitations. – For example, some AI researchers are perfectly happy to leave a

simulation running for hours, days, or even weeks on their 1000-processor Beowolf cluster so long as it has a happy ending they can write a paper about. This of course is an extreme case, but you get my point.

Page 4: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

Game AI

• Game AI programmers, on the other hand, have to work with limited resources.

• The amount of processor cycles and memory available varies from platform to platform. Compromises often have to be made in order to get an acceptable level of performance.

• In addition, successful games — the ones making all the money — do one thing very well: They entertain the player (not to be suboptimal is of least concern).

– After all, most players will quickly become frustrated and despondent with an AI that always gives them a whippin'. To be enjoyable, an AI must put up a good fight but lose more often than win. It must make the player feel clever, sly, cunning, and powerful. It must make the player jump from his seat shouting, "Take that, you little @?%#$!"

Page 5: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

Opponents and Allies - AI

• The Acronym AI is often used to refer to – Enemy AI: Monsters– Friendly AI: AI, Parties – NPCs (Non-Player Characters) – ‘Bots

• AI being “uber” (too deadly, German Word: over)

• ‘Bots are “nerfed” (a nerf is a change t either the rules of the game or the behaviour of the game objects that weakens or reduces power of the object or rule in question)

Page 6: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

The Illusion about Intelligence

• But what is this mysterious thing we call artificial intelligence?

• With regard to game AI, it is often firm of the opinion that if the player believes the agent he's playing against is intelligent, then it is intelligent. It's that simple. Our goal is to design agents that provide the illusion of intelligence, nothing more.

• Because the illusion of intelligence is subjective, sometimes this takes very little effort at all.

• The designers of the AI for Halo, for instance, discovered their playtesters could be fooled into thinking the AI agents were more intelligent simply by increasing the number of hit points required to kill them.

Page 7: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

Playtesting on the AI illusion

• For one test session they allowed the agents to die really easily (low hit points)

– the result was that 36% of the testers thought the AI was too easy and 8% thought the AI were very intelligent.

• For the next test session the agents were made harder to kill (higher hit points).

– After just this small change 0% of the testers thought the AI was too easy and 43% thought the AI was very intelligent!

• This is an astonishing result and clearly shows the importance of playtesting throughout the game development cycle.

Page 8: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

More tips on creating the AI illusion

• It has also been shown that a player's perception of the level of intelligence of a game agent can be considerably enhanced by providing the player with some visual and/or auditory clues as to what the agent is "thinking" about.

• For example, – if the player enters a room and startles an agent, it should act

startled. – If your game is a "stealth-'em-up" like Thief and a game character

hears something suspicious, then it should start to look around and maybe mumble a few words such as "What was that?" or "Is anyone there?"

– Even something simple like making sure that an agent tracks the movement of neighboring agents with its head can contribute significantly to a player's perception of the AI.

Page 9: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

What not to do to ruin your AI illusion

• You must be careful though when designing your AI not to let the cloak of illusion slip, since once it does, the player's belief in the game character will evaporate and the game becomes much less fun to play.

• This will happen if the AI is– seen to act stupidly (running into walls, getting stuck in corners,

not reacting to obvious stimuli) or – is caught "cheating" (seeing through walls, requiring less gold to

build units than the human player, hearing a pin drop at 500 meters)

• You must take great pains to avoid all of these pitfalls

Page 10: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

The non-cheating AI

Page 11: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

Different Levels of Intelligence

• Unit AI: Individual Units need to behave sensibly and autonomously for the player to perceive as a being with intellect.

– Autonomous Agents• Reactive (chase, evade, attach etc)• Goal-driven (defend from dragon, attach dragon, get food …)

• Group AI: communication between units (‘bots) in a group– Team behaviour

• Master AI: control multiple groups, analyse the terrain and make high-level decisions (more useful for RTS games).

Page 12: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

Multi-tiered AI

2-5 times per Second

Every Second

Every 5-15 second

Page 13: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,
Page 14: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

AI for Computer Games

• Script-Based AI

• Finite State Machines

• Searching and Finding Path

• Behaviour Trees

• Fuzzy Logic

• Genetic Algorithms

• Neural Networks

• Others

Page 15: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

Script-Based AI

• The opponent acts according to a predefined script. A script is nothing more than a series of simple actions:

1. Find a suitable base location.2. Establish a base.3. Build building A.4. Build building B.5. …6. Train units.7. Train three footmen.8. Train two archers.9. …10. Attack Player P.11. Repeat from Step 6.

Page 16: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

Examples: scripting with NeoAxis

• The Logic Editor also supports a form of scripting, including a special “Wait” command.

• Coroutines allow scripting directly in languages like C# that support “yield” in enumerators. (As in previous lectures.)

• Alternatively a separate scripting language like Lua can be used.

– Reference LuaInterface.dll in the solution browser– Register C# methods as Lua functions.– Load and run scripts at runtime with Lua calling C# and C#

calling Lua.

Page 17: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

Finite State Machines

• In FSMs, the AI ‘bots can be in one of several states.

• There is also a set of rules to govern how to move from one state to another.

• Comparing to script-based AI, FSMs are much more robust. Scripted AI will stop working as intended if the situation occurred isn’t in the script.

– Stationary (guards, spies)– Move

• Follow paths• Free Roaming• Chase

Page 18: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

Behaviour Trees

• Behaviour Trees are a recent and increasingly popular way of describing behaviour.

• They naturally generalize scripts and hierachical FSMs plus they fit well with goal directed behaviour like path finding.

• They originated in software engineering research about ten years ago, at the Software Quality Institute at Griffith University.

• They are now used in many mainstream games such as Halo 2 and 3.

Page 19: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

Practical Path Finding

Points of visibility Navigation Graph (left: Coarse, right: Fine)

Page 20: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

Fuzzy Logic

• Fuzzy logic uses approximate reasoning to sort data into vaguely defined set.

• In Fuzzy logic, a question of “are you hungry”, can be answered as 30% to the “hungry” set and 70% to the “not hungry” set. More interesting decisions can be made based on this:

– If peckish, have a salad– If somewhat hungry, have some spaghetti– If starving, have the roast beef

• In comparison, Boolean logic, can only be answered with “Yes”, or “No”.

Page 21: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

Genetic Algorithm

• GA builds on the concept of evolution, concepts such as Natural Selection and survival of the fittest, inheritance and mutation are used.

– Start with a number of random solutions (each solution is an individual)

– For each iteration of the algorithm (generation)• Pick a number of good solutions (parents)• Breed them together using cross-over operation (take genes from

parents)• Form new solutions (children)

• GA can be used to solve problems with large search space or learn the strategy used by a player and figure out how to beat them.

Page 22: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

Artificial Neural Networks

• Similar to GA, ANN has its roots in biology. It tries to mimic the way interconnected neurons in a brain operates.

• ANN can extact meaning from complex and imprecise data. They can be used to identify patterns and trends that are too complex to be noticed by either humans or other AI methods.

• They learn from examples, but cannot be programmed to perform specific task. A trained network can be used to draw good conclusions from similar cases.

– Good news is: they are fast at runtime– Bad news is: they are hard to train, tweak and change.

Page 23: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

Others

• Natural Language Processing and Natural Language Generation

• Speech recognition and processing

• Still not widely adopted by the Gaming Community due to its sheer complexity and the constraints placed by real-time games

Page 24: Introduction to Game AI · • “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14) • Advanced 3D Game Programming All in One”,

References

• "Programming Game AI by Example", by Mat Buckland ISBN 1-55622-078-2 (Two copies in the UWA library.)

• “Programming an RTS Game with Direct3D”, by Carl Granberg, Thomson, ISBN 1-58450-498-6 (Chapter 14)

• Advanced 3D Game Programming All in One”, by Kenneth C Finney, Thomson, ISBN 1-900-733-3, Part II (Chap 5-9)

• AI-Junkie: www.ai-junkie.com