Coder Social home page Coder Social logo

hayderkharrufa / snake_pathfinding_ai Goto Github PK

View Code? Open in Web Editor NEW
34.0 3.0 16.0 63 KB

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

License: MIT License

Python 100.00%
snake-game snake ai bfs python breadth-first-search pathfinding pathfinding-algorithm artificial-intelligence pygame

snake_pathfinding_ai's Introduction

Snake Pathfinding AI

This AI-powered snake game uses the Breadth-First Search (BFS) algorithm to navigate the snake autonomously. Learn how this project was developed by watching this YouTube video (Arabic).

Gameplay

Setup and Execution

  1. Download and install Python 3.
  2. Install the required modules by executing the following command in your terminal:
pip install pygame
  1. Run play.py to start the game.

Code Overview

  • settings.py : This file houses game configurations and global variables such as width and height.
  • snake.py : This is where the Snake and Square classes are defined.
  • play.py : Contains the code required to run the game.

Functionality

  1. The snake uses the BFS algorithm to find the shortest path (path_1) to the apple. If path_1 is not accessible, the process moves to step 4.
  2. A virtual snake, identical to the actual one, is created and set to follow path_1.
  3. Once the virtual snake reaches the apple, the path between its head and tail (path_2) is checked. If accessible, the actual snake is then directed to follow path_1.
  4. If either path_1 or path_2 is inaccessible, the actual snake is commanded to follow its tail.

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

Contributors

  • Hayder Kharrufa - Initial work

License

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

snake_pathfinding_ai's People

Contributors

hayderkharrufa avatar kareembasher avatar

Stargazers

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