From af9d1c19bd5dbdb8c6d5921003d3de12561ed062 Mon Sep 17 00:00:00 2001 From: Egor Kostan Date: Wed, 30 Oct 2024 20:06:05 -0700 Subject: [PATCH] Update walker_class.py --- .../walker_class.py | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/kyu_3/line_safari_is_that_a_line/walker_class.py b/kyu_3/line_safari_is_that_a_line/walker_class.py index db7d2962982..14707a95d1b 100644 --- a/kyu_3/line_safari_is_that_a_line/walker_class.py +++ b/kyu_3/line_safari_is_that_a_line/walker_class.py @@ -11,7 +11,6 @@ class Walker: """ def __init__(self, grid: list): - # print('__init__') self.__grid: list = grid self.__is_start: bool = True self.__position: dict = self.__get_start_point() @@ -158,6 +157,8 @@ def __set_direction(self) -> None: self.__reset_direction() print(f'prev: {previous_position}, pos: {self.position}') + case_i = self.__get_case_i(previous_position) + if self.position == '+' and previous_position in '-X': self.__direction['up'] = self.__test_up() self.__direction['down'] = self.__test_down() @@ -186,6 +187,46 @@ def __set_direction(self) -> None: elif self.__position['row'] > self.__position['prev_row']: self.__direction['down'] = self.__test_down() + def __get_case_i(self, previous_position) -> int: + """ + Get case i base on the current position vs previous_position + :param previous_position: + :return: + """ + i: int = 0 + + if self.position == '+' and previous_position in '-X': + i = 1 + + if self.position == '+' and previous_position == '|': + i = 2 + + if self.position == previous_position == '+' \ + and self.__position['col'] == self.__position['prev_col']: + i = 3 + + if self.position == previous_position == '+' \ + and self.__position['row'] == self.__position['prev_row']: + i = 4 + + if self.position == '-' and previous_position in '-X+' \ + and self.__position['col'] < self.__position['prev_col']: + i = 5 + + if self.position == '-' and previous_position in '-X+' \ + and self.__position['col'] > self.__position['prev_col']: + i = 6 + + if self.position == '|' and previous_position in '|X+' \ + and self.__position['row'] < self.__position['prev_row']: + i = 7 + + if self.position == '|' and previous_position in '|X+' \ + and self.__position['row'] > self.__position['prev_row']: + i = 8 + + return i + def __test_up(self) -> bool: row: int = self.__position['row'] col: int = self.__position['col']