2022-01-03
A* Snake Game
At the beginning of this small weekend project, I just wanted to make a small snake game like one may have played on those old cellphones. But very quickly my attention was drawn into the interesting A* path finding algorithm, and decide to combine it with the Snake game.
So now when you press space bar to pause the game at any time, an animation will be played to demonstrate how the A* algorithm would find the most optimal path from the head of the snake to the apple, bypassing all the walls. The green pixels annotates the spot that the algorithm marked as "will check later" and red means "checked".
Play the game yourself at snake.xinshi.me
Or read more about A on this wikipedia [page](https://en.wikipedia.org/wiki/A_search_algorithm), or check our plenty of nice YouTube videos about it like this and this
Tools that are used in this small project: Typescript, Reactjs, chakra-ui/react. The board is rendered using canvas (instead of divs in the Game of Life implementation)
Read the source code here I also used this nice implementation of Heap-based priority queue from gyre on stackOverflow to implement the A* algorithm.