lecture 4 1 minor games programming. artificial intelligence for games today’s theory &...
TRANSCRIPT
Artificial Intelligence for
GamesLecture 4
1
Minor Games Programming
Artificial Intelligence for Games
Today’s Theory & Demo’s:
Previous Practice A* (A Real Good Algorithm) Scripting Goal-Driven Behavior SIMS with a Twist Homework and Next Practice: Robocode
2
A* PracticeSee demo Cannibals and Missionaries
A generic A* implementation
How to define your nodes and edges? In memory? Runtime build?
How to define an heuristic function?
3
Scripting
Chapter 6 in your study book
Just study pages 249 thru 255
The rest of the chapter (about Lua Scripting Language) isn’t exam stuff, so you can skip the skript
4
What do we want?Each custom behavior should be able to
function in isolation from other custom behaviors, so it is easier to test and manage
We want to be able to tweak as easily as possible
Behavior should be determined at run-time, rather than compile-time, for the above reason
Behavior should be treated as “data”, rather than code, and be managed accordingly
Schumaker
Scripting LanguagesScripting languages are programming
language other than the one actually used to program your game, and are used to write game behavior through an API
You pass the scripting language through tools that compile the language into a format that can be loaded on the fly and executed
Schumaker
Problems with Scripting Languages
Writing one is not for the faint of heartRequire an enormous amount of workYou have to write a compiler and executerYou have to expose an API to themYou will want a nice suite of tools, like a
development environment, debugger, etc.There will be learning curve since it’s a brand
new languageMay result in unmaintainable spaghetti code if
poorly designedUsually at best 1/10 speed of C/C++, so can
drag down performanceExisting scripting languages (Python, Ruby,
Lua) may not meet your needs, there’s still a learning curve, and will still run very slowly
Schumaker
Goal-Driven Behavior
(see study book: chapter 9)
8
Goal-Driven Agent Behavior Implementation Goal Arbitration Spin-offs
DON’T STUDY CODE EXAMPLES IN THIS CHAPTER … unless you are a Raven fan
Goal-Driven Agent Behavior
Instead of states, an agent’s behavior is defined as a collection of hierarchical goals.
Goals are: Atomic (a single task, behavior, action) Composite (comprised of several subgoals)
9
“Eric the Brave” example
The process of decomposing and satisfying goals continues until the entire hierarchy has been traversed.
10
ImplementationUsing the composite design pattern
11
The Raven bots utilize the following goals:
12
RAVEN: view the goal list of a selected agent
13
Active: in blueCompleted: in green
Inactive: in black
Failed: in red
Indenting: how the goals are nested
Goal ArbitrationHow do bots select between strategy-level
goals?This is accomplished by the composite
goal Goal_Think, which each bot owns a persistent instance of, forming the root of its goal hierarchy. Goal_Think's function is to arbitrate between available strategies, choosing the most appropriate to be pursued
14
Six strategy-level goals
Explore: An agent picks an arbitrary point in its environment and plans and follows a path to that point.
Get Health: An agent finds the least cost path to an instance of a health item and follows the path to that item.
Get Weapon (Rocket Launcher): An agent finds the least cost path to an instance of a rocket launcher and follows the path to it.
15
Six strategy-level goals
Get Weapon (Shotgun): An agent finds the least cost path to an instance of a shotgun and follows the path to it.
Get Weapon (Railgun): An agent finds the least cost path to an instance of a railgun and follows the path to it.
Attack Target: An agent determines a strategy for attacking its current target.
16
(Next college)
The selection of an adequate weapon is handled with use of
FUZZY LOGIC the topic of next week (chapter 10)
17
Spin-OffsOne great thing about a hierarchical goal-
based arbitration design is that extra features are provided with little additional effort from the programmer:
PersonalitiesState MemoryCommand Queuing
18
Personalities
You can create agents with different personalities by giving them different goals or different weighting factors
19
State memory examples
Example One — Automatic Resuming of Interrupted Activities
20
State memory examples
Example Two Negotiating
Special Path Obstacles
21
State memory examples
Example TwoNegotiate
Door.
Run raven and load map:
Raven_DM1_With_Doors.map.
22DEMO TIM
E
Example of Command QueuingYou can observe command queuing in action in
Raven. You can queue multiple MoveToPosition goals by
holding down the "Q" key while clicking on the map.
If you release the "Q" key and right-click on the map again, the queue is cleared and replaced with the single new goal. (This would be just as easy to implement with any goal of your choosing though, because the queuing takes care of itself).
23
DEMO TIME
Q
24
SIMS* with a TwistThe Making Of …
25
*
Sims *Example of Goal-
Oriented BehaviorUse of a Script
language
Unlimited number of goals and actions
In this special edition two main characters: B & K
26
Some samples of goals and actions
Goals: Eat Sleep Bathroom
Actions: Get-Snack Sleep-In-Bed Visit-Bathroom Study-Minor-Gaming Kill-Barbie
27
AttributesGoal:
Name To identify a goal Value The ranking of a goal (The lower the
better) TickValue Each tick of the clock the ranking
value is increased with tickvalue
Action: Name To identify an action Goals<Goal> The goals which ranking values
are altered due to this action
28
Example of the script:
GOAL EATGOAL BATHROOM
ACTION GET_SNACK EAT(-3) BATHROOM(2)ACTION VISIT_BATHROOM BATHROOM(-8)
SIM BARBIE EAT(8,2) BATHROOM(4,5)SIM KEN EAT(12,3)
29
SIMS*
DEMO TIME
See: Project WinSimCS (don’t expect too much graphical excitement)
30
SIMS* the engineMain classes: Goal, Action and Character.
Character: Goals<Goal> the goals he/she wants to
fulfill
Execute(action) change the value of all involved goals
ChooseAction(Actions) choose the one action from all actions in the game with the best result for the character
31
How to choose the action?
By calculating for each action of a characters the amount of discontentment.
The action with the lowest discontentment (also called energy) is chosen
Follow the calculations on your school board ….
32
Homework and Practice
33
Robocode
Robocode is a programming game, where the goal is to develop a robot battle tank to battle against other tanks in Java.
The robot battles are running in real-time
and on-screen.
DEMO TIME34
Robocode setupStart at: http://robocode.sourceforge.net/
Download and install:
Read Getting Started and some tutorials
Run some battles
Have fun35
Homework Study this presentation Read Chapter 6 Scripting (selected pages) Read Chapter 9 Goal-Driven Behavior
Practice preparation (homework) Install Robocode on your laptop Run some battles with the sample robot tanks Learn to program in Java ;-)
Practice You will be asked to develop your own robot tank
given some requirements
36