Skip to content
/ snake Public

This project is a demonstration of a snake game + ai made in javascript.

License

Notifications You must be signed in to change notification settings

ferrybig/snake

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Snake

This project is a demonstration of a snake game + ai made in javascript.

Build proccess

This project uses Grunt as its task runner, and the code has been setup modulairy to provide good build support

  • Build and runs the project

    grunt
  • Builds the project

    grunt build

AI

The AI is made using a few basic rules:

  • On an even x cordinate, it may NOT move down (low priority)
  • On an odd x cordinate, it may NOT move up (low priority)
  • On an even y cordinate, it may NOT move left (low priority)
  • On an odd y cordinate, it may NOT move right (low priority)
  • The AI should avoid going thru walls (medium priority)
  • After committing a move, it may not intersect with itself (high priority)

The rules are resolved when trying to move, and usualy, no rules will be broken during the move progress.

After these steps are run, the ai will evaluate the strategic position of the move by using the euclidean distance function from the new position archieved, and move to that direction.

The basic steps prevent the ai from ever getting into a situation where it will kill itself (the first options basicly make it move in a grid like fasion)

The grid created by these operations look like:

↗️↘️↗️↘️↗️↘️↗️↘️
↖️↙️↖️↙️↖️↙️↖️↙️
↗️↘️↗️↘️↗️↘️↗️↘️
↖️↙️↖️↙️↖️↙️↖️↙️
↗️↘️↗️↘️↗️↘️↗️↘️
↖️↙️↖️↙️↖️↙️↖️↙️
↗️↘️↗️↘️↗️↘️↗️↘️
↖️↙️↖️↙️↖️↙️↖️↙️ 

To prevent the ai from making circles around the food in case the food in near a wall, the position of the food will be shifted a little off center, and is clipped at the sides of the playing field, this makes sure the food can always be picked up.

About

This project is a demonstration of a snake game + ai made in javascript.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published