lecture 4 1 minor games programming. artificial intelligence for games today’s theory &...

36
Artificial Intelligence for Games Lecture 4 1 Minor Games Programming

Upload: russell-white

Post on 16-Jan-2016

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

Artificial Intelligence for

GamesLecture 4

1

Minor Games Programming

Page 2: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Jan [email protected]

Page 3: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Page 4: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Page 5: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Page 6: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Page 7: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Page 8: Lecture 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

(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

Page 9: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Page 10: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

“Eric the Brave” example

The process of decomposing and satisfying goals continues until the entire hierarchy has been traversed.

10

Page 11: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

ImplementationUsing the composite design pattern

11

Page 12: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

The Raven bots utilize the following goals:

12

Page 13: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Page 14: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Page 15: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Page 16: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Page 17: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

(Next college)

The selection of an adequate weapon is handled with use of

FUZZY LOGIC the topic of next week (chapter 10)

17

Page 18: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Page 19: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

Personalities

You can create agents with different personalities by giving them different goals or different weighting factors

19

Page 20: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

State memory examples

Example One — Automatic Resuming of Interrupted Activities

20

Page 21: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

State memory examples

Example Two Negotiating

Special Path Obstacles

21

Page 22: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

State memory examples

Example TwoNegotiate

Door.

Run raven and load map:

Raven_DM1_With_Doors.map.

22DEMO TIM

E

Page 23: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Page 24: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

Q

24

Page 25: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

SIMS* with a TwistThe Making Of …

25

*

Page 26: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Page 27: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

Some samples of goals and actions

Goals: Eat Sleep Bathroom

Actions: Get-Snack Sleep-In-Bed Visit-Bathroom Study-Minor-Gaming Kill-Barbie

27

Page 28: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Page 29: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Page 30: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

SIMS*

DEMO TIME

See: Project WinSimCS (don’t expect too much graphical excitement)

30

Page 31: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Page 32: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Page 33: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

Homework and Practice

33

Page 34: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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

Page 35: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

Robocode setupStart at: http://robocode.sourceforge.net/

Download and install:

Read Getting Started and some tutorials

Run some battles

Have fun35

Page 36: Lecture 4 1 Minor Games Programming. Artificial Intelligence for Games Today’s Theory & Demo’s:  Previous Practice A* (A Real Good Algorithm)  Scripting

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