Skip to content

A pathfinding visualization of A* algorithm using python's pygame module

License

Notifications You must be signed in to change notification settings

CSjianbel/A-Pathfinding-Visualization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Pathfinding Visualization

A pathfinding visualization of A* Algorithm using python's pygame module.

A* is a famous algorithm for search problems in Computer Science. A* guarantees the shortest path from 2 nodes. It uses heuristics to decide which node to explore next, prioritizing nodes that are known to be closer to the goal based on the Euclidean distance that is returned by a heuristic function.

To visualize the algorithm a 2d grid in pygame was created, and represented each cell of the grid as a node. A node can either be a wall, start, or end. The pathing can either be both diagonal and across (default), or it can only be across. Usage and Basic Controls may be found below and in src/pathfind.py.

Clone

git clone https://github.com/CSjianbel/A-Pathfinding-Visualization.git

Setup

Install Dependencies through package manager pip

pip install -r requirements.txt

Basic Controls

  • START: 's'

  • END: 'e'

  • WALL: left click

  • REMOVE WALL: right click

  • FIND PATH: 'a'

  • STOP FINDING PATH: '0'

  • SET PATHING:

    • SET ACROSS AND DIAGONAL: 'p' (DEFAULT)
    • SET ACROSS ONLY: 'o'

  • SET SPEEDS:

    • 3: FAST (DEFAULT)
    • 2: MEDIUM
    • 1: SLOW

  • GENERATE RANDOM MAZE: '9'

  • RESETS:

    • SOFT RESET: 'q'
    • HARD RESET: 'r'

COLOR REPRESENTATIONS:

  • Turquoise #40e0d0
    • START NODE
  • Purple #9400d3
    • END NODE
  • Black #000
    • WALL
  • White #ffffff
    • OPEN PATH
  • Green #00ff00
    • NODES IN OPEN SET
  • Red #ff0000
    • NODES IN CLOSED SET
  • Yellow #f0ff00
    • PATH FROM START TO END

Usage

python pathfind.py

Optionally you may change the WIDTH of the window. Width must be divisible by 15, if not the program will automatically adjust the specified width to be divisible by 15. Invalid command line arguments will result to default width of 600.

python pathfind.py --width

python pathfind.py --width 900

optional arguments:
  -h, --help            show this help message and exit
  -w WIDTH, --width WIDTH
  			Enter width of the pygame window : default - 600

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

A Project by Jiankarlo A. Belarmino

About

A pathfinding visualization of A* algorithm using python's pygame module

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages