A simple 2D Snake game is present, wherein the task of the snake is to grow by consuming 'food', while avoiding the edges of the window, and it's own body. The human player's Snake achieves this through keyboard input from the user.
Alternatively, the code also contains an algorithm to automatically achieve this, to an extent, I for any number of snakes and for any speed of the snake(s).
The implemented auto-play algorithm does not use any kind of Deep learning or Artificial Intelligence modelling. It does not use any Search or traversal algorithms. It is implemented using if-else decision trees and performs satisfactorily, even when a large number of automated snakes are involved.
It automatically stores scores of every playing Snake, along with the timestamp, through a score_save() helper function in the code, every time the Game is Restarted(R)
or Quit(Q)
.
It also saves Average Score of Snakes, and the Game Parameters(see below) that the Game was played with.
- Whether human plays or not.
- Number of total Snakes.
Number of AI Snakes = Total Snakes - (Is Human playing)
- Number of available food for Snakes.
- Friendly Fire: Whether Snakes can consume other snakes and thereby gain their score.
- Whether number of available food is changeable in game
Press
w
to increase the number of available food ands
to decrease the number of available food. - Speed of the Game.
- Install Python 3.8 and the required Py-Game Library.
- Scroll down to main() at the bottom of the Snake\Snake+Algo.py code for checking and changing game parameters.
- Compile and Run.
- Arrow keys control the snake if
User
variable has been set to 1 in main(). - Number of available food for Snakes can be increased with
w
and decreased withs
iscontrolled_food
has been set to 1 in main().
- Further improvements to the algorithm of the Snake (if possible, without implementing techniques like Learning)
- Inclusion of traits like competitiveness, aggression to the automatic solving algorithm