From 5796ce0a6eb478baee3319df0bc31e1a4f4b6c45 Mon Sep 17 00:00:00 2001 From: Daniel Dolezal Date: Thu, 18 Apr 2024 17:14:49 +0200 Subject: [PATCH] add function to calculate where the new snake body is with or with no tail based on the move that is taken --- snakes/TemplateSnake.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/snakes/TemplateSnake.py b/snakes/TemplateSnake.py index b38eeb3..05f486a 100644 --- a/snakes/TemplateSnake.py +++ b/snakes/TemplateSnake.py @@ -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