Giter Club home page Giter Club logo

snaketf's Introduction

Neural Network Snake Game

This project is an implementation of the classic Snake game using p5.js, a JavaScript library for creative coding. The snake is controlled by a neural network that is evolved over time using a genetic algorithm, powered by tensorflow.js.

Description

The Snake game involves a snake on a grid that is controlled by a neural network. The snake moves continuously and grows longer as it consumes food items. The objective is to evolve a neural network that can navigate the snake without colliding into itself or the game boundaries.

Features

  • Neural network controlled snake.
  • Genetic algorithm for evolving the neural network.
  • The snake grows longer upon eating food.
  • Game ends if the snake collides with itself or the border.

How to Play

You can access the game by clicking here!

  1. Gameplay:
    • The snake moves continuously in the direction determined by the neural network.
    • When the snake eats the food, it grows longer, and new food appears.
    • Avoid collisions with the snake's body or the game border.
  2. Game Over:
    • The game ends if the snake collides with itself or the border.
    • Press 'Refresh' to restart the game.

Code Structure

The main components of the code include:

  • Snake class: Controls the behavior of the snake.
  • Food class: Manages the food items on the game board.
  • NNSnake class: A snake controlled by a neural network.
  • Brain class: Represents the neural network that controls the snake.
  • GameInstance class: Represents a single instance of the game, including the snake, food, and game state.
  • GameInstancesManager class: Manages multiple game instances for the genetic algorithm.
  • Game loop: Handles the game logic and drawing on the canvas.

Dependencies

snaketf's People

Contributors

awakenedhaki avatar

Stargazers

 avatar

Watchers

 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.