Activity 4.3.1: Terminus - Part 2 [top] -
# Terminus - Part 2: Right-Hand Rule Navigation # Assumes a grid with obstacles (1 = wall, 0 = open) def right_hand_rule_navigation(grid, start, goal): """ Navigate from start to goal using the right-hand rule. grid: 2D list (0=free, 1=wall) start, goal: (row, col) tuples """ # Directions: 0=North, 1=East, 2=South, 3=West dirs = [(-1, 0), (0, 1), (1, 0), (0, -1)] direction = 1 # start facing East
if (row, col) == goal: print(f"Goal reached in {steps} steps!") return path else: print("Goal unreachable or loop detected.") return None grid_example = [ [0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 0, 0, 1, 0], [0, 1, 0, 0, 0], [0, 0, 0, 1, 0] ] activity 4.3.1: terminus - part 2
steps = 0 max_steps = len(grid) * len(grid[0]) * 2 # prevent infinite loops # Terminus - Part 2: Right-Hand Rule Navigation
(like adding a “teleport” command, logging moves, visualizing the grid, or handling dynamic obstacles), just let me know. 0 = open) def right_hand_rule_navigation(grid