Giter Club home page Giter Club logo

snake-algorithms's Introduction

Snake Solving Algorithms

Indroduction

The classic game snake and various algorithms to play the game. This is not an AI.

Installation

You need to have Python and pip running. Also, pygame is required.

pip install pygame

Concept

The snake makes decisions staring from its head, since it´s moving from there

Play the Game

In the directory of the repository execute

py game.py <number>

on Windows. It should work the same on any OS, but hasn´t been tested.

The <number> attribute determines which algorithm will be used to play snake.

The window can be resized even while the game is running which resets the progress.

All results of each algorithm are saved in a file.

The game speed can be controlled using a scrolling mechanism like a mouse wheel or a touchpad. Time can be frozen and unfrozen using the space key. Additionally, the keys 1, 2, 3 can set the speed to fixed values quickly.

Algorithms

number Algorithm
0 Manual Gameplay: The player controls the snake using the arrow keys.
1 Straight: The snake is going straight for the food without knowing the position of its body.
2 Turning: The snake knows how to turn when its own body is in the way.
3 Smart: The snake doesn't die to the edge or itself.
4 Perfect: It's not but is makes sure that at every time 80% of the free tiles are available to the head. The snake will trap itself on one side of the grid and cycles until it's dead.
5 Gap: This algorithm leaves a gap to avoid trapping itself, but it's not perfect.
6 Hamiltonian Cycle: It lays out a path and follows it all the time. Will reach 100% but takes very long.
7 Skip of Hamiltonian Cycle: The attempt to let the snake skip some parts of the Hamiltonian cycle, but it didn't work out.

snake-algorithms's People

Contributors

ey-jo 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.