Members - Reputation: 937
Posted 08 November 2012 - 07:38 AM
Deltron Zero and Automator.
Crossbones+ - Reputation: 10553
Posted 08 November 2012 - 08:01 AM
A linked list with head and tail could be appropriate, as each step you could just remove the tail if the snake hasn't grown, and add a new head depending on the direction the snake is facing, I guess. And then use an ordinary list to store the apples on the map and check if the snake's head is on any apple or on any part of its body (by iterating through the linked list - this might not be ideal). At least that's what springs to mind at first - there are possibly better ways to do it.
How to know what data structures and algorithms to use to program Snake.
A simple 2D array which keeps track of the snake's head and tail would probably work better here anyway, in fact.
Edited by Bacterius, 08 November 2012 - 08:11 AM.
The slowsort algorithm is a perfect illustration of the multiply and surrender paradigm, which is perhaps the single most important paradigm in the development of reluctant algorithms. The basic multiply and surrender strategy consists in replacing the problem at hand by two or more subproblems, each slightly simpler than the original, and continue multiplying subproblems and subsubproblems recursively in this fashion as long as possible. At some point the subproblems will all become so simple that their solution can no longer be postponed, and we will have to surrender. Experience shows that, in most cases, by the time this point is reached the total work will be substantially higher than what could have been wasted by a more direct approach.
- Pessimal Algorithms and Simplexity Analysis