Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Sharing of my learning and implementation of A* algorithm

Author
Message
hoyoyo80
8
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 19th Sep 2017 16:25
Hi,

I read and learn to implement a* algorithm in AGK2. Maybe someone want to learn or make the code better and more efficient.But for now its works!
For the tiles, the number on the centre of tiles is the tile id. Top left corner is the F Value, Bottom left is G and Bottom right is H.
The pink tile is the source, the yellow is the destination, the blue is on openlist, orange on closedlist and green is traceback path.

But this code have limitation and need optimization/better code as:
1.I calculate the H value, the distance between the tiles to the destination once the map load
2.The code only check left,right,up,down but it also easy to add diagnol check
3.I use spriteraycast to check neighbour tiles

Maybe the code can be enhanced to when can have dynamic source and destination for testing? Any better way on checking neighbouring tiles?

Thanks and hope this can help to start learning a*. Forgive me for the poor coding structure.

Attachments

Login to view attachments
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 20th Sep 2017 14:14 Edited at: 20th Sep 2017 14:17
that's neat, i adjusted it a bit to make it easier to make random paths/obstacles (click to restart), works pretty nicely
p.s. i dont suggest you keep my code, it's merely an attempt to show off the path finding in a more repetitive way.
life's one big game
spec= 4ghz, 16gb ram, AMD R9 2700 gpu

Attachments

Login to view attachments
hoyoyo80
8
Years of Service
User Offline
Joined: 11th May 2016
Location:
Posted: 20th Sep 2017 17:30
Yesss...i really like that smallg.Thanks.Haha. Hope it can help beginner coder like myself to understand pathfinding better.

Login to post a reply

Server time is: 2024-11-22 20:56:06
Your offset time is: 2024-11-22 20:56:06