8x8 Network Utility Info

> send 0,0 7,7 Path: (0,0) -> (1,0) -> (2,0) -> (3,0) -> (4,0) -> (5,0) -> (6,0) -> (7,0) -> (7,1) -> (7,2) -> (7,3) -> (7,4) -> (7,5) -> (7,6) -> (7,7) Status: Success

path = [] x, y = src tx, ty = dst

# move in Y direction step_y = 1 if ty > y else -1 while y != ty: y += step_y if self.nodes[(x, y)] != "up": return None, f"Node (x,y) is down — path blocked" path.append((x, y)) 8x8 network utility

def display_grid(self): """Text representation of 8x8 grid with node status""" print("\n8x8 Network Grid (U=up, .=down):") print(" " + " ".join(f"i:2" for i in range(self.size))) for y in range(self.size): row = f"y:2 " for x in range(self.size): status = "U" if self.nodes[(x, y)] == "up" else "." row += f" status " print(row) print() def main(): net = MeshNetwork(8) print("=== 8x8 Mesh Network Utility ===") print("Commands: send <x1,y1> <x2,y2> | down/up <x,y> | show | quit")

> down 4,0 Node (4,0) is now down

def route_packet(self, src, dst): """Simple dimension-order routing (X then Y)""" if src not in self.nodes or dst not in self.nodes: return None, "Source or destination out of range" if self.nodes[src] != "up" or self.nodes[dst] != "up": return None, "Source or destination down"

# move in X direction step_x = 1 if tx > x else -1 while x != tx: x += step_x if self.nodes[(x, y)] != "up": return None, f"Node (x,y) is down — path blocked" path.append((x, y)) &gt; send 0,0 7,7 Path: (0,0) -&gt; (1,0)

while True: cmd = input("\n> ").strip().lower() if cmd == "quit": break elif cmd == "show": net.display_grid() elif cmd.startswith("down ") or cmd.startswith("up "): parts = cmd.split() if len(parts) == 2: try: x, y = map(int, parts[1].split(",")) state = "up" if parts[0] == "up" else "down" if net.set_node_state((x, y), state): print(f"Node (x,y) is now state") else: print("Invalid node or state") except: print("Use: down x,y or up x,y") elif cmd.startswith("send"): parts = cmd.split() if len(parts) == 3: try: src = tuple(map(int, parts[1].split(","))) dst = tuple(map(int, parts[2].split(","))) path, status = net.route_packet(src, dst) if path is None: print(f"Routing failed: status") else: print(f"Path: src -> ' -> '.join(map(str, path))") print(f"Status: status") except: print("Use: send x1,y1 x2,y2") else: print("Unknown command. Try: send, down, up, show, quit") if == " main ": main() Example usage === 8x8 Mesh Network Utility === Commands: send <x1,y1> <x2,y2> | down/up <x,y> | show | quit > show 8x8 Network Grid (U=up, .=down): 0 1 2 3 4 5 6 7 0 U U U U U U U U 1 U U U U U U U U 2 U U U U U U U U 3 U U U U U U U U 4 U U U U U U U U 5 U U U U U U U U 6 U U U U U U U U 7 U U U U U U U U