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 Oct 31, 2024
1 parent e4db2e7 commit c4b63fc
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions kyu_3/line_safari_is_that_a_line/walker_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,27 @@ def __set_initial_direction(self) -> dict:
'left': False,
'right': False,
'up': False,
'down': False,
}
'down': False}

# coordinates
row: int = self.__position['row']
col: int = self.__position['col']

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

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

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

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

print(f"\nINITIAL DIRECTION: {direction}")
return direction
Expand Down Expand Up @@ -165,23 +160,27 @@ def __set_direction(self) -> None:
if self.position == '+' and (previous_position in ('-', 'X')):
self.__direction['up'] = self.__test_up()
self.__direction['down'] = self.__test_down()
elif self.position == '+' and previous_position == '|':

if self.position == '+' and previous_position == '|':
self.__direction['left'] = self.__test_left()
self.__direction['right'] = self.__test_right()
elif self.position == '+' and previous_position == '+':

if self.position == '+' and previous_position == '+':
if self.__position['col'] == self.__position['prev_col']:
self.__direction['left'] = self.__test_left()
self.__direction['right'] = self.__test_right()
elif self.__position['row'] == self.__position['prev_row']:
self.__direction['up'] = self.__test_up()
self.__direction['down'] = self.__test_down()
elif ((self.position == '-' and (previous_position in ('-', 'X')))

if ((self.position == '-' and (previous_position in ('-', 'X')))
or (self.position == '-' and previous_position == '+')):
if self.__position['col'] < self.__position['prev_col']:
self.__direction['left'] = self.__test_left()
elif self.__position['col'] > self.__position['prev_col']:
self.__direction['right'] = self.__test_right()
elif ((self.position == '|' and (previous_position in ('|', 'X')))

if ((self.position == '|' and (previous_position in ('|', 'X')))
or (self.position == '|' and previous_position == '+')):
if self.__position['row'] < self.__position['prev_row']:
self.__direction['up'] = self.__test_up()
Expand Down

0 comments on commit c4b63fc

Please sign in to comment.