All pastes #758472 Raw Edit

Unnamed

public c v1 · immutable
·published 2007-11-02 08:57 UTC
rendered paste body
// connectNodes - add edge between from and to nodes with colour and ownervoid connectNodes(GameBoard gameBoard, Node from, Node to, int distance, Colour colour, Owner owner) {    assert(gameBoard != NULL); // check that game board has been created    assert(from < gameBoard->numberOfNodes);    assert(to < gameBoard->numberOfNodes);    assert(from != to); // it is a simple game board so no self loops    assert(distance >= 0); // only positive distances    // add edge from -> to    struct adjacencyList *fromEdge = (struct adjacencyList *) malloc (sizeof(struct adjacencyList));    assert(fromEdge != NULL);    fromEdge->to = to;    fromEdge->distance=distance;    fromEdge->colour=colour;    fromEdge->owner=owner;    fromEdge->nextEdge = gameBoard->nodes[from];    gameBoard->nodes[from] = fromEdge;        // add edge from -> to    struct adjacencyList *toEdge = (struct adjacencyList *) malloc (sizeof(struct adjacencyList));    assert(toEdge != NULL);    toEdge->to = from;    toEdge->distance=distance;    toEdge->colour=colour;        toEdge->owner=owner;    toEdge->nextEdge = gameBoard->nodes[to];    gameBoard->nodes[to] = toEdge;   }// isConnected - is fromLocation directly connected with toLocation by colour and// owned by owner// NOTE 1: returns length of connection if connected and 0 if no connectionint isConnected(GameBoard gameBoard, Node fromNode, Node toNode, Colour colour, Owner owner) {    assert(gameBoard != NULL);    assert(fromNode >= 0 && fromNode < gameBoard->numberOfNodes);    assert(toNode >= 0 && toNode < gameBoard->numberOfNodes);      int connection=0; //returns a length if connected or 0 if not//    int i=0;    printf("number of nodes: %d\n",numberOfNodes(gameBoard));    printf("number of edges: %d\n",numberOfEdges(gameBoard));    struct adjacencyList *tmp = (struct adjacencyList *) malloc (sizeof(struct adjacencyList));    assert(tmp != NULL);    tmp=gameBoard->nodes[fromNode];        printf("from owner: %d\n",tmp->owner);    /*