GithubHelp home page GithubHelp logo

alifiazahra12 / snake_pathfinding_ai Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hayderkharrufa/snake_pathfinding_ai

0.0 0.0 0.0 54 KB

AI plays snake game using BFS (Breadth-First Search) algorithm.

License: MIT License

Python 100.00%

snake_pathfinding_ai's Introduction

Snake Pathfinding AI

AI plays snake game using BFS (Breadth-First Search) algorithm.
Check out this YouTube video (in Arabic) to see how I built this project.

gameplay

How to run?

  • Install Python 3.
  • Install these modules:
pip install pygame
  • Run play.py file.

Files / Directories

  • settings.py : contains game settings and global variables like width, height, etc..
  • snake.py : contains Snake and Square classes.
  • play.py : contains code for running the project.

How it works?

  1. The snake will use BFS algorithm to find the shortest path between its head and the apple (let's call it path_1). If path1 is not available, then go to step 4.
  2. Create a virtual snake identical to the original snake and make it follow path_1.
  3. After the virtual snake reaches the apple, check if the path between the virtual snake's head and its tail is available (let's call it path_2), if so, then make the original snake follow path_1.
  4. If path_1 or path_2 are not available, make the original snake follow its tail.

For more details, read the comments in .py files.

Authors

  • Hayder Kharrufa - Initial work -

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

snake_pathfinding_ai's People

Contributors

hayderkharrufa 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.