add function to calculate where the new snake body is with or with no tail based on the move that is taken
This commit is contained in:
@@ -155,3 +155,17 @@ class TemplateSnake:
|
||||
self.avoid_walls()
|
||||
self.avoid_snakes()
|
||||
self.avoid_get_eaten_by_other_snakes()
|
||||
|
||||
def calculate_new_body_position(self, move:str=None, with_tail:bool=False):
|
||||
if move:
|
||||
head = self.get_possible_moves(self.my_head)[move]
|
||||
|
||||
body = [head]
|
||||
body.extend(self.my_body)
|
||||
body.pop()
|
||||
|
||||
if not with_tail:
|
||||
body.pop()
|
||||
|
||||
return body
|
||||
return move
|
||||
|
||||
Reference in New Issue
Block a user