gaming with artificial intelligency

27
Seminar On Gaming With Artificial Intelligence Gohil Hardik L 100850131004 Goswami Hardik K 100850131007 HJD Institute Of Technical Education And Research

Upload: pratikblackunicorn

Post on 05-Dec-2014

355 views

Category:

Education


0 download

DESCRIPTION

-By Geniushkg

TRANSCRIPT

Page 1: Gaming with artificial intelligency

Seminar OnGaming With Artificial

Intelligence

Gohil Hardik L 100850131004 Goswami Hardik K 100850131007

HJD Institute Of Technical Education And Research

Page 2: Gaming with artificial intelligency

Outline

• Abstract• History• Finite State Maschines• Fuzzy logic• AI Example • Bibliography

Page 3: Gaming with artificial intelligency

Abstract

A brief introduction on Artificial intellegency used in compter gaming i.e basic concept of how a computer player should, in its behaviour and strategies of playing, be indistinguishable from a real player on the other side of an Internet connection.

Page 4: Gaming with artificial intelligency

History• Video game AI is rooted in long-forgotten single-player games, which first

come into view in the 1970s from “pursuit”• World War I flying ace, shooting down enemy planes.• Atari's "Qwak" was another opener that saw basic AI at work• Finite State Machine AI's• Pacman• Real Time Strategy AI’s• Dune II’s AI activity than any average platformer or side-scrolling shooter

that came before. The enemy determines where to attack first, on top of setting certain priorities in its behaviour to ensure for realistic battle tactics

Page 5: Gaming with artificial intelligency

Finite State Machines (FSM)• FSM is one of the simplest and most basic AI models.• You may have seen FSM in your Computer

Architecture and your Formal Languages classes.• It is useful, for example, in first-person shooter games.• Basically, FSM consists of

– States– State transitions

• An object (a non-player character) is in one of the states.

• When certain conditions are met, the object changes to another state.

Page 6: Gaming with artificial intelligency

FSM Basics

• A FSM consists of the following 4 components:– States which define behavior and may produce actions – State transitions which are movement from one state to

another – Rules or conditions which must be met to allow a state

transition – Input events which are either externally or internally

generated, which may possibly trigger rules and lead to state transitions

Page 7: Gaming with artificial intelligency

Example of States• For example, Quake2 uses 9 states for the monsters:

– Standing, walking, running, dodging, attacking, melee, seeing the enemy, idle and searching

• In other words, at any one time, a monster can be in one of the above 9 states.

• Each state has its own distinct behavior and actions. For example, a monster in the running state would behave differently from a monster in the standing state.

• The behavior and actions for each state has to be defined by the programmer.

Page 8: Gaming with artificial intelligency

State Transitions• A finite state machine must have:

– an initial state which provides a starting point, and – a current state which remembers the product of the last

state transition.• An input event act as a trigger• This causes an evaluation of the rules that govern the

transitions from the current state to other states. A state change then occurs according to the rules.

• The best way to visualize a FSM is to think of it as a directed graph of the states.

Page 9: Gaming with artificial intelligency

Example of State Transitions

Idle Attack

Die

Melee

Dodge

Search

See enemy

Close range

Enemy Fires

Lose Sight

Time Out

Start state

Get ShotGet Shot

Get Shot

See enemy

Close range

Here, a monster starts in the Idle state.In the Idle state, it just walks around.At every iteration of the game loop,check if enemy is in sight.If yes, transition to the attack state.In the attack state, chase after the enemy and fire at the enemy.In the Idle state,if the monster gets the input “Get Shot”,it will transition to the Die state.

state

state transition

input event

Page 10: Gaming with artificial intelligency

Implementation(psuedocode)class Monster { int state; // 0: Idle 1: Attack 2: Melee 3: Dodge 4: Search 5: Die Monster(); void Iterate(); void HandleInput(int eventID); void Shoot(); void Melee(); void Dodge(); void Chase(); void FindEnemy();};

Monster::Monster() : state(0) { } // initialize to start state

void Monster::Iterate() { // called on every game cycle if (state==0) { Move(rand()); // move in random direction } else if (state==1) { Chase(); Shoot(); } else if (state==2) { Melee(); } else if (state==3) { Dodge(); } else if (state==4) { FindEnemy(); } else if (state==5) { }}

void Monster::HandleInput(int eventID) { if (eventID==0) { // monster got shot state = 5; } else if (eventID==1) { // see enemy if ((state==0) || (state==4)) { state = 1; } } …}

Page 11: Gaming with artificial intelligency

FSM for ghosts in packman

The ghosts have four behaviours: •1. Wander the maze •2. Chase Pac-man •3. Run away from Pac-man •4. Return to the central base

Page 12: Gaming with artificial intelligency
Page 13: Gaming with artificial intelligency

Disadvantages of FSM• May be too predictable• Large FSM with many states and transitions can be difficult to

manage and maintain. • State oscillation. States may be too rigid. Conditions are too

crisp. – For example, there are two states: Flee and Idle. – The condition for being in the Flee state is to be within a distance 5.0

from the enemy. The condition for being in the Idle state is to be greater than 5.0 from the enemy.

– Say, the object is 4.9 from the enemy. It is in Flee state, so it runs away. Now it is 5.1, so it is in Idle state. It randomly moves around, and goes to 4.9 and gets into the Flee state again etc.

Page 14: Gaming with artificial intelligency

Fuzzy Logic• Historical Origins:

– Derived from fuzzy set theory– Developed by Prof. Lotfi Zadeh at the University of California, Berkeley

in 1965• Fuzzy set theory is in contrast to traditional (“crisp”) set

theory– Traditional set theory: An object either belongs to a set or not.– Fuzzy set theory: An object can “partially belong” to a set– Example: To classify people into two sets: Tall and Short– In traditional set theory, an arbitrary cut-off is set at, say, 6 feet. Any

person taller than 6 feet is in the Tall set. Any person less than or equal to 6 feet is in the Short set.

– In fuzzy set theory, for example, a person taller than 6’2” is considered to be 100% in the Tall set, a person at 5’11” is considered to have 20% membership in the Tall set etc.

• Fuzzy logic often mimics real life.• Can be used to improve the rules used in FSM.

Page 15: Gaming with artificial intelligency

Fuzzy Set Membership

• Traditional Set Theory: An object is either a member of a set or not a member of a set.

• Fuzzy Set Theory: An object is either in a set, not in a set, or partially in a set.– This is denoted by a number from 0.0 to 1.0.– Membership number m of Object A in Set S:

• m = 0.0 means that Object A is not in Set S.• 0.0 < m < 1.0 means that Object A is partially in Set S, for example

m = 0.2 means that Object A is 20% in Set S, a rather weak membership.

• m = 1.0 means that Object A is completely in Set S.

Page 16: Gaming with artificial intelligency

Fuzzy Logic Operations• NOT:

– If Fuzzy Statement A is m true, then the statement “Not A” is (1.0 – m) true (where m is a number between 0.0 and 1.0 inclusive).

– Equivalent Set Theory operation: If an object A has m membership in Fuzzy Set S, then it must have membership (1.0 – m) in Fuzzy Set Not-S.

• AND:– If Fuzzy Statement A is m true, and Fuzzy Statement B is n true, then

the Fuzzy Statement “A and B” is k true, where k = min(m,n). (Here, m, n and k are numbers between 0.0 and 1.0 inclusive.)

• OR:– If Fuzzy Statement A is m true, and Fuzzy Statement B is n true, then

the Fuzzy Statement “A or B” is k true, where k = max(m,n). (Here, m, n and k are numbers between 0.0 and 1.0 inclusive.)

Page 17: Gaming with artificial intelligency

Making a Decision• We can simply decide the arbitrary cut-off to be 0.5. If a condition is at

least 0.5 true, then perform the action.– In the preceding example, the condition is only 0.3 true, so the decision is to

not shoot.• Or, we can make a random decision with the probability equal to the

value of the condition.– In the preceding example, attack with the probability 0.3.

• Most of the time, there are many rules.– For example:

• Rule 1: If Self is Tall and Enemy is Short, then Attack.• Rule 2: If Self is Big and Enemy is Green, then Attack.• Rule 3: If Self’s Power is greater than 10, and Self’s Health is greater than 5, then

Attack.– In this case, there are a few options to make a decision whether to attack or

not.• Option 1: Take the majority decision.

– For the example above: If at least two of the above conditions are at least 0.5, then Attack. Otherwise don’t attack.

• Option 2: Take the average.– For the example above: If condition 1 is 0.6, condition 2 is 0.6, and condition 3 is 0.0,

then the average is 0.4. 0.4 is less than 0.5, so the decision is not to attack.• Option 3: Make a random decision with the probability equal to the average.

Page 18: Gaming with artificial intelligency

Rules• Crisp rule:

– Example: “If Self is Tall and Enemy is Short, then Attack.”– The Condition of a Rule:

• The condition for this rule is: “If Self is Tall and Enemy is Short”• To check the condition is easy, just check self for membership in the set

Tall, and enemy for membership in the set Short.• Suppose that Self is not Tall, then the decision is to not attack.

• Fuzzy rule:– Example: “If Self is Tall and Enemy is Short, then Attack.”– The condition of the rule once again is: “If Self is Tall and Enemy is

Short”– Suppose that Self is 0.3 Tall, and Enemy is 0.6 Short, then this

condition is 0.3 True.– So, should we attack?

Page 19: Gaming with artificial intelligency

Predicting the Player’s Move

• Real players will notice one another’s behavior and start to adapt. For example, if Player A notices that Player B always likes to move to a certain spot, Player A will ambush Player B at that place.

• We want to give Non-Player Characters (NPC) some Artificial Intelligence to do that.

• One simple method: Build a table.

Page 20: Gaming with artificial intelligency

Predicting a Player’s Move• Example: In a fighting game,

predict a player’s third move given his/her first and second move.– Suppose there are three possible

moves: Punch, Low Kick and High Kick.

– Build a table where the first column represents the first move and the second column represents the third move of the player.

– The third column of the table is split into 3 columns, one for each possible move, and each entry represents the count of the third move of the player given the first two moves.

3rd move

1st move 2nd move Punch Low Kick

High Kick

Punch Punch 10 15 2

Punch Low Kick 1 9 13

Punch High Kick 8 0 1

Low Kick Punch 2 3 1

Low Kick Low Kick 8 9 15

Low Kick High Kick 23 1 13

High Kick Punch 4 5 9

High Kick Low Kick 1 2 1

High Kick High Kick 0 8 9

Page 21: Gaming with artificial intelligency

Predicting a Player’s Move• How to build the table

– The first two columns must contain all possible combinations of first and second moves

– Every time a player does a Punch – High Kick – High Kick combination, for example, increment the number in the highlighted entry.

– In this example, the Punch – High Kick – High Kick combination has been seen 6 times.

3rd move

1st move 2nd move Punch Low Kick

High Kick

Punch Punch 10 15 2

Punch Low Kick 1 9 13

Punch High Kick 8 0 6

Low Kick Punch 2 3 1

Low Kick Low Kick 8 9 15

Low Kick High Kick 23 1 13

High Kick Punch 4 5 9

High Kick Low Kick 1 2 1

High Kick High Kick 0 8 9

Page 22: Gaming with artificial intelligency

Predicting a Player’s Move• How to predict the player’s third

move.– After the player has made the first

and second moves, look up the row in the table, and pick the entry that has the largest number.

– For example, suppose that the player has done a Low Kick followed by a High Kick.

– We look at the highlighted row, and find that the entry with the largest number is Punch (23).

– Therefore, we predict that the player will punch, and the NPC anticipates a punch and tries to block the punch.

– Then, when the player actually makes a move, we increment the appropriate number in the row.

3rd move

1st move 2nd move Punch Low Kick

High Kick

Punch Punch 10 15 2

Punch Low Kick 1 9 13

Punch High Kick 8 0 1

Low Kick Punch 2 3 1

Low Kick Low Kick 8 9 15

Low Kick High Kick 23 1 13

High Kick Punch 4 5 9

High Kick Low Kick 1 2 1

High Kick High Kick 0 8 9

Page 23: Gaming with artificial intelligency

Probability• The preceding application is an example of using probability

to predict the player’s next move, and hence act in anticipation of it.

• But, how to calculate probability?• Probability is calculated based on previous observation.

– Example: Suppose that a player has made 100 moves, and out of these 100 moves, 30 moves were punches. In this case the probability of the next move being a punch is P(punch) = 0.30

• However, we need to know how to interpret observations in order to assign probabilities correctly.

Page 24: Gaming with artificial intelligency

AI Examples Counterstrike

• Most us Have used Commands in Cs Like : follow me,regroup team,taking fire need assistance,etc

• Node Graph And Navigation meshes are the base on which above commands are executed efficently.

Page 25: Gaming with artificial intelligency

Navigation Mesh:Follow Me The floor is divided in Mesh of matricular squares

Every player have its own identityAnd on any position represent a square( Co-ordinate on bsp)Follow me1)Every player is commanded to reach the square on which commander is present2)To follow foot steps parallely, similar to same rate of movement in context of time.

Page 26: Gaming with artificial intelligency

Bibliography

• https://developer.valvesoftware.com• http://www.codeproject.com• http://en.wikipedia.org• http://research.ncl.ac.uk• http://www.cs.sjsu.edu

Page 27: Gaming with artificial intelligency

Any Question’s ?

Thanking You