Skip to content

Commit

Permalink
Update walker_class.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ikostan committed Dec 3, 2024
1 parent 02f6d4c commit 17c8585
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions kyu_3/line_safari_is_that_a_line/walker_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Walker:
"""
Walker class: make moves, check directions, etc...
"""

def __init__(self, grid: list):
self.__grid: list = grid
self.__is_start: bool = True
Expand All @@ -28,15 +27,15 @@ def __set_initial_direction(self) -> dict:
col: int = self.__position['col']

# up
if row - 1 >= 0 and self.__grid[row - 1][col] in 'X|+':
if row >= 1 and self.__grid[row - 1][col] in 'X|+':
direction['up'] = True

# down
if row + 1 < len(self.__grid) and self.__grid[row + 1][col] in 'X|+':
direction['down'] = True

# left
if col - 1 >= 0 and self.__grid[row][col - 1] in 'X+-':
if col >= 1 and self.__grid[row][col - 1] in 'X+-':
direction['left'] = True

# right
Expand All @@ -57,7 +56,7 @@ def position(self) -> str:

def move(self) -> None:
"""
Make one step if possible
Make one step if possible.
:return: None
"""
if not self.is_done:
Expand Down Expand Up @@ -87,8 +86,7 @@ def move(self) -> None:
@property
def is_done(self) -> bool:
"""
Check if get to the 'X' point
or can make one move only
Check if get to the 'X' point or can make one move only.
:return: true/false
"""
if self.__is_start:
Expand All @@ -105,7 +103,7 @@ def is_done(self) -> bool:

def __get_start_point(self) -> dict:
"""
Locate starting point
Locate starting point.
:return: dict, starting point X
"""
result: dict = {}
Expand All @@ -131,7 +129,7 @@ def __reset_direction(self) -> None:

def position_plus(self, previous_position) -> None:
"""
Process cells if current position is +
Process cells if current position is +.
:param previous_position:
:return:
"""
Expand All @@ -155,7 +153,7 @@ def position_plus(self, previous_position) -> None:

def position_minus(self, previous_position) -> None:
"""
Process cells if current position is -
Process cells if current position is -.
:param previous_position:
:return:
"""
Expand All @@ -167,7 +165,7 @@ def position_minus(self, previous_position) -> None:

def position_pipe(self, previous_position) -> None:
"""
Process cells if current position is |
Process cells if current position is |.
:param previous_position:
:return:
"""
Expand All @@ -179,8 +177,7 @@ def position_pipe(self, previous_position) -> None:

def __set_direction(self) -> None:
"""
Update directions based on current
position and previous direction
Update directions based on current position and previous direction.
:return: None
"""
prev_row = self.__position['prev_row']
Expand All @@ -194,6 +191,10 @@ def __set_direction(self) -> None:
self.position_pipe(previous_position)

def __test_up(self) -> bool:
"""

Check warning on line 194 in kyu_3/line_safari_is_that_a_line/walker_class.py

View check run for this annotation

Codecov / codecov/patch

kyu_3/line_safari_is_that_a_line/walker_class.py#L194

Added line #L194 was not covered by tests
Test u
:return:
"""

Check warning on line 197 in kyu_3/line_safari_is_that_a_line/walker_class.py

View check run for this annotation

Codecov / codecov/patch

kyu_3/line_safari_is_that_a_line/walker_class.py#L197

Added line #L197 was not covered by tests
row: int = self.__position['row']
col: int = self.__position['col']
if row - 1 >= 0 and self.__grid[row - 1][col] in 'X|+':
Expand Down

0 comments on commit 17c8585

Please sign in to comment.