Exemplo n.º 1
0
def createKnightGraph(boardSize):             #this function creates the graph that
    knightGraph = Graph()                     #will be used in the tour.  "boardSize" is the length of 
    for row in range(boardSize):              #a row or column of the chess board
        for col in range(boardSize):
            nodeId = assignNodeId(row,col,boardSize)         #calls helper function to create nodes in the graph
            newPositions = genLegalMoves(row,col,boardSize)  #calls helper function to generate legal moves from a node
            for e in newPositions:
                nid = assignNodeId(e[0],e[1],boardSize)
                knightGraph.addEdge(nodeId,nid)              #adds edge between initial node and all legal knight's moves
    return knightGraph
Exemplo n.º 2
0
def makeSpecificGraph():
    # Set up graph
    graph = Graph()

    v1 = Vertex(2,3)
    graph.addVertex(v1)

    v2 = Vertex(0,0)
    graph.addVertex(v2)
    
    dist = v1.EuclidDist(v2)
    e = Edge(v1, v2, dist, False)
    graph.addEdge(e)

    v3 = Vertex(4,5)
    graph.addVertex(v3)
    
    e2 = Edge(v1, v3, v3.EuclidDist(v1), True)
    graph.addEdge(e2)

    v4 = Vertex(10,20)
    graph.addVertex(v4)

    e3 = Edge(v3, v4, v3.EuclidDist(v4), False)
    graph.addEdge(e3)
    return graph
Exemplo n.º 3
0
def tests():
    v1 = Vertex(2,3)
    v2 = Vertex(0,0)
    v1.print_out()
    v2.print_out()
    print "\n"
    
    dist = v1.EuclidDist(v2)
    e = Edge(v1, v2, dist, False)

    graph = Graph()

    graph.addVertex(v1)
    graph.addVertex(v2)
    graph.addEdge(e)
    graph.print_adjmatrix()
    graph.print_vertexlst()

    v3 = Vertex(4,5)
    graph.addVertex(v3)
    e2 = Edge(v1, v3, v3.EuclidDist(v1), True)
    graph.addEdge(e2)
    print("Real Print starts here ")
    graph.print_graph()