def tail_gate(snake: Snake, board: BoardState, grid_map : GridMap) -> Direction: head = snake.get_head() tail = snake.get_tail() body = snake.get_body() distance = Distance.manhattan_dist(head, tail) if distance == 1: for direction in Direction: if head.advanced(direction) == tail: return direction else: dist = 9999 next_direction = None for direction in Direction: advanced_head = head.advanced(direction) d = Distance.manhattan_dist(advanced_head, tail) if advanced_head not in body: if d < dist: dist = d next_direction = direction return next_direction
def grow_snake(self, snake: Snake): if len(snake.body) > 0: tail = snake.get_tail() snake.body.append(tail)