Giter VIP home page Giter VIP logo

snake-neat's Introduction

Snake-NEAT


Snake-NEAT

A self-learning snake game implemented using NEAT algorithm

About

Project developed at the college as a final work for the artificial intelligence subject

Original code developed between May 15, 2018 - Jun 29, 2018

How to run

Install dependencies

pip install -r requirements.txt

Run

python game.py

Dependencies

  • Pygame: Used in game development and user interaction
  • neat-python: Python implementation of the NEAT neuroevolution algorithm

Controls

  • F1: Takes control of the game, making it possible to control the snake's movements with the keyboard arrows
  • F2: Sets a high frame rate (fast) until the snake dies
  • F3: Sets a low frame rate (slow) until the snake dies
  • F4: Enable the debug draw, drawing input indicators

Fitness function

SnakeLength - TurnedQuantity * 0.01
  • SnakeLength: Snake length defined by how many apples it ate

  • TurnedQuantity: How many times did the snake change direction, either left or right

Inputs

  1. cd_left: Collision-free units at left
  2. cd_top: Collision-free units at top
  3. cd_right: Collision-free units at right
  4. cd_bottom: Collision-free units at bottom
  5. cd_top_left: Collision-free units at top left
  6. cd_top_right: Collision-free units at top right
  7. cd_bottom_left: Collision-free units at bottom left
  8. cd_bottom_right: Collision-free units at bottom right
  9. apple_x_distance: If there is an apple on the right or left, this variable contains the distance in units to the apple
  10. apple_y_distance: If there is an apple on the top or bottom, this variable contains the distance in units to the apple

You can "see" these inputs in debug mode

Debug Mode

Outputs

  • 0: Don't change direction
  • 1: Turn right
  • 2: Turn left

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.