Download presentation
Presentation is loading. Please wait.
Published byRussell White Modified over 9 years ago
1
Lecture 4 1 Minor Games Programming
2
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 Verhoeven j.verhoeven@windesheim.nl
3
A* Practice See 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
4
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
5
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
6
Scripting Languages Scripting 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
7
Problems with Scripting Languages Writing one is not for the faint of heart Require an enormous amount of work You have to write a compiler and executer You have to expose an API to them You will want a nice suite of tools, like a development environment, debugger, etc. There will be learning curve since it’s a brand new language May result in unmaintainable spaghetti code if poorly designed Usually at best 1/10 speed of C/C++, so can drag down performance Existing scripting languages (Python, Ruby, Lua) may not meet your needs, there’s still a learning curve, and will still run very slowly Schumaker
8
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
9
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
10
“Eric the Brave” example The process of decomposing and satisfying goals continues until the entire hierarchy has been traversed. 10
11
Implementation Using the composite design pattern 11
12
The Raven bots utilize the following goals: 12
13
RAVEN: view the goal list of a selected agent 13 Active: in blue Completed: in green Inactive: in black Failed: in red Indenting: how the goals are nested
14
Goal Arbitration How 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
15
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
16
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
17
(Next college) The selection of an adequate weapon is handled with use of FUZZY LOGIC the topic of next week (chapter 10) 17
18
Spin-Offs One great thing about a hierarchical goal- based arbitration design is that extra features are provided with little additional effort from the programmer: Personalities State Memory Command Queuing 18
19
Personalities You can create agents with different personalities by giving them different goals or different weighting factors 19
20
State memory examples Example One — Automatic Resuming of Interrupted Activities 20
21
State memory examples Example Two Negotiating Special Path Obstacles 21
22
State memory examples Example Two Negotiate Door. Run raven and load map: Raven_DM1_With_Doors.map. 22
23
Example of Command Queuing You 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
24
Q 24
25
SIMS * with a Twist The Making Of … 25 *
26
Sims * Example of Goal- Oriented Behavior Use of a Script language Unlimited number of goals and actions In this special edition two main characters: B & K 26
27
Some samples of goals and actions Goals: Eat Sleep Bathroom Actions: Get-Snack Sleep-In-Bed Visit-Bathroom Study-Minor-Gaming Kill-Barbie 27
28
Attributes Goal: NameTo identify a goal ValueThe ranking of a goal (The lower the better) TickValueEach tick of the clock the ranking value is increased with tickvalue Action: NameTo identify an action Goals The goals which ranking values are altered due to this action 28
29
Example of the script: GOAL EAT GOAL 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
30
SIMS* 30
31
SIMS* the engine Main classes: Goal, Action and Character. Character: Goals 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
32
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
33
Homework and Practice 33
34
Robocode 34
35
Robocode setup Start at: http://robocode.sourceforge.net/http://robocode.sourceforge.net/ Download and install: Read Getting Started and some tutorials Run some battles Have fun 35
36
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.