Exemple #1
0
//prints out the results for the canReachInN function 
// with values of n from 0 to 3, from all 
//starting locations, via all transport types
void showCanReach(Graph g){
    int n, t;
    Location loc;
    for(n = 0; n <= 3; n++){
        printf("n is %d\n", n);
        for(loc = 0; loc < NUM_MAP_LOCATIONS; loc++){
            for(t = LAND; t <= ANY; t++){
                Location locations[NUM_MAP_LOCATIONS] = {0};
                canReachInN(g, loc, t, n, locations);
                printLocations(locations);
            }
        }
    }
}
Exemple #2
0
void canReachInN(HunterView g, LocationID start, int type, int n, int locs[]){
   //IMPLEMENT FOR TASK 3
   
    locs[start] = 1;
    Node curr = g->connections[start];
    while (curr != NULL){
        if (type == curr->type || type == ANY) {
            int m;
            for (m = 0; m < n; m++) {
                canReachInN(g, curr->location, type, m, locs);
            }
        }
        curr = curr->next;
    }
    
}
Exemple #3
0
//This function returns an array of LocationID that represent all locations that are connected 
//to the given LocationID. 
//road, rail and sea are connections should only be considered if the road, rail, sea parameters 
//are TRUE.
//The size of the array should be stored in the variable pointed to by numLocations
//The array can be in any order but must contain unique entries
//Your function must take into account the round and player id for rail travel
//Your function must take into account that dracula can't move to the hospital or travel by rail
//but need not take into account draculas trail
//The destination 'from' should be included.
LocationID * connectedLocations(HunterView currentView, int * numLocations, LocationID from, 
                              PlayerID player, Round round, int road, int rail, int sea) {
	//this should come from graph file. 
	//this function alters the value pointed to be the pointer numLocations
    
    assert(road == FALSE || road == TRUE);
    assert(rail == FALSE || rail == TRUE);
    assert(sea == FALSE || sea == TRUE);    
    
	//conditions that need to be considered
	
	LocationID to_search = NUM_MAP_LOCATIONS;
	int moves_allowed = round % 4;
	if (!moves_allowed) rail = FALSE;
	if (player == PLAYER_DRACULA) rail = FALSE;
	if (!sea) to_search = ZURICH + 1; //Zurich is the last city

	Graph g = newGraph(); //our graph to check
	int i;
	*numLocations = 0;
	LocationID *connected;//[NUM_MAP_LOCATIONS];
	connected = malloc(sizeof(LocationID)*NUM_MAP_LOCATIONS);
	int locationsFound[NUM_MAP_LOCATIONS]; //using this later
	for (i = 0; i < NUM_MAP_LOCATIONS; i++) {
		connected[i] = -1;
		locationsFound[i] = FALSE;
	}
	i = 0;
	int found;
	while (i < to_search) {
		found = FALSE;

		if (road) {
			//don't need to check for duplicates here, all connections will be uninitialized
			if (isAdjacent(g,from, i, ROAD)) {
				connected[*numLocations] = i;
				(*numLocations)++;
				found = TRUE;
			}
		}
		if ((sea)&&(!found)) {
			if (isAdjacent(g,from, i, SEA)) {
				connected[*numLocations] = i;
				(*numLocations)++;
				found = TRUE;
			}
		}
		if (found) locationsFound[i] = TRUE; 
		i++;
	}
	
 	if (rail) { 
		//now we consider being able to move further by train
		//only do the check for the further cities if the condition of mod 4 is met
		//check places within two moves
		LocationID connected_by_rail[NUM_MAP_LOCATIONS];
		for (i = 0; i < NUM_MAP_LOCATIONS; i++) connected_by_rail[i] = FALSE;
		canReachInN(g, from, RAIL, moves_allowed, connected_by_rail);
		int j = 0;
		while (j < NUM_MAP_LOCATIONS) {
			if (!locationsFound[j]) {
				
				if (connected_by_rail[j]) {
					connected[*numLocations] = j;
					(*numLocations)++;
					locationsFound[j] = TRUE;
				}
			}
			j++;
		}	
	} 
	if (!locationsFound[from]) {
		connected[*numLocations] = from;
		(*numLocations)++; 
	}
	return connected;
}
Exemple #4
0
//This function returns an array of LocationID that represent all locations that are connected 
//to the given LocationID. 
//road, rail and sea are connections should only be considered if the road, rail, sea parameters 
//are TRUE.
//The size of the array should be stored in the variable pointed to by numLocations
//The array can be in any order but must contain unique entries
//Your function must take into account the round and player id for rail travel
//Your function must take into account that dracula can't move to the hospital or travel by rail
//but need not take into account draculas trail
//Any location that the player is currently in, should be included.
LocationID * connectedLocations(HunterView currentView, int * numLocations, LocationID from, 
                                PlayerID player, Round round, int road, int rail, int sea){
    // TRUE 1
    // FALSE 0
    // TAKEN FROM GRAPH.C WEEK 9.
    // GET WHERE CURRENT PLAYER IS. 
    LocationID *result = malloc(sizeof(int)*NUM_MAP_LOCATIONS);

    Node current = currentView->connections[from];
    current = current->next;
    
    result[0]=from;
    int checker;
    int counter;
    // TO CHECK AND GIVE INDICATION WHETHER ITS ROAD, RAIL OR SEA.
    if(road == TRUE){
        checker = LAND;
    }else if(sea == TRUE){
        checker = SEA;
    }else if(road == TRUE && sea == TRUE){
        checker = ANY;
    }

    counter = 1;

    // MEANS THIS IS HUNTER
    if((road == TRUE && sea == FALSE ) || 
       (road == FALSE && sea == TRUE ) || 
       (road == TRUE && sea == TRUE  ) ) 
    {
        
        //printf ("it comes here\n");
        if(checker == ANY){
            
            while(current != NULL){

                if(current->type != RAIL){


                    int arrayChecker;
                    int somethingEqual = FALSE;
                    for(arrayChecker=0; arrayChecker<counter; arrayChecker++){
                        if (result[arrayChecker] == current->location)
                        {
                            somethingEqual = TRUE;
                        }
                    }

                    if (!somethingEqual) {
                        result[counter] = current->location;
                    counter++;
                    }



                    if(player == PLAYER_DRACULA && current->location == ST_JOSEPH_AND_ST_MARYS){
                        // TO SKIP THIS PART. 
                        current = current -> next;
                    }
                    
                }

                current = current -> next;
                
            }

            *numLocations = counter;


        }else{

           
            //printf ("it comes here\n");
            while(current != NULL){

                if (current->type == checker)
                {
                    //printf ("it comes here counter %d\n", counter);
                    // CHECK WHETHER THERE IS ANY DUPLICATE OR NOT.
                    
                    int arrayChecker;
                    int somethingEqual = FALSE;
                    for(arrayChecker=0; arrayChecker<counter; arrayChecker++){
                        if (result[arrayChecker] == current->location)
                        {
                            somethingEqual = TRUE;
                        }
                    }

                    if (!somethingEqual) {
                        result[counter] = current->location;
                        counter++;
                    }
                    
                    if(player == PLAYER_DRACULA && current->location == ST_JOSEPH_AND_ST_MARYS){
                        // TO SKIP THIS PART. 
                        //printf ("it comes here BLA BLA %d\n", counter);
                        current = current -> next;
                    }
                    
                    
                }
                current = current -> next;
            }
            //printf ("COUNTER %d\n", counter);
            *numLocations = counter;


        }
        
        // FOR DEBUGGING PURPOSES.
        
        /*    int counter99;

            for(counter99=0; counter99< NUM_MAP_LOCATIONS; counter99++){
                //printf("number zero is %d\n", result[0]);

                if(result[counter99] != 0){
                    printf("the CITY inside array[%d] result is %d\n", counter99, result[counter99]);
                }
                
            }
            printf("\n");*/
        
    }else if(rail == TRUE && player != PLAYER_DRACULA){

        int railSum;
        int sum;

        sum = round + player;

        railSum = sum % 4;

        printf("railSum is %d\n", railSum );


        
        if(railSum == 0){
            // NO MOVE AVAILABLE
            *numLocations = counter;
            return result;
        }else if(railSum == 1){
            printf("COMES HERE2\n");
            // MOVE ONE AWAY BY RAIL

            while(current != NULL){

                if (current->type == RAIL)
                {
                    int arrayChecker;
                    int somethingEqual = FALSE;
                    for(arrayChecker=0; arrayChecker<counter; arrayChecker++){
                        if (result[arrayChecker] == current->location)
                        {
                            somethingEqual = TRUE;
                        }
                    }

                    if (!somethingEqual) {
                    result[counter] = current->location;
                    counter++;
                    }
                    
                    
                }
            current = current -> next;

            *numLocations = counter;
            }

        }else if(railSum == 2){

            // MOVE UP TO 2 PLACES BY RAIL
           int *num2 = malloc(sizeof(int)*NUM_MAP_LOCATIONS);
           canReachInN(currentView, from, RAIL, 2, num2);
           int cityCounter;

           for(cityCounter=0; cityCounter<NUM_MAP_LOCATIONS; cityCounter++){

                if(num2[cityCounter] == 1){

                    int finalChecker;
                    int somethingEqual;

                    for(finalChecker=0; finalChecker<counter; finalChecker++){
                            if (result[finalChecker] == current->location)
                            {
                                somethingEqual = TRUE;
                            }
                        }

                        if (!somethingEqual) {
                        result[counter] = cityCounter;
                        counter++;
                        }
                }
           }
        

        *numLocations = counter;
            

        }else if(railSum == 3){

            // MOVE UP TO 3 PLACES BY RAIL
           int *num3 = malloc(sizeof(int)*NUM_MAP_LOCATIONS);
           canReachInN(currentView, from, RAIL, 3, num3);
           int cityCounter;

           for(cityCounter=0; cityCounter<NUM_MAP_LOCATIONS; cityCounter++){

                if(num3[cityCounter] == 1){

                    int finalChecker;
                    int somethingEqual;

                    for(finalChecker=0; finalChecker<counter; finalChecker++){
                            if (result[finalChecker] == current->location)
                            {
                                somethingEqual = TRUE;
                            }
                        }

                        if (!somethingEqual) {
                        result[counter] = cityCounter;
                        counter++;
                        }
                }
           }
            

        }
        
        // FOR DEBUGGING PURPOSES.
        int counter99;

            for(counter99=0; counter99< NUM_MAP_LOCATIONS; counter99++){
                //printf("number zero is %d\n", result[0]);

                if(result[counter99] != 0){
                    printf("the CITY inside array[%d] result is %d\n", counter99, result[counter99]);
                }
                
            }
        printf("\n");

  }
    
  
  return result;

}