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
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" 8x8 network utility
def set_node_state(self, node, state): if node in self.nodes and state in ["up", "down"]: self.nodes[node] = state return True return False while True: cmd = input("\n> ")
> 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 while True: cmd = input("\n>
> send 0,0 7,7 Routing failed: Node (4,0) is down — path blocked
class MeshNetwork: def (self, size=8): self.size = size self.nodes = {} for x in range(size): for y in range(size): self.nodes[(x, y)] = "up" # all nodes initially up
return path, "Success"