Ai in games

28

Click here to load reader

Transcript of Ai in games

Page 1: Ai in games

Neural Networks in GamesRawan Al-Samman Noor Alhuda Espil

Page 2: Ai in games

Why Neural Network ??

Simplifying the games code (complex state machines ,rules-based systems)

offer the potential for the game's AI to adapt as the game is played

1

2

Page 3: Ai in games

Cool Ways to Use NN in Games

Threat Assessment (strategy)

Inputs: types of units and their movement

Output: Aerial threat, a ground threat, both an aerial and ground threat, or no threat.

1

Page 4: Ai in games

Cool Ways to Use NN in Games

Attack or Flee

Used for mobsInputs: class, group size, level, rangeDecision making process: that is,

whether the creature will attack, evade, or wander, depending on whether or not there's an enemy (a player) in the creature's proximity.

2

Page 5: Ai in games

Cool Ways to Use NN in Games

Anticipation

Computer tell what the player is going to do based on past attacks (low kick, low kick, high kick, punch)

Inputs: a few previous attacksOutputs: next predicted attackComputer can then decide to block,

move, punch, etc

3

Page 6: Ai in games

Cool Ways to Use NN in Games

Control:

robotics applications. handle the flight controls for a space

ship or an aircraft. racing games.

4

Page 7: Ai in games

Pong

One of the first video games ever made.Developed by Atari Company. Based on NeuroEvolution of Augmenting Topologies (NEAT) which is the artificial evolution of neural networks using Genetic Algorithm.

Page 8: Ai in games

Genetic Algorithm What is Genetic Algorithm??

adaptive heuristic search algorithm based on the evolutionary ideas of natural selection and genetics.

Why Genetic Algorithm?? do not break easily even if the inputs changed slightly. in searching a large state-space or n-dimensional

surface, it may offer significant benefits over more typical search of optimization techniques.

Page 9: Ai in games

Genetic Algorithm

Population

Ranking by fitness

Mate selection “selection probability is proportional to fitness”

Crossover “exploit

goodness of parent”

Mutation “explore

unknown”

Best Solution

Page 10: Ai in games

NEAT Algorithm

It combines the usual search for appropriate network weights with Complexity of the network structure.

Has advantages:1. historical marking.2. Specification.3. Complexification.

Page 11: Ai in games

NEAT Algorithm

Genetic Encoding

Page 12: Ai in games

NEAT Algorithm

Topologies innovation:

Page 13: Ai in games

NEAT Algorithm

Connection Weight Mutation:

A random number is added or subtracted to the current weight.

the number can be chosen from uniform, Gaussian or the distributions.

Page 14: Ai in games

NEAT Algorithm Matching up genomes for different network topologies using innovation number:

Page 15: Ai in games

NEAT Algorithm

Speciation in Neat:in order to let survive useful topological innovation it have to be protected.NEAT solve this problem with specification:• Similar networks are clustered.• Competition and mating is restricted with the same

space.• Fitness sharing prevent from a single species taking

over the hole population.

Page 16: Ai in games

NEAT Algorithm

Page 17: Ai in games

NEAT Algorithm Complexification:NEAT begins with simple networks with no hidden nodes differing only in their initial random weights. NEAT :

searches through a minimal number of weight dimensions.

reducing the number of generations necessary to find a solution

ensuring that networks become no more complex than necessary.

In other words, NEAT searches for the optimal topology by incrementally complexifying existing structure

Page 18: Ai in games

NEAT Algorithm in Pong This game uses NEAT algorithm to control the

right paddle. The NEAT algorithm is given 5 normalized

inputs: • The center of the paddle (Y value).• the center of the ball (2 values).• the motion vector of the ball (2values).

The NEAT algorithm gives 1 output that is the movement direction and velocity of the paddle.

6 trial runs were used to test several different fitness functions.

Page 19: Ai in games

Pong “Evolution”

Trail 1:

After 50 generations:It had not learned to follow the ball.It does not anticipate, but reacts to the changes in the ball's positionoften misses balls with shallow angles.

Page 20: Ai in games

Pong “Evolution”

Trail 2:

The controller behaves similarly to that of Trial 1.After a few generations:the paddle would begin to shake at the edges of the screen.after generation 12, simulations take much longer to complete. For these reason, this trial was cut short.

Page 21: Ai in games

Pong “Evolution”

Trail 3:

The controller behaves similarly to the one evolved in Trial 1 .until generation 15 :stops ball tracking, lying in wait until the ball is near enough to be hit by the paddle.at generation 17:becomes entirely unresponsive to the ball, and shakes in one of the corners indefinitely.

Page 22: Ai in games

Pong “Evolution”

Trail 4:

The controller is able to predict the ball movement more than previous trials. After 25 generations: began moving from one edge to the other before the ball hit the wall. 2 hidden nodes. 58.3% hit rate

Page 23: Ai in games

Pong “Evolution”

Trail 5: No new Fitness function, the size of the ball and

paddles is reduced signicantly. This trial behaved similarly to those before it. it continued to exhibit the behavior, but to much less

effect than before. It demonstrated more of Trial 3's behavior around

generation 25. it would still miss the ball more often than not.

Page 24: Ai in games

Pong “Evolution”

Trail 6:

After 25 generations: unable to find the ball. It was able to predict where the ball was going to go.constant shaking, especially near the edges. generation 22:had a perfect hit percentage.

Page 25: Ai in games

Possible Remedies

To solve the problems appeared in the previous trail:Warning input used to let the paddle know when the ball is imminently close.Reducing the size of the ball and paddles would reduce the advantage of staying on one of the edges.Increasing the score to win would make the

change in fitness more gradual as the controllers got better.

Page 26: Ai in games

Conclusion

This study has applied NN with GA for thePong Game.

Some problems has appeared but as we mentioned above it can be solved.

The main conclusion is that NEAT is a powerful method for artificially evolving neural networks.

NEAT Algorithm can be used in many application like games.

Page 27: Ai in games

ReferancesRamirez, L. E. (May 9th, 2014). Using Arti cial fiNe ura l

Ne two rks to Pla y Po ne . FANG, S.-K. W.-W. (2012). A Study o n G e ne tic

Alg o rithm a nd Ne ura l Ne two rk fo r Mini-G am e s . Hsinchu, 300 Taiwan: Department of Computer Science National Chiao Tung University .

Kenneth O. Stanley, R. M. (2002). Evo lving Ne ura l Ne two rks thro ug h Aug m e nting To p o lo g ie s . the Massachusetts Institute of Technolog.

David M. Bourg, G. S. (2004, 9 30). Cool Ways to Use

Neural Networks in Games.Rawlins, G. J. (2000). Genetic Algorithm.Stanley, K. O. ( 2004, 2 8). NeuroEvolution of

Augmenting Topologies (NEAT).

Page 28: Ai in games

Thank You