image_output_1.png
import matplotlib.pyplot as plt

import networkx as nx

def knight_moves(pos):
    x, y = pos
    moves = [(x + 1, y + 2), (x + 1, y - 2), (x - 1, y + 2), (x - 1, y - 2), (x + 2, y + 1), (x + 2, y - 1), (x - 2, y + 1), (x - 2, y - 1)]
    return [(a, b) for a, b in moves if 0 <= a < 8 and 0 <= b < 8]

def create_chessboard_graph():
    chess_graph = nx.Graph()
    for x in range(8):
        for y in range(8):
            pos = (x, y)
            chess_graph.add_node(pos, pos=pos)
            for move in knight_moves(pos):
                chess_graph.add_edge(pos, move)
    return chess_graph

def draw_chessboard_graph(chess_graph):
    pos = nx.get_node_attributes(chess_graph, 'pos')

def create_maze_graph():
    maze_graph = nx.Graph()
    maze_graph.add_nodes_from(range(1, 22))
    maze_graph.add_edges_from([(1, 2), (2, 3), (2, 5), (5, 4), (5, 6), (6, 7), (6, 9), (9, 8), (9, 10), (10, 11), (10, 13), (13, 12), (13, 14), (14, 17), (14, 15), (14, 21), (17, 16), (17, 18), (21, 19), (21, 22), (18, 20), (18, 21)])
    return maze_graph

def draw_maze_graph(maze_graph):
    pos = nx.spring_layout(maze_graph, seed=1)
    nx.draw(maze_graph, pos, with_labels=True, node_size=500)
    nx.draw_networkx_labels(maze_graph, {x: (y[0], y[1] - 0.08) for x, y in pos.items()}, labels=dict(maze_graph.degree()), font_size=10)
    plt.show()
maze_graph = create_maze_graph()
draw_maze_graph(maze_graph)