• Tidak ada hasil yang ditemukan

Index of /Kuliah2016-2017/KecerdasanBuatanUntukGame

N/A
N/A
Protected

Academic year: 2017

Membagikan "Index of /Kuliah2016-2017/KecerdasanBuatanUntukGame"

Copied!
24
0
0

Teks penuh

(1)

Artificial Intelligence in

Game Design

(2)

Finite State Machines

Non-player character in one of several possible

states

– Must be some initial state

That state controls actions taken by the NPC

Transitions to other states caused by

internal/external stimuli

Current State

Actions in current state

Another State

Stimuli

Another State

(3)

“Guardbot” Example

Patrol

Move back and forth in front of door

Energy at 100%

Chase

Move towards player Energy = Energy - 1 Player visible

Return

Move towards door Energy = Energy - 1 At door

Player not visible

Energy below 50%

(4)
(5)

Finite State Machines

Each state can be reflex agent

Example: “fight” state

Fight

Player swings  Raise shield Player waits  Swing sword

Player moves  Move towards player

(6)

Designing FSMs

• What different things does NPC do?

– Types of action taken

• Chase, wander, etc.

– Steps in some process

• Get food from fridge  Cook food  eat food

– Can include “terminal” state

• Object destroyed and deallocated

Return

Move towards door Energy = Energy - 1 Energy == 0

(7)

Implementing FSMs

Can treat each state like a C++/Java class

– Possibly derived from some base “State” class

Typical methods in class:

Enter()

Executed once when state entered

Example: entering “Fight” state causes NPC to select weapon

Exit()

Executed before go to another state

(8)

Implementing FSMs

Typical methods in class:

Update()

Executed by game engine each frame while NPC in this state

Example: reflex actions taken by NPC in “Fight” state

int CheckTransitions()

• Executed by game engine each frame while NPC in this state

• Returns ID of the next state to enter based on

(9)

Implementing FSMs

class Chase extends State {

int stateNumber = 1; // Patrol = 0, Return = 2 public:

void Enter() {say(“intruder alert”);}

void Exit() {say(“intruder has escaped”);} void Update() {

moveTowards(player.getLocation); if (rand() < 0.3) say (“exterminate”); energyLevel--;

}

int checkTransitions() {

if (energyLevel <= distance(location(door.getLocation)) || distance(location(door.getLocation)) > 10) return 2; else return 1;

(10)

Emotional FSMs

• States represent emotions for character

• Actions express emotion

• Stimuli change emotional state

Confident Angry

Frightened

Player HP < 10

Player hit > 5 HP

My HP < 10 Heavy hit

by me

(11)

Emotional FSMs

• Can combine with action states appropriate to emotion

– Looks more realistic if orc displays fear before running

Confident Angry

Frightened

Player HP < 10

Player hit > 5 HP

My HP < 10 Heavy hit

by me

Player hit > 10 HP

My HP < 5

(12)

Emotional FSMs and Personalities

• Can “tweak” parameters for different NPCs

• Differences must be large enough to be noticeable

Confident Angry

Frightened

Player HP < 5

Player hit > 1 HP

My HP < 5 Heavy hit

by me

Player hit > 20 HP

Orc with anger

(13)

Emotional FSMs

NPC must clearly express emotional state

– Facial expression (difficult in low resolution)

– Body language

• Posture, motion, etc.

– Sound (speakers must be on)

• Spoken phrases

• Sounds (growl, etc.)

– Abilities

(14)

Emotional FSMs

Confident

• Smiles

• Shouts insult

• Stands ground

Angry

• Growls

• Frowns

• Faster attack

• Less accurate

Fearful

Backs away

• Grimaces

(15)

Timeouts in FSMs

Problem: Abrupt transitions in FSMs

– As player approaches, NPC jumps back and forth

between “Walk around” and “Run” states

Player < 5 feet away

(16)

Timeouts in FSMs

• Solution: State “timeouts”

– Continue high-emotion states for fixed amount of time after stimulus gone

• Keep running for time even after at safe distance

• Supported by evidence from biology

(17)

Timeouts in FSMs

class Run extends State { int timeout;

void Update() {

Flee(player.getLocation());

if (distance(location, player.getLocation()) < 5)

timeout = 10; // run for 10 frames even after escape) }

int CheckTransitions() { if (timeout > 0) {

timeout--;

return 1; // stay in run state }

(18)

Extended “

Guardbot

” Example

Patrol

Move back and forth in front of door

Energy at 100%

Player visible

Escaped

Move towards door Energy = Energy - 1 At door Player not visible Energy below 50% Return

(19)

FSM Issues

Problems with Finite State Machines:

Complexity

– Potentially hundreds of states

• Design difficult

• Debugging impossible

Duplication

– Many blocks of states similar

• Example: Return state also needs “Turn”, “Move”, and “Dodge”

– Many transitions similar

(20)

Hierarchical State Machines

Single high-level state contains entire low-level FSM

– Need initial state that high-level passes control to

– Need final states that correspond to transitions from high-level state Chase Turning Forward Player to side Dodge Obstacle in front Start Player to side Player in front Obstacle not in front

(21)

Hierarchical State Machines

Usually implemented as stack

– Push low-level state on stack when enter

– Pop and move to next state when finished

(22)

Exiting Low-level States

• “Interrupts” may cause exit before task is completed

– Example: Caution flag interrupts passing

• All states on stack may have interrupt conditions

– Check all at each frame

– Better than having same transition for all states

Turning

Chasing

Guarding Door

Forward

Player in front

Return

Go to HQ

(23)

Exiting Low-level States

Can store current low level state and return if

necessary once exception handled

Build Farm

Clear land Build barn Plant crops

Dam break

Fix Dam

(24)

Weaknesses of FSMs

Abrupt transitions between emotional states

– Confident  Terrified not a realistic transition

– May need more intermediate states

Confident  Worried  Terrified

Multiple next states may be indicated by stimuli

– Must make sure all are mutually exclusive

Chasing

Attack

Within 1 unit

Return

Referensi

Dokumen terkait

PEMERINTAH KOTA PALU UNIT LAYANAN PENGADAAN POKJA PENGADAAN JASA

Dem ikian pengum um an ini kam i sam paikan, apabila ada pesert a yang berkeberat an at as pengum um an ini dapat m enyam paikan sanggahan secara t ert ulis at as

Usaha Jasa Konsfruksi (IUJK) dan Sertifikat Badan Vriiu (SBU) yangmaslh berlaku.. ?id|,q .Tul Lingkungan / Subbidang rnsratasi pengolahan Limbah

Pada hari Rabu Tanggal Dua Puluh Tiga Bulan Juni Tahun Dua Ribu Sebelas, kami yang bertanda tangan di bawah ini Pokja Pengadaan Barang, Pekerjaaan Konstruksi dan Jasa

NO NAMA SATUAN KERJA NAMA KEGIATAN LOKASI SUMBER DANA KODE DIPA JENIS PENGADAAN PAGU (Rupiah)...

Jenderal Gatot

 Menyampaikan terima kasih dan mengingatkan agar mahasiswa mempelajari keseluruhan modul sebagai bahan UAS. -

Untuk membaca secara detail pembahasan mengenai Pengertian budaya politik , Ciri-Ciri Budaya Politik , Bagian-Bagian Budaya Politik , Macam-Macam Budaya Politik dan Budaya