pygame is
Simple DirectMedia Layer is
Site Swing
A* Pathfinding Algorithm

A* Pathfinding Algorithm - 2.2

Canio Massimo Tristano (keebus)



This is a A* pathfinding algorithm demo working with pygame.

Just run the file.

Red cell means it's in the CLOSED list, green in the OPEN list (cells still to check). The numbers in cells are g (the cost), h ( the heuristic) and f ( the total score, f = g + h).

Thanks and enjoy.


Possibility to save/load the map and other improvements.


Home Page:


click to view original size


A* Pathfinding Algorithm - 2.2 - Jul 8, 2008
A* Pathfinding Algorithm - 2.0 - Jun 11, 2008
A* Pathfinding Algorithm - 1.0 - Jun 10, 2008 account Comments

If you wish to leave a comment with your account, please sign in first.

March 2, 2010 12:21pm - sharavsambuu gunchinish - nickname: (sharavsambuu) - 4/5
link is not working. can u give another link?
September 27, 2009 5:40am - Unknown - nickname: (cib) - 5/5
This utility owns! I don't understand the numbers yet, but it is interesting to see how clumsy the computer guesses before it finds the correct path =)
July 10, 2008 1:50pm - Jordan Trudgett - nickname: (tgfcoder)
return (r3,g3,b3) if a3 != 255 else (r3,g3,b3,a3)

These things are everywhere.. are they new in Python? I have Python 2.4.4.

This is how I've done it in the past:

return [(r3,g3,b3,a3), (r3,g3,b3)][a3 != 255]

(which is equivalent)
July 9, 2008 7:35pm - RB[0] - nickname: (roebros)
There is a pygame installer for 2.5 ...
And yes, that probably is your problem...

Basically, you should totally uninstall python and then install the new version...(I assume you are using winXP ;) )

Then download the new version of pygame and install :)
July 9, 2008 2:17pm - Dylan J. Raub - nickname: (dylanjraub)
Oh... I only have 2.4. Did they finaly release a 2.5 version of pygame?
July 9, 2008 10:46am - Canio Massimo Tristano - nickname: (keebus)
on my system there's the 2.5.2 :)
July 8, 2008 9:34pm - Paul Davey - nickname: (technomancer) - 5/5
are you using python 2.5.1 or 2.5.2?
June 18, 2008 3:07pm - Dylan J. Raub - nickname: (dylanjraub)
Nope, it just won't work.

There is a syntax error on line... um, never mind. There's a part where it says like " jack = jill if True and Crown" or something... IDLE dousn't like it.
June 17, 2008 3:26pm - Dylan J. Raub - nickname: (dylanjraub)
No, wait! It may work. I'm using a computer where I'm not allowed to use Command Prompt, so python won't run. Sorry for the confution... (please ignore my spelling errors...)
June 17, 2008 3:24pm - Dylan J. Raub - nickname: (dylanjraub)
Dude, it STILL won't work!!! I read the files and I got lost at the part where it changes the 26 to 20 because of some wierd reason that it explained very poorly... Oh, and I don't know why it won't work this time. Simply put: I can't figure out the problem and I need help!
June 14, 2008 2:07pm - Canio Massimo Tristano - nickname: (keebus)
Avoid the 1.0 version because, yes it was ugly =) The 2.0 is much more understandable, but still not really beautiful.

The gui system is avaible here on, check this link

June 13, 2008 12:44pm - foo - nickname: (foo)
I am running Ubuntu 8.04 too and I have the same problem littlegoat has: widgets are there, otherwise everthing's black.

Hell, your source is ugly :P
On the other hand, your UI looks nice :)

Otherwise a nice program.
June 13, 2008 1:06am - Ian Mallett - nickname: (geometrian)
Very nice.
June 12, 2008 11:38am - Canio Massimo Tristano - nickname: (keebus)
I run Ubuntu 8.04 as well and it runs fine to me. Try downloading again... I did a little change.

Thank you ethan.
June 11, 2008 11:16pm - Ethan Huang - nickname: (ethan) - 5/5
Thanks a lot for your shared. It's a good programs.
June 11, 2008 3:32pm - Dylan J. Raub - nickname: (dylanjraub)
It won't run due to a problem in draw path.
June 11, 2008 2:43pm - Caleb G - nickname: (littlegoat) - 4/5
I run Ubuntu 8.04, and the first version ran fine, but now all it shows are the option boxes and a gray dot. All the rest of the window is black.
Very cool when it worked, though.
June 11, 2008 8:12am - Dylan J. Raub - nickname: (dylanjraub)
I looked at the first link. You project looks just like how they discribed it should be made. Cool.
So it finds the shortest path, right? Man, that's cool!
June 10, 2008 5:37pm - Emanuel Berg - nickname: (metabaron)
Very cool.
June 10, 2008 11:15am - Cepheus - nickname: (cepheus) - 5/5
Functionally and visually impressive :)
June 10, 2008 10:16am - pymike - nickname: (pymike)
Cool demo :)
June 10, 2008 10:13am - pymike - nickname: (pymike)
link didn't work till I changed it to ""
June 10, 2008 9:55am - Canio Massimo Tristano - nickname: (keebus)
I can give you the sources I've used to learn what I had to learn (I did it in one afternoon, and if I did it you can do it too).

Here you go:

I suggest you to start from the first, coz it's quite simple.

For any matter, just ask.
June 10, 2008 8:35am - Dylan J. Raub - nickname: (dylanjraub)
Hmm. How did you do that? That type of programing is common in many games ith ai, but I've always had trouble with it, so how do you do it (and how do you do it quickly)?

our projects welcomes all python game, art, music, sound, video and multimedia projects. If they use pygame or not.
recent releases
Jan 7, 2017

Dec 30, 2016

Dec 21, 2016

Dec 8, 2016

Nov 28, 2016

Nov 27, 2016

Nov 24, 2016

Nov 20, 2016

Nov 14, 2016

Nov 6, 2016

Nov 5, 2016

... more!
for pygame related questions, comments, and suggestions, please see help (lists, irc)