Skip to content

nrsharip/ai-genetic-algorithm-snake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview

Try the following link: https://nrsharip.github.io/ai-genetic-algorithm-snake/

This is a port of AI-for-Snake-Game (see The AI for Snake Game Chronicles by Craig Haber) from Python to Javascript.

UPDATE: Managed to reach the score of 79 by adjusting the criterias (see RUN 2022-07-24 21:21:26).

NOTE: To accelerate the training process use the multiprocessing python version.

Screenshots

Development

Neural Network and Data Flow

Pareto Fronts and Scatter Charts

Generation #4140:

Successes

RUN 2022-07-24 21:21:26

Criterias changed:

(see this line in snakeGameGATest.js)

if self.frames_since_last_fruit == 100:
    self.game_over()

(see this line in snakeGameGATrain.js)

if self.frames_since_last_fruit == 100:
    frame_score = self.frames_alive - self.frames_since_last_fruit
    if frame_score <= 0:
        frame_score = 0

(see this line in snakeGameGATrain.js)

_1 = self.score**(4.5 - (self.score + 1)**(1/5))
_2 = frame_score**((self.score + 1)**(1/3))
fitness = _1 * _2

RESULTS:

(see GAdata.txt):

Generation 4007 Best Game Score: 79
Generation 3186 Best Game Score: 73
Generation 3465 Best Game Score: 73
Generation 4141 Best Game Score: 73
Generation 3448 Best Game Score: 72
Generation 4035 Best Game Score: 72
Generation 4223 Best Game Score: 72
Generation 4368 Best Game Score: 72
Generation 4449 Best Game Score: 72
Generation 3825 Best Game Score: 71
Generation 4077 Best Game Score: 71
Generation 4332 Best Game Score: 71
Generation 4333 Best Game Score: 71

Tries and Failures

Generation #4140 (4152) CPG:200 BPW:8 I:9 H:10 O:4 failures:

File Map to AI-for-Snake-Game