Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualBacterius

Posted 08 November 2012 - 08:11 AM

How to know what data structures and algorithms to use to program Snake.

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.

A simple 2D array which keeps track of the snake's head and tail would probably work better here anyway, in fact.

#3Bacterius

Posted 08 November 2012 - 08:07 AM

How to know what data structures and algorithms to use to program Snake.

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.

Though a simple 2D array could work just as well, I guess.

#2Bacterius

Posted 08 November 2012 - 08:02 AM

How to know what data structures and algorithms to use to program Snake.

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.

#1Bacterius

Posted 08 November 2012 - 08:01 AM

How to know what data structures and algorithms to use to program Snake.

A linked list with head and tail could be appropriate, as each step you could just add the tail to the head and remove the tail if the snake hasn't grown, 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. At least that's what springs to mind at first - there are possibly better ways to do it.

PARTNERS