Code Monkey home page Code Monkey logo

snakeais's Introduction

SnakeAIs

SnakeAIs (Snakeyes) is a recreation of the famous snake game using Python( famous for those who have witnessed the keypad era of mobile phones). Traditionally in this game, a player assumes the role of a snake that has to manoeuvre around a grid to collect food and also avoid hitting obstacles in the process. As the game progresses and the snake collects more food, its speed and size increase making it difficult for the player to efficiently manoeuvre the snake. The objective here is to collect as many food items as possible before colliding with the obstacles, the walls of the grid or any part of the snake itself.

SnakeAIs puts a twist on the traditional snake game by using various state-space search algorithms that generate paths for the snake to traverse the grid and collect food. The idea behind this project was to understand how these algorithms work by applying them to a game for better visualization and comparison. The ultimate objective is to create gamified informational website for explaining each of these state-space algorithms though examples based on the game.



Table of Contents

Installation

Before you start the installation process make sure you have python installed.

  1. Clone this repositor on your local machine:
git clone https://github.com/megh-khaire/snakeAIs.git
  1. Move inside the main project directory:
cd snakeAIs
  1. Setup and activate your virtual environment (optional):
# To create a virtual env:
python -m venv .venv

# For activation use one of the following commands based on your OS:
source .venv/bin/activate   # On Mac / Linux
.venv\Scripts\activate.bat  # In Windows CMD
.venv\Scripts\Activate.ps1  # In Windows Powershel
  1. Install the required packages from the requirements.txt file:
pip install -r requirements.txt

(back to top)

Usage

  • To start the game run the main.py file:

    python snake -gt "bfs" -o True
    
  • The main.py file accepts two command line argument: game_type and obtacles, through which we can specify the type of algorithm the snake will use for traversal and if obstacles should be present in the game.

> python ./snake/main.py -h

optional arguments:
  -h, --help            show this help message and exit
  -gt GAME_TYPE, --game_type GAME_TYPE
                        type of game you want to play
  -o OBSTACLES, --obstacles OBSTACLES
                        specify if you would like to include obstacles in the game
  • Refer the following list to get the arguments required for using any of the currently supported algorithms:
Algortihm Argument
Random Search random
Breadth First Search bfs
Depth First Search dfs
Hill Climing simple_hc
Steepest Ascent Hill Climing steepest_ascent_hc
Stochastic Hill Climing stochastic_hc
Best First Seach bestfs
A* Search a_star
  • To play the game yourself you can use the following command:

      python snake -gt "manual"
    

Note: The random search algorithm moves the snake randomly through the state-space and also avoids obstacles while doing so resulting in an endless loop.

(back to top)

Modifications

  • snake\resources\configs.py defines configurations that determine the rate at which the difficulty of the game will increase as the game progresses.
  • To increase the difficulty of the game the speed of the game is increased by increasing the framerate.
  • Following are the configs defined under configs.py that are used to manipulate the difficulty level of the game.
    • INITIAL_SPEED is the initial framerate when the game starts.
    • SPEEDUP is the rate at which the framerate increases after the snake accumulates a fixed threshold of points.
    • SPEED_THRESHOLD defines the number of food points the snake has to collect before speedup.
    • FIXED_AUTO_SPEED is the maximum framerate for the game, this is the maximum difficulty level. It is also the framerate at which the game runs when the snake while using the search algorithm.
  • snake\resources\colors.py defines color constants used throughtout the game. These colors can be modified to change the color of the grid, snake, food and obstacles.

Note: The difficulty configurations are only applicable when the user controls the snake's action. In cases where the algorithm controls the snake a fixed difficulty rate (FIXED_AUTO_SPEED) is used.

(back to top)

Roadmap

This project is currently under active development. In the near future, I plan to implement the following algorithms:

  • Hamiltonian Cycle
  • Reinforcement Learning
  • Evolutionary Algorithms
  • Genetic Algorithm combined with Deep Learning

After implementing these algorithms the next step will be to analyze their performance and start work on the gamified informational website, as mentined above that is the ultimate goal of this project.

(back to top)

Contributing

Do you like the project or have new ideas? You are welcome to join the project. For small changes, you can drop in pull requests. For major changes, please open an issue first to discuss what you would like to change.

(back to top)

License

Distributed under the Apache License. See LICENSE.txt for more information.

(back to top)

Acknowledgments

Earlier the scope of the projects was just restricted to the exploration of state-space search algorithms. A big thanks to the Python Engineer for making this amazing tutorial on Reinforcement learning that has now inspired me to explore Machine Learning techniques in my quest for developing the smartest Snake AI. Stay tuned for ore updates :).

(back to top)

snakeais's People

Contributors

megh-khaire avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.