Members - Reputation: 950
Posted 08 November 2012 - 07:38 AM
Deltron Zero and Automator.
Crossbones+ - Reputation: 12941
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.
“If I understand the standard right it is legal and safe to do this but the resulting value could be anything.”