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:
2024-04-18 17:14:49 +02:00
parent 5522a52227
commit 5796ce0a6e
+14
View File
@@ -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