Beispiel #1
0
def knightGraph(bdSize):
    ktGraph = DFS_Graph()
    for row in range(bdSize):
        for col in range(bdSize):
            nodeId = posToNodeId(row, col, bdSize)
            newPositions = genLegalMoves(row, col, bdSize)
            for e in newPositions:
                nid = posToNodeId(e[0], e[1], bdSize)
                ktGraph.add_edge(nodeId, nid)
    return ktGraph
Beispiel #2
0

def knightGraph(bdSize):
    ktGraph = DFS_Graph()
    for row in range(bdSize):
        for col in range(bdSize):
            nodeId = posToNodeId(row, col, bdSize)
            newPositions = genLegalMoves(row, col, bdSize)
            for e in newPositions:
                nid = posToNodeId(e[0], e[1], bdSize)
                ktGraph.add_edge(nodeId, nid)
    return ktGraph


if __name__ == "__main__":
    g = DFS_Graph()
    g.add_edge("a", "b")
    g.add_edge("a", "d")

    g.add_edge("b", "c")
    g.add_edge("b", "d")

    g.add_edge("d", "e")

    g.add_edge("e", "b")
    g.add_edge("e", "f")

    g.add_edge("f", "c")

    path = g.compile("a")
    print("\n".join([str(el) for el in path]))