The goal of this assignment was to measure the usefulness of various search algorithms. In this example, we are using Breadth First Search, Depth First Search, and A* search with two heuristics (and combined) to allow the snake to find the food.
This application uses web workers to offload the processing, which allows the browser UI to remain responsive even though CPU intensive operations may be taking place. The results are drawn on the screen using a canvas element.
Breadth First Search - Results in low average moves, but must process many nodes (low number of moves at high CPU cost)
Depth First Search - Results in high average moves, but must process many nodes (high number of moves at high CPU cost, very bad)
A* Search - Results in low average moves, with low number of processed nodes (low number of moves at low CPU cost, very good)
It's the heuristics! A* search allows us to know what direction the food is closest to, so we search in that direction instead of randmonly wandering around the board. Sort of like if the snake had a sense of smell.