コード例 #1
0
ファイル: hunter.c プロジェクト: bradywatkinson/1927ass2
//makes the message of a follower
static void makeMessageFollower(HunterView h, int player, char *out)
{
	int round = giveMeTheRound(h);
	int score = 0;
	int extra = 0;
	if (giveMeTheRound(h) == 0) {
		if(player == PLAYER_LORD_GODALMING) {score = -1;}
		else if(player == PLAYER_DR_SEWARD) {score = 0;}
		else if(player == PLAYER_VAN_HELSING) {score = 1;}
		else if(player == PLAYER_MINA_HARKER) {score = 2;}
	} else if (round == 1 && player == PLAYER_LORD_GODALMING) {
		score = 3;
	} else if (isHunterDead(h,player)) {
		extra = 50;
	} else {
		
		int currLoc;
		if (player == PLAYER_LORD_GODALMING) currLoc = whereIs(h,PLAYER_MINA_HARKER);
		else currLoc = whereIs(h,player-1);
		int foundDrac = FALSE;
		LocationID dracTrail[TRAIL_SIZE];
		giveMeTheTrail(h,PLAYER_DRACULA,dracTrail);
		
		int i;
		for(i=0;i<TRAIL_SIZE;i++) {
			if (currLoc == dracTrail[i]) {
				score = i;
				foundDrac = TRUE;
				break;
			}
		}
	
		int ignore1;
		char ignore2;
		int ignore3;
		
		int turn = giveMeTurnNum(h);

		if (!foundDrac) {
			sscanf(messages[turn-NUM_PLAYERS],"%d %c %d %d",&ignore1,&ignore2,&score,&ignore3);
			score++;
		}
	}
	
	if (player == current_leader) {
		int leader_trail[TRAIL_SIZE];
		giveMeTheTrail(h,current_leader,leader_trail);
		if (leader_trail[0]==leader_trail[1] && leader_trail[1]==leader_trail[2]) {
			extra+=50;
		}
	}
	
	int outscore = score+extra;
	sprintf(out,"0 . %d -1",outscore);
}
コード例 #2
0
// Get the current location id of a given player
LocationID whereIs(DracView dv, PlayerID player) {
   int location;

   int round;
   round = giveMeTheRound(dv);
   // location = getRoundLocation(dv, round, PLAYER_DRACULA);
   location = getLocation(dv->gv, player);

      /*
      #define HIDE                    102
      #define DOUBLE_BACK_1           103
      #define DOUBLE_BACK_2           104
      #define DOUBLE_BACK_3           105
      #define DOUBLE_BACK_4           106
      #define DOUBLE_BACK_5           107
      #define TELEPORT                108
      */   
   
   while (location >= HIDE && location <= TELEPORT && round >= 0) {
      round -= 1;
      location = getRoundLocation(dv, round, PLAYER_DRACULA);
   }

   return location;
}
コード例 #3
0
// Creates a new HunterView to summarise the current state of the game
HunterView newHunterView(char *pastPlays, PlayerMessage messages[])
{
    HunterView hunterView = malloc(sizeof(struct hunterView));
    assert(hunterView!=NULL);
    hunterView->g = newGameView(pastPlays,messages);

    int rounds = giveMeTheRound(hunterView);
    hunterView->messages = malloc(sizeof(PlayerMessage)*rounds);
    int i;
    for (i=0;i<rounds;i++) {
        strncpy(hunterView->messages[i], messages[i], MESSAGE_SIZE);
    }
    return hunterView;
}
コード例 #4
0
ファイル: dracula.c プロジェクト: chrism-/1927_assignment2
void decideDraculaMove(DracView gameState)
{	
    char* nextPos = NULL;

   	if (giveMeTheRound(gameState) == 0){
      nextPos = "MR";
  	} else {
        int numLocations;
        LocationID* possibleDest = whereCanIgo(gameState, &numLocations, 1, 0);

        srand((unsigned int)time(NULL)); //seed random

        nextPos = idToName(possibleDest[rand()%numLocations]);
	}

	PlayerMessage msg = "Dracula MSG";

	registerBestPlay(nextPos,msg);
}
コード例 #5
0
// What are the specified player's next possible moves
// FREE THIS ARRAY IN THE AI
LocationID *whereCanTheyGo(DracView currentView, int *numLocations,
                        PlayerID player, int road, int rail, int sea) {

    LocationID *locations;

   // Remember to free the array retured from connectedLocations 
   // if you use it in the AI
   if (player == PLAYER_DRACULA) {
      locations = whereCanIgo(currentView, numLocations, road, sea);
   
   } else {
      locations = connectedLocations(currentView->gv, numLocations, \
                                 whereIs(currentView, player), \
                                 player, (giveMeTheRound(currentView)+1), \
                                 road, rail, sea);
   }

   return locations;
}
コード例 #6
0
LocationID *returnConLocs(DracView currentView, int *numLocations) {

   LocationID *locations;
   LocationID myLocation;
   int road;
   int rail;
   int sea;

   myLocation = whereIs(currentView, PLAYER_DRACULA);
   road = 1;
   rail = 0;
   sea = 0;

   locations = connectedLocations(currentView->gv, numLocations, 
                  myLocation, PLAYER_DRACULA, 
                  giveMeTheRound(currentView), road, rail, sea);

   return locations;
}
コード例 #7
0
ファイル: testDracView.c プロジェクト: Nick1221/COMP1927
int main()

{

    int i;

    DracView dv;



//NEW SET

    printf("Test for basic functions, just before Dracula's first move\n");

    PlayerMessage messages1[] = {"Hello","Rubbish","Stuff",""};

    dv = newDracView("GST.... SAO.... HZU.... MBB....", messages1);

    assert(giveMeTheRound(dv) == 0);

    assert(whereIs(dv,PLAYER_LORD_GODALMING) == STRASBOURG);

    assert(whereIs(dv,PLAYER_DR_SEWARD) == ATLANTIC_OCEAN);

    assert(whereIs(dv,PLAYER_VAN_HELSING) == ZURICH);

    assert(whereIs(dv,PLAYER_MINA_HARKER) == BAY_OF_BISCAY);

    assert(whereIs(dv,PLAYER_DRACULA) == UNKNOWN_LOCATION);

    assert(howHealthyIs(dv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS);

    printf("passed\n");

    disposeDracView(dv);



//NEW SET

    printf("Test for encountering Dracula and hunter history\n");

    PlayerMessage messages2[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!","","",""};

    dv = newDracView("GST.... SAO.... HCD.... MAO.... DGE.... "

                     "GGED... SAO.... HCD.... MAO....", messages2);

    assert(giveMeTheRound(dv) == 1);

    assert(whereIs(dv,PLAYER_DRACULA) == GENEVA);

    assert(howHealthyIs(dv,PLAYER_LORD_GODALMING) == 5);

    assert(howHealthyIs(dv,PLAYER_DRACULA) == 30);

    assert(whereIs(dv,PLAYER_LORD_GODALMING) == GENEVA);

    LocationID history[TRAIL_SIZE];

    giveMeTheTrail(dv,PLAYER_DRACULA,history);

    assert(history[0] == GENEVA);

    assert(history[2] == UNKNOWN_LOCATION);

    giveMeTheTrail(dv,PLAYER_LORD_GODALMING,history);

    assert(history[0] == GENEVA);

    assert(history[1] == STRASBOURG);

    assert(history[2] == UNKNOWN_LOCATION);

    giveMeTheTrail(dv,PLAYER_DR_SEWARD,history);

    assert(history[0] == ATLANTIC_OCEAN);

    assert(history[1] == ATLANTIC_OCEAN);

    assert(history[2] == UNKNOWN_LOCATION);

    printf("passed\n");        

    disposeDracView(dv);



//NEW SET

    printf("Test for Dracula leaving minions\n");

    PlayerMessage messages3[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!","","","","Drop a V","Party in Strasbourg","Party","Party","Party"};

    dv = newDracView("GGE.... SGE.... HGE.... MGE.... DED.V.. "

                     "GST.... SST.... HST.... MST.... DMNT... "

                     "GST.... SST.... HST.... MST....", messages3);

    int nT, nV;

    whatsThere(dv,EDINBURGH,&nT,&nV);

    assert(nT == 0 && nV == 1);

    whatsThere(dv,MANCHESTER,&nT,&nV);

    assert(nT == 1 && nV == 0);

    assert(whereIs(dv,PLAYER_DRACULA) == MANCHESTER);

    giveMeTheTrail(dv,PLAYER_DRACULA,history);

    assert(history[0] == MANCHESTER);

    assert(history[1] == EDINBURGH);

    assert(history[2] == UNKNOWN_LOCATION);

    giveMeTheTrail(dv,PLAYER_MINA_HARKER,history);

    assert(history[0] == STRASBOURG);

    assert(history[1] == STRASBOURG);

    assert(history[2] == GENEVA);

    assert(history[3] == UNKNOWN_LOCATION);

    printf("passed\n");

    disposeDracView(dv);



//NEW SET

    printf("Test for connections\n");

    int size, seen[NUM_MAP_LOCATIONS], *edges;



    printf("Checking Galatz road connections\n");

    PlayerMessage messages5[] = {"Gone to Galatz"};

    dv = newDracView("GGA....", messages5);

    edges = whereCanTheyGo(dv,&size,PLAYER_LORD_GODALMING,1,0,0);

    memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int));

    for (i = 0; i< size ; i++) seen[edges[i]] = 1;

    assert(size == 5); assert(seen[GALATZ]); assert(seen[CONSTANTA]);

    assert(seen[BUCHAREST]); assert(seen[KLAUSENBURG]); assert(seen[CASTLE_DRACULA]);

    free(edges);

    disposeDracView(dv);



    printf("Checking Ionian Sea sea connections\n");

    PlayerMessage messages6[] = {"Sailing the Ionian"};

    dv = newDracView("GIO....", messages6);

    edges = whereCanTheyGo(dv,&size,PLAYER_LORD_GODALMING,0,0,1);

    memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int));

    for (i = 0; i < size; i++) seen[edges[i]] = 1;

    assert(size == 7); assert(seen[IONIAN_SEA]); assert(seen[BLACK_SEA]);

    assert(seen[ADRIATIC_SEA]); assert(seen[TYRRHENIAN_SEA]);

    assert(seen[ATHENS]); assert(seen[VALONA]); assert(seen[SALONICA]);

    free(edges);

    disposeDracView(dv);



    printf("Checking Athens rail connections (none)\n");

    PlayerMessage messages7[] = {"Leaving Athens by train"};

    dv = newDracView("GAT....", messages7);

    edges = whereCanTheyGo(dv,&size,PLAYER_LORD_GODALMING,0,1,0);

    assert(size == 1);

    assert(edges[0] == ATHENS);

    free(edges);

    disposeDracView(dv);

    printf("passed\n");



//NEW SET

    printf("test for mature vampire (drac view)\n");

    PlayerMessage messages8[] = {"im sorry i'm lazy", "copy paste is a great thing"};

    dv= newDracView("GST.... SAO.... HCD.... MBO.... DLET... " //0

                    "GST.... SAO.... HCD.... MNA.... DPAT... " //1

                    "GST.... SAO.... HCD.... MCF.... DSTT... " //2

                    "GSTT... SAO.... HCD.... MGE.... DZUT... " //3 -2 LG

                    "GST.... SAO.... HCD.... MZUTD.. DCDT... " //4 trap at castle dracula??? -10hp drac, -6hp mina harker, +2LG, + 10hp drac

                    "GST.... SAO.... HCDTD.. MZU.... DGAT... " //5 + 3hp mina harker -6hp van helsing, -10 hp drac

                    "GST.... SAO.... HGATD.. MZU.... DCNT.M. " //6 -6hp vh (van helsing dies), -10hp drac, +3 mina marker

                    "GST.... SAO.... HSZ.... MMU.... DBS..M. " //7 -2hp dracula, helsing been in hospital

                    "GST.... SAO.... HKL.... MZA.... DCDT.M. " //8 +10hp drac

                    "GST.... SAO.... HKL.... MZA.... DCDT.M. " //9 +10hp drac

                    "GST.... SAO.... HCDTTD. MZA.... DCDT.M. " //10 -8hp vn, drac is constant

                    "GST.... SAO.... HGA.... MZA.... DKLT.M. " //11 +3hp vh

                    "GST.... SAO.... HGA.... MZA.... DBE.VM. " //12 +3hp vh

                    "GST.... SAO.... HGA.... MZA.... DSOT... " //13 +2hp vh

                    "GST.... SAO.... HCDTTT. MZA.... DSJT.M. " //14 -6hp vh

                    "GST.... SAO.... HCD.... MZA.... DVET.M. " //15 +3hp vh

                    "GST.... SAO.... HCD.... MZA.... DZAT.M. " //16 +3hp vh

                    "GMU.... SAO.... HCD.... MZA.... DVIT.M. " //17 

                    "GVITD.. SAO.... HCD.... MZA.... DPRT... " //18 -6LG, -10 drac

                    "GVI.... SAO.... HCD.... MZA.... DCDT.V.", messages8); //19 +3 LG

    //basically copied from testGameView...

    //making sure the basics of drac view works

    assert(giveMeTheRound(dv)==20);

    assert(giveMeTheScore(dv)==GAME_START_SCORE -20 -6 -13);

    assert(howHealthyIs(dv, PLAYER_LORD_GODALMING)==GAME_START_HUNTER_LIFE_POINTS-3);

    assert(howHealthyIs(dv, PLAYER_DR_SEWARD)==GAME_START_HUNTER_LIFE_POINTS);

    assert(howHealthyIs(dv, PLAYER_VAN_HELSING)==GAME_START_HUNTER_LIFE_POINTS);

    assert(howHealthyIs(dv, PLAYER_MINA_HARKER)==GAME_START_HUNTER_LIFE_POINTS);

    assert(whereIs(dv, PLAYER_LORD_GODALMING)==VIENNA);

    assert(whereIs(dv, PLAYER_DR_SEWARD)==ATLANTIC_OCEAN);

    assert(whereIs(dv, PLAYER_VAN_HELSING)==CASTLE_DRACULA);

    assert(whereIs(dv, PLAYER_MINA_HARKER)==ZAGREB);

    

    giveMeTheTrail(dv,PLAYER_DRACULA,history);

    assert(history[0] == CASTLE_DRACULA);

    assert(history[1] == PRAGUE); 

    assert(history[2] == VIENNA);  

    assert(history[3] == ZAGREB);   

    assert(history[4] == VENICE);  

    assert(history[5] == SARAJEVO); 

    giveMeTheTrail(dv,PLAYER_LORD_GODALMING,history);

    assert(history[0] == VIENNA);

    assert(history[1] == VIENNA); 

    assert(history[2] == MUNICH);  

    assert(history[3] == STRASBOURG);

    giveMeTheTrail(dv,PLAYER_DR_SEWARD,history);

    assert(history[0] == ATLANTIC_OCEAN);

    assert(history[1] == ATLANTIC_OCEAN);

    assert(history[2] == ATLANTIC_OCEAN);

    assert(history[3] == ATLANTIC_OCEAN);

    assert(history[4] == ATLANTIC_OCEAN);

    assert(history[5] == ATLANTIC_OCEAN);



    //start and end are the same for all

    int start, end;

    lastMove(dv, PLAYER_LORD_GODALMING, &start, &end);

    assert(start==VIENNA && end==VIENNA); 

    lastMove(dv, PLAYER_DR_SEWARD, &start, &end);

    assert(start==ATLANTIC_OCEAN && end==ATLANTIC_OCEAN); 

    lastMove(dv, PLAYER_VAN_HELSING, &start, &end);

    assert(start==CASTLE_DRACULA && end==CASTLE_DRACULA); 

    lastMove(dv, PLAYER_MINA_HARKER, &start, &end);

    assert(start==ZAGREB && end==ZAGREB); 

    disposeDracView(dv);

    printf("passed\n");



//NEW SET

    printf("test more many traps\n"); 

    PlayerMessage messages9[] = {"hey look!, something new..."};

    dv= newDracView("GST.... SAO.... HCD.... MBO.... DLET... "

                    "GCO.... SIR.... HGA.... MNA.... DD1T...",messages9 );

    int nnT, nnV;

    whatsThere(dv,LE_HAVRE,&nnT,&nnV);

    assert(nnT == 2 && nnV == 0);

    assert(giveMeTheRound(dv)==2);

    assert(giveMeTheScore(dv)==GAME_START_SCORE -2);

    

    lastMove(dv, PLAYER_LORD_GODALMING, &start, &end);

    assert(start==STRASBOURG && end==COLOGNE); 

    lastMove(dv, PLAYER_DR_SEWARD, &start, &end);

    assert(start==ATLANTIC_OCEAN && end==IRISH_SEA); 

    lastMove(dv, PLAYER_VAN_HELSING, &start, &end);

    assert(start==CASTLE_DRACULA && end==GALATZ); 

    lastMove(dv, PLAYER_MINA_HARKER, &start, &end);

    assert(start==BORDEAUX && end==NANTES);



    //more basics

    giveMeTheTrail(dv,PLAYER_LORD_GODALMING,history);

    assert(history[0] == COLOGNE);

    assert(history[1] == STRASBOURG); 

    assert(history[2] == UNKNOWN_LOCATION); 

    giveMeTheTrail(dv,PLAYER_DR_SEWARD,history);

    assert(history[0] == IRISH_SEA);

    assert(history[1] == ATLANTIC_OCEAN); 

    assert(history[2] == UNKNOWN_LOCATION); 

    giveMeTheTrail(dv,PLAYER_VAN_HELSING,history);

    assert(history[0] == GALATZ);

    assert(history[1] == CASTLE_DRACULA); 

    assert(history[2] == UNKNOWN_LOCATION); 

    giveMeTheTrail(dv,PLAYER_MINA_HARKER,history);

    assert(history[0] == NANTES);

    assert(history[1] == BORDEAUX); 

    assert(history[2] == UNKNOWN_LOCATION);    

    assert(history[3] == UNKNOWN_LOCATION);

    assert(history[4] == UNKNOWN_LOCATION);

    assert(history[5] == UNKNOWN_LOCATION);             

    disposeDracView(dv);

    printf("passed\n"); 



//NEW SET

    printf("test for dracula paths (where can i go)\n");

    //int size, seen[NUM_MAP_LOCATIONS], *edges; -->declared at top    

    PlayerMessage messages10[] = {"going from le havre"};

    dv= newDracView("GST.... SAO.... HCD.... MBO.... DLET...", messages10);

    printf("Checking Le Havre Road connections\n");

    edges = whereCanIgo(dv, &size, 1,0);

    memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int));

    for (i = 0; i< size ; i++) seen[edges[i]] = 1;

    assert(size==4);

    assert(seen[LE_HAVRE]); assert(seen[NANTES]); assert(seen[PARIS]); 

    assert(seen[BRUSSELS]);

    free(edges);

    printf("Checking Le Havre boat connections\n");

    edges = whereCanIgo(dv, &size, 0,1);

    memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int));

    for (i = 0; i< size ; i++) seen[edges[i]] = 1;    

    assert(size==2); //only one boat

    assert(seen[LE_HAVRE]); assert(seen[ENGLISH_CHANNEL]);

    free(edges);

    disposeDracView(dv);



    PlayerMessage messages11[] = {"going from bucharest"};

    dv= newDracView("GST.... SAO.... HCD.... MBO.... DBCT...", messages11);

    printf("Checking bucharest road connections\n");

    edges = whereCanIgo(dv, &size, 1,0);

    memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int));

    for (i = 0; i< size ; i++) seen[edges[i]] = 1;

    assert(size==6); 

    assert(seen[BUCHAREST]); assert(seen[BELGRADE]); assert(seen[CONSTANTA]); 

    assert(seen[GALATZ]); assert(seen[KLAUSENBURG]); assert(seen[SOFIA]);

    free(edges);

    disposeDracView(dv);



    PlayerMessage messages12[] = {"going from galway"};

    dv= newDracView("GST.... SAO.... HCD.... MBO.... DGWT...", messages12);

    printf("Checking galway road AND boat connections\n");

    edges = whereCanIgo(dv, &size, 1,1);

    memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int));

    for (i = 0; i< size ; i++) seen[edges[i]] = 1;

    assert(size==3); 

    assert(seen[GALWAY]); assert(seen[DUBLIN]); assert(seen[ATLANTIC_OCEAN]);

    free(edges);

    disposeDracView(dv);

    

    PlayerMessage messages13[] = {"going from cologne"};

    dv= newDracView("GST.... SAO.... HCD.... MBO.... DCOT...", messages13);

    printf("Checking cologne boat connections (none)\n");

    edges = whereCanIgo(dv, &size, 0,1);

    memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int));

    for (i = 0; i< size ; i++) seen[edges[i]] = 1;

    assert(size==1); assert(seen[COLOGNE]);

    free(edges);

    disposeDracView(dv);

    printf("passed\n");



//NEW SET

    printf("test for double back in train when seeing where dracula goes \n");

    PlayerMessage messages14[] = {"going from cologne","to cologne lol"};

    dv= newDracView("GST.... SAO.... HCD.... MBO.... DCOT... " 

                    "GST.... SAO.... HCD.... MBO.... DD1T...", messages14);

    edges = whereCanIgo(dv, &size, 0,1);

    //cannot have another double back so cannot stay in cologne via boat       

    assert(size==1); //cant hide at sea

    free(edges);

      

    edges = whereCanIgo(dv, &size, 1,0);

    memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int));

    for (i = 0; i< size ; i++) seen[edges[i]] = 1;

    assert(size==7);

    assert(seen[COLOGNE]); //can hide in city again

    assert(seen[AMSTERDAM]); assert(seen[BRUSSELS]); assert(seen[FRANKFURT]);

    assert(seen[HAMBURG]); assert(seen[LEIPZIG]); assert(seen[STRASBOURG]);

    free(edges);

    disposeDracView(dv);    

    printf("passed\n");



//NEW SET

    printf("check for hide AND double back\n");

    dv= newDracView("GST.... SAO.... HCD.... MBO.... DCOT... " 

                    "GST.... SAO.... HCD.... MBO.... DD1T... "

                    "GST.... SAO.... HCD.... MBO.... DHI....", messages14);

    edges = whereCanIgo(dv, &size, 0,1);

    //cannot have another double back so cannot stay in cologne via boat       

    assert(size==0); //cant hide at sea

    free(edges);

      

    edges = whereCanIgo(dv, &size, 1,0);

    memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int));

    for (i = 0; i< size ; i++) seen[edges[i]] = 1;

    assert(size==6);

    assert(seen[AMSTERDAM]); assert(seen[BRUSSELS]); assert(seen[FRANKFURT]);

    assert(seen[HAMBURG]); assert(seen[LEIPZIG]); assert(seen[STRASBOURG]);

    free(edges);

    disposeDracView(dv);    

    printf("passed\n");

    

    return 0;

}
コード例 #8
0
void decideHunterMove(HunterView gameState)
{

    int dracLocation;   // don't call when round is 0
    int myLocation;     // don't call when round is 0

    // get the current round number
    Round roundNum = giveMeTheRound(gameState);
    
    // current hunter
    PlayerID hunter = whoAmI(gameState);
    printf("My life points are: %d\n", howHealthyIs(gameState, hunter));

    // health of current player
    //int currentHealth = howHealthyIs(gameState, hunter);

    srand(time(NULL));
    //srand(time(NULL));

    //LocationID whereIs(HunterView currentView, PlayerID player);

    // Mina setup at castle dracula for whole game
    // camp at KL/GA. if drac is at DC, then move to DC
    if (hunter == PLAYER_LORD_GODALMING) {

        if (roundNum == 0) {
            registerBestPlay("KL", "First round..");

        } else {
            dracLocation = whereIs(gameState, PLAYER_DRACULA);
            myLocation = whereIs(gameState, hunter);
            printf("--- mylocation: %d, draclocation: %d\n", myLocation, dracLocation);
            // drac is at castle dracula. if i'm at SZ/KL then move there
            if (dracLocation == CASTLE_DRACULA &&
                (myLocation == GALATZ || myLocation == KLAUSENBURG || myLocation == CASTLE_DRACULA)) {  

                registerBestPlay("CD", "Drac is at CD! Attack!");

            }else if(dracLocation == myLocation){
		registerBestPlay(idToAbbrev(myLocation),"Drac is Here I'm Staying");
	    }else if((roundNum%RESEARCH_ROUND) == 0 && roundNum != 1){
		registerBestPlay(idToAbbrev(myLocation),"Lets Just Rest Here");
	    } else {
                // drac isn't at CD, or I'm not near there. 
                // camp at Klausenburg/Galatz or return from hospital
                if (myLocation == KLAUSENBURG) {
                    registerBestPlay("GA", "Klausenburg -> Galatz");

                } else if (myLocation == GALATZ) {
                    registerBestPlay("KL", "Galatz -> Klausenburg");

                } else if (myLocation == ST_JOSEPH_AND_ST_MARYS) {
                    registerBestPlay("SZ", "I died. Heading Back To the Castle");

                } else if (myLocation == SZEGED) {
                    registerBestPlay("KL", "Heading Back To the Castle");

                } else if (myLocation == CASTLE_DRACULA) {
                    registerBestPlay("KL", "Castle Drac -> Klausenburg");
                }
            }
        }

    // hunters other than mina harker
    // for round zero, spawn hunters in spanned out locations on map
    } else if (roundNum == 0) {
        switch (hunter) {
        case PLAYER_MINA_HARKER: registerBestPlay("MA", "I'm starting at Madrid");
            break;
        case PLAYER_DR_SEWARD: registerBestPlay("FR", "I'm starting at Frankfurt");
            break;
        case PLAYER_VAN_HELSING: registerBestPlay("ZA", "I'm starting at Szeged");
            break;
        }

    // randomised location
    } else {
        myLocation = whereIs(gameState, hunter);

	LocationID goToID = goToDrac(gameState, myLocation, roundNum, hunter);

	char *goTo = idToAbbrev(goToID);

    	registerBestPlay(goTo, "Never Stop Looking For Drac.");
    }
}
コード例 #9
0
ファイル: hunter.c プロジェクト: bradywatkinson/1927ass2
void decideHunterMove(HunterView gameState)
{

	int turn = giveMeTurnNum(gameState);
	messages = malloc(sizeof(PlayerMessage)*turn);
	getMessages(gameState,messages);
	

	int current_player = whoAmI(gameState);
	srand(time(NULL));
	//initialises current_leader global variable
	int current_round = giveMeTheRound(gameState);
	int current_rank = getRank(gameState, current_player, current_round);
	PlayerMessage message = "";

	int leader_trail[TRAIL_SIZE];
	giveMeTheTrail(gameState,current_leader,leader_trail);

	printf("current leader is %d\n",current_leader);

	printf("LT->");
	int j;
	for (j=0;j<TRAIL_SIZE;j++){
		printf("%d->",leader_trail[j]);
	}
	printf("x\n");
	
	int drac_trail[TRAIL_SIZE];
	giveMeTheTrail(gameState,PLAYER_DRACULA,drac_trail);

	printf("DT->");
	int m;
	for (m=0;m<TRAIL_SIZE;m++){
		printf("%d->",drac_trail[m]);
	}
	printf("x\n");	

	int move;
	char *moveTo;
	
	printf("check %d %d\n",current_round,current_leader);
	if (current_round == 0) {
		if(current_player == PLAYER_LORD_GODALMING) {move = PLAYER1_START_POS;}
		else if(current_player == PLAYER_DR_SEWARD) {move = PLAYER2_START_POS;}
		else if(current_player == PLAYER_VAN_HELSING) {move = PLAYER3_START_POS;}
		else if(current_player == PLAYER_MINA_HARKER) {move = PLAYER4_START_POS;}
		else printf("I am noone..\n");
		makeMessageFollower(gameState, current_player, message);
	} else if (current_player == current_leader) {
		printf("I am the leader\n");
		move = makeRandomMove2(gameState,current_player);
		moveTo = idToAbbrev(move);
		registerBestPlay(moveTo,message);
		move = makeLeaderMove(gameState,message);
	} else {
		printf("I am a follower");
		move = makeRandomMove2(gameState,current_player);
		moveTo = idToAbbrev(move);
		registerBestPlay(moveTo,message);
		printf(" and I am making a move\n");
		
		move = makeFollowerMove(gameState, current_player, current_rank);
		makeMessageFollower(gameState, current_player, message);
	}
	
	printf("move is %d\n",move);
	
	moveTo = idToAbbrev(move);
	registerBestPlay(moveTo,message);
}
コード例 #10
0
ファイル: hunter.c プロジェクト: bradywatkinson/1927ass2
LocationID makeLeaderMove (HunterView h, char *out)
{
	//'C' or '.' form conga
	//'E' explode
	//'H' hunt TODO
	
	int move;
	
	int ignore;
	
	char incode;
	char outcode;
	
	int inactionTurns;
	int outactionTurns;
	
	int intarget;
	int outtarget;
	
	int player = current_leader;
	int turn = giveMeTurnNum(h);
	int myLoc = whereIs(h,player);
	
	LocationID dracTrail[TRAIL_SIZE];
	giveMeTheTrail(h,PLAYER_DRACULA,dracTrail);
	
	sscanf(messages[turn-NUM_PLAYERS],"%d %c %d %d",&inactionTurns,&incode,&ignore,&intarget);
	
	//GENERATES move, outactionturns, outcode and out target
	if (incode == 'E' && inactionTurns < EXPLODE_TURNS) {//continue exploding
		printf("Continue explode\n");
		move = explode(h,player);
		outactionTurns = inactionTurns+1;
		outcode = 'E';
		outtarget = -1;
	} else if (incode == 'R') { //after a rest, reset target to that location
		printf("Locking onto drac\n");
		if (dracTrail[5] >= MIN_MAP_LOCATION && dracTrail[5] <= MAX_MAP_LOCATION) {
			int path[NUM_MAP_LOCATIONS];
			findHunterPath(h, myLoc, dracTrail[5], path, TRUE, TRUE, TRUE);
			move = path[1];
			outtarget = dracTrail[5];
		} else {
			move = makeRandomMove2(h,player);
			outtarget = -1;
		}
		outactionTurns = inactionTurns+1;
		outcode = '.';
		
	} else if (incode == 'E' && inactionTurns == EXPLODE_TURNS) { //rest
		printf("Explode got nowhere. Resting!\n");
		move = whereIs(h,player);
		outactionTurns = 0;
		outcode = 'R';
		outtarget = -1;
	} else if (myLoc == intarget) { //decide when to explode
		printf("INITIATE EXPLODE\n");
		move = explode(h,player);
		outactionTurns = 0;
		outcode = 'E';
		outtarget = -1;
	} else if (incode == '.' && inactionTurns == TURNS_UNTIL_REST) { //rest
		printf("Dracula has escaped. I need to research!\n");
		move = whereIs(h,player);
		outactionTurns = 0;
		outcode = 'R';
		outtarget = -1;
	}  else {
		printf("Business as usual\n");
		
		int tmpLoc = -1;
		int j;
		for(j=0;j<TRAIL_SIZE;j++) {
			if (dracTrail[j] >= MIN_MAP_LOCATION && dracTrail[j] <= MAX_MAP_LOCATION) {
				tmpLoc = dracTrail[j];
				break;
			}
		}
		
		if (tmpLoc != -1) outtarget = tmpLoc;
		else if (intarget != -1) outtarget = intarget;
		else outtarget = -1;		
		
		outactionTurns = inactionTurns+1;
		outcode = '.';
		
		if (outtarget != -1) {
			int path[NUM_MAP_LOCATIONS];
			findHunterPath(h, myLoc, outtarget, path, TRUE, TRUE, TRUE);
			move = path[1];
		} else move = makeRandomMove2(h,player);
	}
	
	
	//GENERATES outscore
	int inscore = 0;
	int outscore = 0;
	if(giveMeTheRound(h) == 1 && player == PLAYER_LORD_GODALMING) {
		outscore = 3;
	} else {
		int currLoc;
		if (player == PLAYER_LORD_GODALMING) currLoc = whereIs(h,PLAYER_MINA_HARKER);
		else 								 currLoc = whereIs(h,(player-1));

		int foundDrac = FALSE;
		
		int i;
		for(i=0;i<TRAIL_SIZE;i++) {
			if (currLoc == dracTrail[i]) {
				outscore = i;
				foundDrac = TRUE;
				//printf("someone is on drac's trail[%d] location: %d\n",i,currLoc);
				break;
			}
		}
	
		int ignore1;
		char ignore2;
		int ignore3;
		
		if (!foundDrac) {
			//printf("no one is on drac's trail\n");			
			sscanf(messages[turn-NUM_PLAYERS],"%d %c %d %d",&ignore1,&ignore2,&inscore,&ignore3);
			outscore = inscore + 1;
		}
	}
	
	sprintf(out,"%d %c %d %d",outactionTurns,outcode,outscore,outtarget);
	
	return move;
}
コード例 #11
0
ファイル: dracula.c プロジェクト: jasonvly/furiousdracula
void decideDraculaMove(DracView gameState)
{
    int round = giveMeTheRound(gameState);

    if (round == 0) {
        registerBestPlay("GA","");
    } else if (round == 1){
		registerBestPlay("CD","");
	} else if (round == 2){
		registerBestPlay("KL","");
	} else if (round == 3){
		registerBestPlay("D1","");
    } else if (round == 4){
        registerBestPlay("HI","");
    } else if (round == 5){
        registerBestPlay("TP","");
    } else if (round == 6){
        registerBestPlay("TP","");
	} else {   

   
    // Populate dracTrail with last 6 moves made
    int *dracTrail = calloc(sizeof(int),6);
    giveMeTheTrail(gameState, 4, dracTrail);
    
    // === PREDETERMINE HIDE AND DOUBLE BACK ===
    // Determine if hide has been used in trail. 
    // Returns HIDING = 0 if you can't hide, and 1 if you can.
    int hideCount = 0;
    int HIDING = 0;
    int reference0 = 0;
        
    while(hideCount < 6){
        if(dracTrail[hideCount] == 102){
            hideCount++; reference0++;
        } else hideCount++; 
    }
    if (reference0 == 0) HIDING = 1;
    
    // Can't hide at sea
    if (idToType(whereIs(gameState,4)) == SEA) { printf("At sea\n"); HIDING = 0; }
    
    // Determine if double back has been used in trail. 
    // Returns BACK = 0 if you can't hide, and 1 if you can.
    int backCount = 0;
    int BACK = 0;
    int reference1 = 0;
        
    while(backCount < 6){
        if(dracTrail[backCount] == 103){
            backCount++; reference1++;
        } else backCount++; 
    }
    if (reference1 == 0) BACK = 1;
    
       // === FIND LEGAL CONNECTED LAND AND WATER CONNECTIONS === //
    
                        // == BASIC MOVES == //
    
                            // = LAND = //
        
    // Populate landArray with possible connected LAND 
    // locations from current location
	int numLocations;
    int *landArray = whereCanIgo(gameState,&numLocations,1, 0);
    int landLength = numLocations;
    
    // Works out if we have already gone through a location in our
    // trail.
    // Each location in dracTrail is compared to every
    // location in landArray. 
    // If they're the same, that entry in landArray is changed
    // to -1, meaning we cannot move there, and landLength shortened.
    int count = 0;
    int x = 0;
        
    while(x < numLocations){
        while(count < 6){
            if(dracTrail[count] == landArray[x]){
                landArray[x] = -1;
                count = 8;
                landLength--;
            }else count++;
        }
        x++;
        count = 0;
    }
    
    // Make array as big as possible LAND moves for us is.
    int *landMoves = calloc(sizeof(int),landLength);
    
    // Little loop to transfer possible LAND moves into the new array
    int a = 0; int b = 0;
    while(a < numLocations){
        if(landArray[a] != -1){
            landMoves[b] = landArray[a];
            a++;
            b++;
        } else a++;
    }
    
    printf("%d land length\n", landLength);
    
    // Register first available move (just for safety)
    registerBestPlay(idToAbbrev(landMoves[0]),"1");
    
                            // = WATER = //
        
    // Populate waterArray with possible connected WATER 
    // locations from current location
    int waterLocations;
    int *waterArray = whereCanIgo(gameState,&waterLocations,0,1);
    int waterLength = waterLocations;
        
    // Works out if we have already gone through a location in our
    // trail.
    // Each location in dracTrail is compared to every
    // location in waterArray. 
    // If they're the same, that entry in waterArray is changed
    // to -1, meaning we cannot move there, and waterLength shortened.
    count = 0; x = 0;
        
    while(x < waterLocations){
        while(count < 6){
            if(dracTrail[count] == waterArray[x]){
                waterArray[x] = -1;
                count = 8;
                waterLength--;
            } else count++;
        }
        x++;
        count = 0;
    }
    // Make array as big as possible WATER moves for us is.
    int *waterMoves = calloc(sizeof(int),waterLength);
    
    // Little loop to transfer possible WATER moves into the new array
    a = 0; b = 0;
    while(a < waterLocations){
        if(waterArray[a] != -1){
            waterMoves[b] = waterArray[a];
            a++;
            b++;
        } else a++;
    }
    
                        // = REGISTER BASIC MOVE = //
        
    // Register first available move (just for safety)
    registerBestPlay(idToAbbrev(landMoves[0]),"1");
    
    // Check if no LAND move has been registered. If it hasn't, register
    // basic water move.
    if (landLength == 0) registerBestPlay(idToAbbrev(waterMoves[0]),"2");
    
    // Check if no basic LAND or WATER move has been registered. If not,
    // hide OR double back.
    if ((landLength == 0) && (waterLength == 0)) {
        if (HIDING == 1) {
            registerBestPlay("HI","3");
        } else if ((HIDING == 0) && (BACK == 1)) {
            registerBestPlay("D1","4");
        } else registerBestPlay("TP", "5");
    }
    
                            // == COMPLEX MOVES == //
    
    // Populate the hunter arrays with the possible moves that they can make
    // - both LAND and WATER
    int *hunter0Moves; int *hunter1Moves;
    int *hunter2Moves; int *hunter3Moves;
        
    int hunter0Locations; int hunter1Locations;
    int hunter2Locations; int hunter3Locations;
        
    hunter0Moves = whereCanTheyGo(gameState,&hunter0Locations,0,TRUE,TRUE,TRUE);
    hunter1Moves = whereCanTheyGo(gameState,&hunter1Locations,1,TRUE,TRUE,TRUE);
    hunter2Moves = whereCanTheyGo(gameState,&hunter2Locations,2,TRUE,TRUE,TRUE);
    hunter3Moves = whereCanTheyGo(gameState,&hunter3Locations,3,TRUE,TRUE,TRUE);
        
    // Attempting to determine the next move by working out
    // where we have been, where we can go, and if the hunters
    // can also go there in their next move, makes us safer!

    int hunter0Count = 0; int hunter1Count = 0;
    int hunter2Count = 0; int hunter3Count = 0; int dracCount = 0;
    int safeLength = landLength; int ref = 0;
        
    // Checking whether the possible LAND moves for Dracula
    // are possible LAND moves for the hunters
    // Note: we do not follow this check for water moves because...
    // WE DON'T CARE ABOUT MATCHING WATER MOVES!
    
    // This works by changing entries in the landMoves to -1
    // when there is a risk their move will be the same as our move
    while(dracCount < landLength){
        while(hunter0Count < hunter0Locations){
            if(hunter0Moves[hunter0Count] == landMoves[dracCount]){
            	landMoves[dracCount] = -1;                    
				dracCount++;
                hunter0Count = hunter0Locations; hunter1Count = hunter1Locations;
                hunter2Count = hunter2Locations; hunter3Count = hunter3Locations;
			    safeLength--;
            }else hunter0Count++;
        }
        while(hunter1Count < hunter1Locations){
            if(hunter1Moves[hunter1Count] == landMoves[dracCount]){
	        	landMoves[dracCount] = -1;                    
                dracCount++;
                hunter1Count = hunter1Locations; hunter2Count = hunter2Locations;
                hunter3Count = hunter3Locations;

			    safeLength--;
            }else hunter1Count++;
        }
        while(hunter2Count < hunter2Locations){
            if(hunter2Moves[hunter2Count] == landMoves[dracCount]){
	        	landMoves[dracCount] = -1;                 
                dracCount++;
                hunter2Count = hunter2Locations; hunter3Count = hunter3Locations;
				safeLength--;
                }else hunter2Count++;
            }
        while(hunter3Count < hunter3Locations){
            if(hunter3Moves[hunter3Count] == landMoves[dracCount]){
		        landMoves[dracCount] = -1;                
                dracCount++;
                hunter3Count = hunter3Locations;
				safeLength--;
            }else hunter3Count++;
        }
        //reset the counters, and if the dracCount hasn't already been incremented during the movement,
        hunter0Count = 0; hunter1Count = 0; hunter2Count = 0; hunter3Count = 0;
        if(dracCount == ref){
	    	dracCount++;
        }
        ref++;
    }
    
    // After changing the move list to the -1s, we must create a new array
    // of possible safe moves we can make.
    
    // Make array as big as possible SAFE LAND moves for us is.
    int *safeMoves = calloc(sizeof(int), safeLength);
    
    // Little loop to transfer possible SAFE LAND moves into the new array
    a = 0; b = 0;
    while(a < landLength){
        if(landMoves[a] != -1){
            safeMoves[b] = landMoves[a];
            a++;
            b++;
        } else a++;
    }
        printf("Number of Safe Moves: %d\n",safeLength);
        printf("Number of Water Moves: %d\n",waterLength);
                    // == REGISTER A SAFE MOVE == //
    if (safeLength > 0) registerBestPlay(idToAbbrev(safeMoves[0]),"7");
    
                        // == SMART MOVES == //
    if (safeLength == 0){
        // If greater than 20 health, move towards them anyway
        // (make a safe move next round if available)
        if((howHealthyIs(gameState,4) > 20) && (waterLength > 0)) {
                registerBestPlay(idToAbbrev(waterMoves[0]),"8");
        // If less than 20, try hiding or double backing.
        } else {
            if(HIDING == 1) {
                registerBestPlay("HI","9");
            } else if ((HIDING == 0) && (BACK == 1)) {
                registerBestPlay("D1","10");
            }
        }
    }
    
                        // == LAST RESORT MOVES == //
    // No moves available, TP 
    if ((landLength == 0) && (waterLength == 0)) {
        if (HIDING == 1) {
            registerBestPlay("HI","11");
        } else if ((HIDING == 0) && (BACK == 1)) {
            registerBestPlay("D1","12");
        } else registerBestPlay("TP", "13");
    }
    
    }

}
コード例 #12
0
ファイル: testDracView.c プロジェクト: kotarou3/COMP1927-Labs
int main()
{
    int i;
    DracView dv;


    printf("Test for basic functions, just before Dracula's first move\n");
    PlayerMessage messages1[] = {"Hello","Rubbish","Stuff",""};
    dv = newDracView("GST.... SAO.... HZU.... MBB....", messages1);
    assert(giveMeTheRound(dv) == 0);
    assert(whereIs(dv,PLAYER_LORD_GODALMING) == STRASBOURG);
    assert(whereIs(dv,PLAYER_DR_SEWARD) == ATLANTIC_OCEAN);
    assert(whereIs(dv,PLAYER_VAN_HELSING) == ZURICH);
    assert(whereIs(dv,PLAYER_MINA_HARKER) == BAY_OF_BISCAY);
    assert(whereIs(dv,PLAYER_DRACULA) == UNKNOWN_LOCATION);
    assert(howHealthyIs(dv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS);
    printf("passed\n");
    disposeDracView(dv);

    printf("Test for encountering Dracula and hunter history\n");
    PlayerMessage messages2[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!","","",""};
    dv = newDracView("GST.... SAO.... HCD.... MAO.... DGE.... "
                     "GGED... SAO.... HCD.... MAO....", messages2);
    assert(giveMeTheRound(dv) == 1);
    assert(whereIs(dv,PLAYER_DRACULA) == GENEVA);
    assert(howHealthyIs(dv,PLAYER_LORD_GODALMING) == 5);
    assert(howHealthyIs(dv,PLAYER_DRACULA) == 30);
    assert(whereIs(dv,PLAYER_LORD_GODALMING) == GENEVA);
    LocationID history[TRAIL_SIZE];
    giveMeTheTrail(dv,PLAYER_DRACULA,history);
    assert(history[0] == GENEVA);
    assert(history[2] == UNKNOWN_LOCATION);
    giveMeTheTrail(dv,PLAYER_LORD_GODALMING,history);
    assert(history[0] == GENEVA);
    assert(history[1] == STRASBOURG);
    assert(history[2] == UNKNOWN_LOCATION);
    giveMeTheTrail(dv,PLAYER_DR_SEWARD,history);
    assert(history[0] == ATLANTIC_OCEAN);
    assert(history[1] == ATLANTIC_OCEAN);
    assert(history[2] == UNKNOWN_LOCATION);
    printf("passed\n");
    disposeDracView(dv);

    printf("Test for Dracula leaving minions\n");
    PlayerMessage messages3[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!","","","","Drop a V","Party in Strasbourg","Party","Party","Party"};
    dv = newDracView("GGE.... SGE.... HGE.... MGE.... DED.V.. "
                     "GST.... SST.... HST.... MST.... DMNT... "
                     "GST.... SST.... HST.... MST....", messages3);
    int nT, nV;
    whatsThere(dv,EDINBURGH,&nT,&nV);
    assert(nT == 0 && nV == 1);
    whatsThere(dv,MANCHESTER,&nT,&nV);
    assert(nT == 1 && nV == 0);
    assert(whereIs(dv,PLAYER_DRACULA) == MANCHESTER);
    giveMeTheTrail(dv,PLAYER_DRACULA,history);
    assert(history[0] == MANCHESTER);
    assert(history[1] == EDINBURGH);
    assert(history[2] == UNKNOWN_LOCATION);
    giveMeTheTrail(dv,PLAYER_MINA_HARKER,history);
    assert(history[0] == STRASBOURG);
    assert(history[1] == STRASBOURG);
    assert(history[2] == GENEVA);
    assert(history[3] == UNKNOWN_LOCATION);
    printf("passed\n");
    disposeDracView(dv);

    printf("Test for connections\n");
    int size, seen[NUM_MAP_LOCATIONS], *edges;

    printf("Checking Galatz road connections\n");
    PlayerMessage messages5[] = {"Gone to Galatz"};
    dv = newDracView("GGA....", messages5);
    edges = whereCanTheyGo(dv,&size,PLAYER_LORD_GODALMING,1,0,0);
    memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int));
    for (i = 0; i< size ; i++) seen[edges[i]] = 1;
    assert(size == 5); assert(seen[GALATZ]); assert(seen[CONSTANTA]);
    assert(seen[BUCHAREST]); assert(seen[KLAUSENBURG]); assert(seen[CASTLE_DRACULA]);
    free(edges);
    disposeDracView(dv);

    printf("Checking Ionian Sea sea connections\n");
    PlayerMessage messages6[] = {"Sailing the Ionian"};
    dv = newDracView("GIO....", messages6);
    edges = whereCanTheyGo(dv,&size,PLAYER_LORD_GODALMING,0,0,1);
    memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int));
    for (i = 0; i < size; i++) seen[edges[i]] = 1;
    assert(size == 7); assert(seen[IONIAN_SEA]); assert(seen[BLACK_SEA]);
    assert(seen[ADRIATIC_SEA]); assert(seen[TYRRHENIAN_SEA]);
    assert(seen[ATHENS]); assert(seen[VALONA]); assert(seen[SALONICA]);
    free(edges);
    disposeDracView(dv);

    printf("Checking Athens rail connections (none)\n");
    PlayerMessage messages7[] = {"Leaving Athens by train"};
    dv = newDracView("GAT....", messages7);
    edges = whereCanTheyGo(dv,&size,PLAYER_LORD_GODALMING,0,1,0);
    assert(size == 1);
    assert(edges[0] == ATHENS);
    free(edges);
    disposeDracView(dv);

    printf("passed\n");
    return 0;
}
コード例 #13
0
// What are my (Dracula's) possible next moves (locations)
//
// * connectedLocations Conditions:
//
// connectedLocations() 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 is 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 Dracula's trail
// The destination 'from' should be included in the array
//
// FREE THIS ARRAY IN THE AI
//
// This function only returns a list of locations where duckula can go
// This does not include HIDE or DOUBLE_BACK. Will need to account for
// this somewhere.. somehow
LocationID *whereCanIgo(DracView currentView, int *numLocations,
                        int road, int sea) {

// whereCanIgo() returns an array of LocationIDs giving
//   all locations that Dracula could reach in his next move
// road and/or sea connections should only be considered
//   if the road and/or sea parameters are TRUE.
// The size of the array is stored in the variable pointed to by numLocations
// The array can be in any order but must contain unique entries
// Should not include the hospital nor any locations only reachable by rail
// The current location should be included in the array
// The set of possible locations must be consistent with the rules on Dracula's
//   movement (e.g. can't MOVE to a location currently in his trail)

   LocationID *locations;
   LocationID trail[TRAIL_SIZE];
   LocationID myLocation;
   int i;
   int j;
   int rail;

   rail = 0;
   myLocation = whereIs(currentView, PLAYER_DRACULA);
   // printf("in DV.c; whereCanIGo: myLocation: %d (%s)\n", myLocation, idToAbbrev(myLocation));

   // printf("here0 connectedLocations(%p, %d, %d, %d, %d, %d, %d, %d)\n", currentView->gv, *numLocations, whereIs(currentView, PLAYER_DRACULA), PLAYER_DRACULA, giveMeTheRound(currentView), road, rail, sea);
//   fprintf(stderr,"from %d, round %d\n", whereIs(currentView,PLAYER_DRACULA),giveMeTheRound(currentView));

   locations = connectedLocations(currentView->gv, numLocations, 
                  myLocation, PLAYER_DRACULA, 
                  giveMeTheRound(currentView), road, rail, sea);

   //fprintf(stderr, "in DV.c: connLocs: \n");
   //for (i = 0; i < *numLocations; i++) {
   //   fprintf(stderr, "\tlocations[%d]: %d (%s)\n", i, locations[i], idToAbbrev(locations[i]));
   //}

   getHistory(currentView->gv, PLAYER_DRACULA, trail);

   // check locations aren't in the trail except for trail[0] (current location)
   for (i = 0; i < *numLocations; i++) {
      // printf("in DV.c: locations[%d] = %d (%s)\n", i, locations[i], idToAbbrev(locations[i]));
      for (j = 0; j < TRAIL_SIZE; j++) {
         
         if (locations[i] == myLocation && idToType(myLocation) == SEA) {
            // I'm currently at sea. Remove currently location
            locations[i] = -1;

            int h;

            // shuffle the locations one index to the 'left'
            for (h = i; h < *numLocations; h++) {
               if ((h+1) < *numLocations) {
                  locations[h] = locations[h+1];
               }
            }
            *numLocations -= 1;

         } else if (locations[i] == trail[j] && locations[i] != UNKNOWN_LOCATION && j != 0) {
            // this location is in the trail, remove it
            // printf("in DV.c: locations[%d] (%d : %s) == trail[%d] (%d : %s)\n", i, locations[i], idToAbbrev(locations[i]), j, trail[j], idToAbbrev(trail[j]));
            locations[i] = -1;
            // printf("\tupdated locations[%d] -> %d\n", i, locations[i]);

            int h;

            // shuffle the locations one index to the 'left'
            for (h = i; h < *numLocations; h++) {
               if ((h+1) < *numLocations) {
                  locations[h] = locations[h+1];
               }
            }

            *numLocations -= 1;
         }
      }
   }

   //fprintf(stderr, "new locs: \n");
   //for (i = 0; i < *numLocations; i++) {
   //       fprintf(stderr, "\tin DV.c: locations[%d] (%d : %s)\n", i, locations[i], idToAbbrev(locations[i]));
   //}

   return locations;
}
コード例 #14
0
ファイル: testDracView.c プロジェクト: Shanush/FODFantastic5
int main()
{
    int i;
    DracView dv;


    printf("Test for basic functions, just before Dracula's first move\n");
    PlayerMessage messages1[] = {"Hello","Rubbish","Stuff",""};
    dv = newDracView("GST.... SAO.... HZU.... MBB....", messages1);
    assert(giveMeTheRound(dv) == 0);
    assert(whereIs(dv,PLAYER_LORD_GODALMING) == STRASBOURG);
    assert(whereIs(dv,PLAYER_DR_SEWARD) == ATLANTIC_OCEAN);
    assert(whereIs(dv,PLAYER_VAN_HELSING) == ZURICH);
    assert(whereIs(dv,PLAYER_MINA_HARKER) == BAY_OF_BISCAY);
    assert(whereIs(dv,PLAYER_DRACULA) == UNKNOWN_LOCATION);
    assert(howHealthyIs(dv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS);
    printf("passed\n");
    disposeDracView(dv);

    printf("Test for encountering Dracula and hunter history\n");
    PlayerMessage messages2[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!","","",""};
    dv = newDracView("GST.... SAO.... HCD.... MAO.... DGE.... "
                     "GGED... SAO.... HCD.... MAO....", messages2);
    assert(giveMeTheRound(dv) == 1);
    assert(whereIs(dv,PLAYER_DRACULA) == GENEVA);
    assert(howHealthyIs(dv,PLAYER_LORD_GODALMING) == 5);
    assert(howHealthyIs(dv,PLAYER_DRACULA) == 30);
    assert(whereIs(dv,PLAYER_LORD_GODALMING) == GENEVA);
    LocationID history[TRAIL_SIZE];
    giveMeTheTrail(dv,PLAYER_DRACULA,history);
    assert(history[0] == GENEVA);
    assert(history[2] == UNKNOWN_LOCATION);
    giveMeTheTrail(dv,PLAYER_LORD_GODALMING,history);
    assert(history[0] == GENEVA);
    assert(history[1] == STRASBOURG);
    assert(history[2] == UNKNOWN_LOCATION);
    giveMeTheTrail(dv,PLAYER_DR_SEWARD,history);
    assert(history[0] == ATLANTIC_OCEAN);
    assert(history[1] == ATLANTIC_OCEAN);
    assert(history[2] == UNKNOWN_LOCATION);
    printf("passed\n");        
    disposeDracView(dv);

    printf("Test for Dracula leaving minions\n");
    PlayerMessage messages3[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!","","","","Drop a V","Party in Strasbourg","Party","Party","Party"};
    dv = newDracView("GGE.... SGE.... HGE.... MGE.... DED.V.. "
                     "GST.... SST.... HST.... MST.... DMNT... "
                     "GST.... SST.... HST.... MST....", messages3);
    int nT, nV;
    whatsThere(dv,EDINBURGH,&nT,&nV);
    assert(nT == 0 && nV == 1);
    whatsThere(dv,MANCHESTER,&nT,&nV);
    assert(nT == 1 && nV == 0);
    assert(whereIs(dv,PLAYER_DRACULA) == MANCHESTER);
    giveMeTheTrail(dv,PLAYER_DRACULA,history);
    assert(history[0] == MANCHESTER);
    assert(history[1] == EDINBURGH);
    assert(history[2] == UNKNOWN_LOCATION);
    giveMeTheTrail(dv,PLAYER_MINA_HARKER,history);
    assert(history[0] == STRASBOURG);
    assert(history[1] == STRASBOURG);
    assert(history[2] == GENEVA);
    assert(history[3] == UNKNOWN_LOCATION);
    printf("passed\n");
    disposeDracView(dv);
    // needs further work - double back 2 not working
    dv = newDracView("GGE.... SGE.... HGE.... MGE.... DED.V.. "
                     "GST.... SST.... HST.... MST.... DHIT... "
                     "GST.... SST.... HST.... MST.... DMNT... "
                     "GST.... SST.... HST.... MST.... DD2T...", messages3);
    whatsThere(dv,EDINBURGH,&nT,&nV);
    assert(nV == 1);
    whatsThere(dv, MANCHESTER, &nT, &nV);
    assert(nT == 1 && nV == 0);
    whatsThere(dv,EDINBURGH,&nT,&nV);
    assert(nT == 2 && nV == 1);
    dv = newDracView("GGE.... SGE.... HGE.... MGE.... DED.V.. "
                     "GST.... SST.... HST.... MST.... DHIT... "
                     "GST.... SST.... HST.... MST.... DMNT... "
                     "GST.... SST.... HST.... MST.... DD1T...", messages3);
    whatsThere(dv,EDINBURGH,&nT,&nV);
    assert(nV == 1);
    whatsThere(dv, MANCHESTER, &nT, &nV);
    assert(nT == 2 && nV == 0);
    whatsThere(dv,EDINBURGH,&nT,&nV);
    assert(nT == 1 && nV == 1);
    dv = newDracView("GGE.... SGE.... HGE.... MGE.... DED.V.. "
                     "GST.... SST.... HST.... MST.... DHIT... "
                     "GST.... SST.... HST.... MST.... DMNT... "
                     "GST.... SST.... HST.... MST.... DD3T...", messages3);
    whatsThere(dv,EDINBURGH,&nT,&nV);
    assert(nV == 1);
    whatsThere(dv, MANCHESTER, &nT, &nV);
    assert(nT == 1 && nV == 0);
    whatsThere(dv,EDINBURGH,&nT,&nV);
    assert(nT == 2 && nV == 1);
    printf("Our test right here\n");
    dv = newDracView("GGE.... SGE.... HGE.... MGE.... DED.V.. "
                     "GST.... SST.... HST.... MST.... DHIT... "
                     "GST.... SST.... HST.... MST.... DMNT... "
                     "GGE.... SGE.... HGE.... MGE.... DLVT... "
                     "GST.... SST.... HST.... MST.... DD3T...", messages3);
    printf("called the funciton\n");
    whatsThere(dv,EDINBURGH,&nT,&nV);
    assert(nV == 1);
    printf("up to first ed\n");
    whatsThere(dv, MANCHESTER, &nT, &nV);
    assert(nT == 1 && nV == 0);
    whatsThere(dv, LIVERPOOL, &nT, &nV);
    assert(nT == 1 && nV == 0);
    whatsThere(dv,EDINBURGH,&nT,&nV);
    assert(nT == 2 && nV == 1);
    printf("passed our tests\n");
    
    //-------------------------
    
    // Visual inspection required!
    printf("\nConn. locs. tests. Eyeball for authenticity:\n");
    dv = newDracView("GGE.... SGE.... HGE.... MGE.... DED.V.. "
                     "GST.... SST.... HST.... MST.... DMNT... "
                     "GST.... SST.... HST.... MST.... DLOT...", messages3);
    int numlocations;
    LocationID *locations = whereCanIgo(dv, &numlocations, TRUE, FALSE);
    for (int i = numlocations-1; i >= 0; i--) {
        printf("Location is %d, aka %s\n", locations[i], idToName(locations[i]));
    }
    dv = newDracView("GGE.... SGE.... HGE.... MGE.... DED.V.. "
                     "GST.... SST.... HST.... MST.... DMNT... "
                     "GST.... SST.... HST.... MST.... DD2T...", messages3);
    locations = whereCanIgo(dv, &numlocations, TRUE, FALSE);
    for (int i = numlocations-1; i >= 0; i--) {
        printf("Location is %d, aka %s\n", locations[i], idToName(locations[i]));
    }
    dv = newDracView("GST.... SST.... HST.... MST.... DMNT... "
                     "GST.... SST.... HST.... MST.... DLOT... "
                     "GST.... SST.... HST.... MST.... DD2T... "
                     "GST.... SST.... HST.... MST.... DHIT... "
                     "GST.... SST.... HST.... MST....", messages3);
    locations = whereCanIgo(dv, &numlocations, TRUE, FALSE);
    for (int i = numlocations-1; i >= 0; i--) {
        printf("Location is %d, aka %s\n", locations[i], idToName(locations[i]));
    }
    printf("last devious test\n");
    dv = newDracView("GST.... SST.... HST.... MST.... DPRT... "
                     "GST.... SST.... HST.... MST.... DBRT... "
                     "GST.... SST.... HST.... MST.... DHAT... "
                     "GST.... SST.... HST.... MST.... DCOT... "
                     "GST.... SST.... HST.... MST.... DAMT... "
                     "GST.... SST.... HST.... MST.... DD3T... "
                     "GST.... SST.... HST.... MST.... DHIT... "
                     "GST.... SST.... HST.... MST....", messages3);
    locations = whereCanIgo(dv, &numlocations, TRUE, FALSE);
    for (int i = numlocations-1; i >= 0; i--) {
        printf("Location is %d, aka %s\n", locations[i], idToName(locations[i]));
    }
    printf("passed tricky conn. locs. tests\n");
    
    //-------------------------
    
    printf("Test for connections\n");
    int size, seen[NUM_MAP_LOCATIONS], *edges;

    printf("Checking Galatz road connections\n");
    PlayerMessage messages5[] = {"Gone to Galatz"};
    dv = newDracView("GGA....", messages5);
    edges = whereCanTheyGo(dv,&size,PLAYER_LORD_GODALMING,1,0,0);
    memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int));
    for (i = 0; i< size ; i++) seen[edges[i]] = 1;
    assert(size == 5); assert(seen[GALATZ]); assert(seen[CONSTANTA]);
    assert(seen[BUCHAREST]); assert(seen[KLAUSENBURG]); assert(seen[CASTLE_DRACULA]);
    free(edges);
    disposeDracView(dv);

    printf("Checking Ionian Sea sea connections\n");
    PlayerMessage messages6[] = {"Sailing the Ionian"};
    dv = newDracView("GIO....", messages6);
    edges = whereCanTheyGo(dv,&size,PLAYER_LORD_GODALMING,0,0,1);
    memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int));
    for (i = 0; i < size; i++) seen[edges[i]] = 1;
    assert(size == 7); assert(seen[IONIAN_SEA]); assert(seen[BLACK_SEA]);
    assert(seen[ADRIATIC_SEA]); assert(seen[TYRRHENIAN_SEA]);
    assert(seen[ATHENS]); assert(seen[VALONA]); assert(seen[SALONICA]);
    free(edges);
    disposeDracView(dv);

    printf("Checking Athens rail connections (none)\n");
    PlayerMessage messages7[] = {"Leaving Athens by train"};
    dv = newDracView("GAT....", messages7);
    edges = whereCanTheyGo(dv,&size,PLAYER_LORD_GODALMING,0,1,0);
    assert(size == 1);
    assert(edges[0] == ATHENS);
    free(edges);
    disposeDracView(dv);

    printf("passed\n");

    // Test whatsThere ()
    printf("Test whatsThere ()\n");
    PlayerMessage messages685[] = {"Hello","Rubbish","Stuff",""};
    dv = newDracView("GST.... SAO.... HZU.... MBB....", messages685);
    assert(giveMeTheRound(dv) == 0);
    assert(whereIs(dv,PLAYER_LORD_GODALMING) == STRASBOURG);
    assert(whereIs(dv,PLAYER_DR_SEWARD) == ATLANTIC_OCEAN);
    assert(whereIs(dv,PLAYER_VAN_HELSING) == ZURICH);
    assert(whereIs(dv,PLAYER_MINA_HARKER) == BAY_OF_BISCAY);
    assert(whereIs(dv,PLAYER_DRACULA) == UNKNOWN_LOCATION);
    assert(howHealthyIs(dv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS);
    printf("passed\n");
    disposeDracView(dv);

    // EXTRA TEST 1
    printf("extra test 1\n");
    PlayerMessage messages9[] = {"Hello","Rubbish","Stuff",""};
    dv = newDracView("GVI.... SZU.... HBB.... MSO....", messages9);
    assert(whereIs(dv, PLAYER_LORD_GODALMING) == VIENNA);
    assert(whereIs(dv, PLAYER_DR_SEWARD) == ZURICH);
    assert(whereIs(dv, PLAYER_VAN_HELSING) == BAY_OF_BISCAY);
    assert(whereIs(dv, PLAYER_MINA_HARKER) == SOFIA);
    assert(whereIs(dv, PLAYER_DRACULA) == UNKNOWN_LOCATION);
    assert(howHealthyIs(dv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS);
    disposeDracView(dv);
    printf("passed extra1!\n");

    // EXTRA TEST 2 - test putting traps twice
    printf("extra test 2\n");
    PlayerMessage messages10[] = {"Drop","party","at","Varrock"};
    dv = newDracView("GHA.... SMA.... HVR.... MBI.... DSZ.V.. "
                     "GCO.... SSR.... HSO.... MNP.... DZAT... "
                     "GFR.... STO.... HBE.... MRO....", messages10);
    assert(giveMeTheRound(dv) == 2);
    assert((giveMeTheScore(dv)) == (GAME_START_SCORE - (SCORE_LOSS_DRACULA_TURN*giveMeTheRound(dv))));
    
    assert(whereIs(dv, PLAYER_LORD_GODALMING) == FRANKFURT);
    assert(whereIs(dv, PLAYER_DR_SEWARD) == TOULOUSE);
    assert(whereIs(dv, PLAYER_VAN_HELSING) == BELGRADE);
    assert(whereIs(dv, PLAYER_MINA_HARKER) == ROME);
    assert(whereIs(dv, PLAYER_DRACULA) == ZAGREB);
    
    int numOfTraps, numOfVamps;
    whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 0 && numOfVamps == 1);
    whatsThere(dv,ZAGREB,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
//    whatsThere(dv,VIENNA,&numOfTraps,&numOfVamps);
//    assert(numOfTraps == 1 && numOfVamps == 0);

    assert(howHealthyIs(dv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS);
    disposeDracView(dv);
    printf("passed extra2!\n");

    // EXTRA TEST 3 - deleting traps once trail has passed
    printf("extra test 3!\n");
    PlayerMessage messages11[] = {"Drop","party","at","Varrock"};
    dv = newDracView("GHA.... SMA.... HVR.... MBI.... DSZT... "
                     "GCO.... SSR.... HSO.... MNP.... DZAT... "
                     "GFR.... STO.... HBE.... MRO.... DVIT... "
                     "GCO.... SSR.... HSO.... MNP.... DPRT... "
                     "GHA.... SMA.... HVR.... MBI.... DNUT... "
                     "GFR.... STO.... HBE.... MRO.... DSTT... "
                     "GHA.... SMA.... HVR.... MBI.... DPAT.M. "
                     "GHA.... SMA.... HVR.... MBI.... ", messages11);
    assert(giveMeTheRound(dv) == 7);
    assert((giveMeTheScore(dv)) == (GAME_START_SCORE - (SCORE_LOSS_DRACULA_TURN*giveMeTheRound(dv))));
    
    assert(whereIs(dv, PLAYER_LORD_GODALMING) == HAMBURG);
    assert(whereIs(dv, PLAYER_DR_SEWARD) == MADRID);
    assert(whereIs(dv, PLAYER_VAN_HELSING) == VARNA);
    assert(whereIs(dv, PLAYER_MINA_HARKER) == BARI);
    assert(whereIs(dv, PLAYER_DRACULA) == PARIS);
    
    LocationID dracTrail[6] = {0};
    giveMeTheTrail(dv, PLAYER_DRACULA, dracTrail);
    
    
    whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 0 && numOfVamps == 0);
    whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps);
    // since traps are destroyed after every 6 moves in the trail
    assert(numOfTraps == 0 && numOfVamps == 0);
    whatsThere(dv,VIENNA,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,PRAGUE,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,NUREMBURG,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,STRASBOURG,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,PARIS,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    
    disposeDracView(dv);
    printf("passed extra3!\n");


    printf("extra test 3!\n");
    dv = newDracView("GHA.... SMA.... HVR.... MBI.... DSZT... "
                     "GCO.... SSR.... HSO.... MNP.... DZAT... "
                     "GFR.... STO.... HBE.... MRO.... DVIT... "
                     "GCO.... SSR.... HSO.... MNP.... DPRT... "
                     "GHA.... SMA.... HVR.... MBI.... DNUT... "
                     "GFR.... STO.... HBE.... MRO.... DSTT... "
                     "GHA.... SMA.... HVR.... MBI.... DPAT.M. "
                     "GHA.... SMA.... HVR.... MBI.... ", messages11);
    assert(giveMeTheRound(dv) == 7);
    assert((giveMeTheScore(dv)) == (GAME_START_SCORE - (SCORE_LOSS_DRACULA_TURN*giveMeTheRound(dv))));
    
    assert(whereIs(dv, PLAYER_LORD_GODALMING) == HAMBURG);
    assert(whereIs(dv, PLAYER_DR_SEWARD) == MADRID);
    assert(whereIs(dv, PLAYER_VAN_HELSING) == VARNA);
    assert(whereIs(dv, PLAYER_MINA_HARKER) == BARI);
    assert(whereIs(dv, PLAYER_DRACULA) == PARIS);
    
    whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 0 && numOfVamps == 0);
    whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps);
    // since traps are destroyed after every 6 moves in the trail
    assert(numOfTraps == 0 && numOfVamps == 0);
    whatsThere(dv,VIENNA,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,PRAGUE,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,NUREMBURG,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,STRASBOURG,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,PARIS,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    
    disposeDracView(dv);
    printf("passed extra3!\n");

    printf("extra test 4!\n");
    dv = newDracView("GHA.... SMA.... HVR.... MBI.... DSZ.V.. "
                     "GCO.... SSR.... HSO.... MNP.... DZAT... "
                     "GFR.... STO.... HBE.... MRO.... DVIT... "
                     "GCO.... SSR.... HSO.... MNP.... DPRT... "
                     "GHA.... SMA.... HVR.... MBI.... DNUT... "
                     "GFR.... STO.... HBE.... MRO.... DSTT... "
                     "GHA.... SMA.... HVR.... MBI.... DPAT.V. "
                     "GHA.... SMA.... HVR.... MBI.... ", messages11);
    assert(giveMeTheRound(dv) == 7);
    assert((giveMeTheScore(dv)) == (GAME_START_SCORE - (SCORE_LOSS_DRACULA_TURN*giveMeTheRound(dv)) -
                                    SCORE_LOSS_VAMPIRE_MATURES));
    
    assert(whereIs(dv, PLAYER_LORD_GODALMING) == HAMBURG);
    assert(whereIs(dv, PLAYER_DR_SEWARD) == MADRID);
    assert(whereIs(dv, PLAYER_VAN_HELSING) == VARNA);
    assert(whereIs(dv, PLAYER_MINA_HARKER) == BARI);
    assert(whereIs(dv, PLAYER_DRACULA) == PARIS);
    
    
    whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 0 && numOfVamps == 0);
    whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps);
    // since traps are destroyed after every 6 moves in the trail
    assert(numOfTraps == 0 && numOfVamps == 0);
    whatsThere(dv,VIENNA,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,PRAGUE,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,NUREMBURG,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,STRASBOURG,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,PARIS,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    
    disposeDracView(dv);
    printf("passed extra4!\n");

    printf("extra test 5!\n");
    dv = newDracView("GHA.... SMA.... HVR.... MBI.... DSZ.V.. "
                     "GCO.... SSR.... HSO.... MNP.... DZAT... "
                     "GFR.... STO.... HBE.... MRO.... DVIT... "
                     "GCO.... SSR.... HSO.... MNP.... DPRT... "
                     "GHA.... SMA.... HVR.... MBI.... DNU.V.. "
                     "GFR.... STO.... HBE.... MRO.... DSTT... "
                     "GHA.... SMA.... HVR.... MBI.... DPAT.V. "
                     "GHA.... SMA.... HVR.... MBI.... ", messages11);
    assert(giveMeTheRound(dv) == 7);
    assert((giveMeTheScore(dv)) == (GAME_START_SCORE - (SCORE_LOSS_DRACULA_TURN*giveMeTheRound(dv)) -
                                    SCORE_LOSS_VAMPIRE_MATURES));
    
    assert(whereIs(dv, PLAYER_LORD_GODALMING) == HAMBURG);
    assert(whereIs(dv, PLAYER_DR_SEWARD) == MADRID);
    assert(whereIs(dv, PLAYER_VAN_HELSING) == VARNA);
    assert(whereIs(dv, PLAYER_MINA_HARKER) == BARI);
    assert(whereIs(dv, PLAYER_DRACULA) == PARIS);
    
    
    whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 0 && numOfVamps == 0);
    whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps);
    // since traps are destroyed after every 6 moves in the trail
    assert(numOfTraps == 0 && numOfVamps == 0);
    whatsThere(dv,VIENNA,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,PRAGUE,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,NUREMBURG,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 0 && numOfVamps == 1);
    whatsThere(dv,STRASBOURG,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,PARIS,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    
    disposeDracView(dv);
    printf("passed extra5!\n");
    
    printf("extra test 6!\n");
    dv = newDracView("GHA.... SMA.... HVR.... MBI.... DSZ.V.. "
                     "GCO.... SSR.... HSO.... MNP.... DZAT... "
                     "GFR.... STO.... HBE.... MRO.... DVIT... "
                     "GCO.... SSR.... HSO.... MNP.... DPRT... "
                     "GHA.... SMA.... HVR.... MBI.... DNU.V.. "
                     "GFR.... SNUV... HBE.... MRO.... DSTT... "
                     "GHA.... SMA.... HVR.... MBI.... DPAT.V. "
                     "GHA.... SMA.... HVR.... MBI.... ", messages11);
    assert(giveMeTheRound(dv) == 7);
    assert((giveMeTheScore(dv)) == (GAME_START_SCORE - (SCORE_LOSS_DRACULA_TURN*giveMeTheRound(dv)) -
                                    SCORE_LOSS_VAMPIRE_MATURES));
    
    assert(whereIs(dv, PLAYER_LORD_GODALMING) == HAMBURG);
    assert(whereIs(dv, PLAYER_DR_SEWARD) == MADRID);
    assert(whereIs(dv, PLAYER_VAN_HELSING) == VARNA);
    assert(whereIs(dv, PLAYER_MINA_HARKER) == BARI);
    assert(whereIs(dv, PLAYER_DRACULA) == PARIS);
    
    
    whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 0 && numOfVamps == 0);
    whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps);
    // since traps are destroyed after every 6 moves in the trail
    assert(numOfTraps == 0 && numOfVamps == 0);
    whatsThere(dv,VIENNA,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,PRAGUE,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,NUREMBURG,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 0 && numOfVamps == 0);
    whatsThere(dv,STRASBOURG,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,PARIS,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    
    disposeDracView(dv);
    printf("passed extra6!\n");
    
    
    
    printf("extra test 7!\n");
    dv = newDracView("GHA.... SMA.... HVR.... MBI.... DSZ.V.. "
                     "GCO.... SSR.... HSO.... MNP.... DZAT... "
                     "GFR.... STO.... HBE.... MRO.... DVIT... "
                     "GCO.... SSR.... HSO.... MNP.... DPRT... "
                     "GHA.... SMA.... HVR.... MBI.... DNU.V.. "
                     "GFR.... SNUV... HSZV... MRO.... DSTT... "
                     "GHA.... SMA.... HVR.... MBI.... DPAT... "
                     "GHA.... SMA.... HVR.... MBI.... ", messages11);
    assert(giveMeTheRound(dv) == 7);
    assert((giveMeTheScore(dv)) == (GAME_START_SCORE - (SCORE_LOSS_DRACULA_TURN*giveMeTheRound(dv))));
    
    assert(whereIs(dv, PLAYER_LORD_GODALMING) == HAMBURG);
    assert(whereIs(dv, PLAYER_DR_SEWARD) == MADRID);
    assert(whereIs(dv, PLAYER_VAN_HELSING) == VARNA);
    assert(whereIs(dv, PLAYER_MINA_HARKER) == BARI);
    assert(whereIs(dv, PLAYER_DRACULA) == PARIS);
    
    
    whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 0 && numOfVamps == 0);
    whatsThere(dv,SZEGED,&numOfTraps,&numOfVamps);
    // since traps are destroyed after every 6 moves in the trail
    assert(numOfTraps == 0 && numOfVamps == 0);
    whatsThere(dv,VIENNA,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,PRAGUE,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,NUREMBURG,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 0 && numOfVamps == 0);
    whatsThere(dv,STRASBOURG,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    whatsThere(dv,PARIS,&numOfTraps,&numOfVamps);
    assert(numOfTraps == 1 && numOfVamps == 0);
    
    disposeDracView(dv);
    printf("passed extra7!\n");
    
    return 0;
}
コード例 #15
0
ファイル: hunter.c プロジェクト: JClumapas/FoD-T09-tut-lab
void decideHunterMove(HunterView gameState)
{
   //printf("------------------------------------------");
   int playerID = whoAmI(gameState);
   if(howHealthyIs(gameState,playerID)==0){
        registerBestPlay("JM","Dead");
   }else if(playerID == 0){
       int round = giveMeTheRound(gameState);
       LocationID trail[TRAIL_SIZE];
       giveMeTheTrail(gameState, whoAmI(gameState), trail);
       int dead = 0;
       int i;

       for(i=0; i<3; i++){
          if(trail[i] == nameToID("JM"))
             dead = i;
          fprintf(stderr, "Dead%d\n",dead);
       }
       
       if(dead){
          if(round%2==0){
             registerBestPlay("KL","Camping 1");
          }else if(round%2==1){
             registerBestPlay("BC","Camping 2");
          }
       }else{
          if(dead == 0){
             registerBestPlay("SZ","Recovery 1");
          }else if(dead == 1){
             registerBestPlay("KL","Recovery 2");
          }else{
             registerBestPlay("KL","Recovery 3");
          }
       } 
   }else{
        fprintf(stderr, "\n\nHunters\n");
        srand((unsigned) time(NULL));
        if(giveMeTheRound(gameState) == 0){
            registerBestPlay("MU","Let the games Begin");
        }else{
            int numLocations = 0;
            int *places; 
            char message[15];
            int i;
            fprintf(stderr,"huntFrom:%s\n",idToName(whereIs(gameState, playerID)));
            fprintf(stderr, "\n\n\n");
            places = whereCanIgo(gameState, &numLocations, 1, 1, 0);
            fprintf(stderr, "Free\nnumLoc:%d\n", numLocations);
            for(i=0; i<numLocations; i++){
                fprintf(stderr, "%s,",idToName(places[i]));
            }
            
            srand(time(NULL));
            registerBestPlay(idToAbbrev(places[rand()%numLocations]),message); 
            //if(places[0])
            //    printf("a");
            sprintf(message, "\n\n");
            //registerBestPlay("MU",""); 
        }
        
   }
   //printf("\n\n\n\n");
   //egisterBestPlay("GE","I'm on holiday in Geneva");
}
コード例 #16
0
// find a path between two vertices using breadth-first traversal
int findPath(HunterView h, LocationID src, LocationID dest, int *path, int road, int rail, int sea)
{
	printf("finding path from %d to %d\n",src,dest);
	if(src==dest) {
		printf("trying to get to where you are\n");
		path[1] = dest;
		return 1;
	}
	int tmp_city = src;
	// Temporary store of path_distance for calculations
	int tmp_distance = 0;
	int path_distance = 0;

	// Array of visited cities, if not visited 0, else 1
	int visited[NUM_MAP_LOCATIONS] = {0};

	// Stores index of the previous city, default value -1
	int prev[NUM_MAP_LOCATIONS] = {[0 ... (NUM_MAP_LOCATIONS-1)] = -1};

	Queue cityQ = newQueue();
	QueueJoin(cityQ, src);

	// While Queue is not empty and the tmp_city is not the destination city (e.g. when path to destination city from src is found)
	while (QueueIsEmpty(cityQ) == 0 && tmp_city != dest) {
		tmp_city = QueueLeave(cityQ);
		
		int num_locs;
		int *locs = connectedLocations(h->g, &num_locs,tmp_city, whoAmI(h), giveMeTheRound(h),road,rail,sea);
		
		int i;
		for (i=0;i<num_locs;i++) {
			
		
			if (!visited[locs[i]]) {
				QueueJoin(cityQ, locs[i]);
				prev[locs[i]] = tmp_city;
				visited[locs[i]] = 1;
			}
		}

		if (tmp_city == dest) {
			prev[locs[i]] = tmp_city;

			// Calculating size of path
			int index = locs[i];
			while (index != src) {
				index = prev[index];
				path_distance++;
			}
		
			// Building path array, storing destination first
			tmp_distance = path_distance-1;
			path[tmp_distance] = dest;
			tmp_distance--;

			// Storing rest of array
			index = prev[dest];
			while (tmp_distance >= 0) {
				path[tmp_distance] = index;
				index = prev[index];
				tmp_distance--;
			}
			break;
		}
	}
	
	
	printf("path->");
	int j;
	for(j=0;j<path_distance;j++) {
		printf("%d->",path[j]);
	}
	printf("x\n");
	
	return path_distance;
}
コード例 #17
0
int main()
{
    int i;
    HunterView hv;

    printf("Test basic empty initialisation\n");
    hv = newHunterView("", NULL);
    assert(whoAmI(hv) == PLAYER_LORD_GODALMING);
    assert(giveMeTheRound(hv) == 0);
    assert(howHealthyIs(hv,PLAYER_DR_SEWARD) == GAME_START_HUNTER_LIFE_POINTS);
    assert(howHealthyIs(hv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS);
    assert(giveMeTheScore(hv) == GAME_START_SCORE);
    assert(whereIs(hv,PLAYER_LORD_GODALMING) == UNKNOWN_LOCATION);
    printf("passed\n");
    disposeHunterView(hv);

    printf("Test for Dracula trail and basic functions\n");
    PlayerMessage messages2[] = {"Hello","Rubbish","Stuff","","Mwahahah"};
    hv = newHunterView("GST.... SAO.... HZU.... MBB.... DC?....", messages2);
    assert(whoAmI(hv) == PLAYER_LORD_GODALMING);
    assert(giveMeTheRound(hv) == 1);
    assert(whereIs(hv,PLAYER_LORD_GODALMING) == STRASBOURG);
    assert(whereIs(hv,PLAYER_DR_SEWARD) == ATLANTIC_OCEAN);
    assert(whereIs(hv,PLAYER_VAN_HELSING) == ZURICH);
    assert(whereIs(hv,PLAYER_MINA_HARKER) == BAY_OF_BISCAY);
    assert(whereIs(hv,PLAYER_DRACULA) == CITY_UNKNOWN);
    assert(howHealthyIs(hv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS);
    printf("passed\n");
    disposeHunterView(hv);

    printf("Test for encountering Dracula and hunter history\n");
    PlayerMessage messages3[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!"};
    hv = newHunterView("GST.... SAO.... HCD.... MAO.... DGE.... GGED...", messages3);
    assert(whereIs(hv,PLAYER_DRACULA) == GENEVA);
    assert(howHealthyIs(hv,PLAYER_LORD_GODALMING) == 5);
    assert(howHealthyIs(hv,PLAYER_DRACULA) == 30);
    assert(whereIs(hv,PLAYER_LORD_GODALMING) == GENEVA);
    LocationID history[TRAIL_SIZE];
    giveMeTheTrail(hv,PLAYER_DRACULA,history);
    assert(history[0] == GENEVA);
    assert(history[1] == UNKNOWN_LOCATION);
    giveMeTheTrail(hv,PLAYER_LORD_GODALMING,history);
    assert(history[0] == GENEVA);
    assert(history[1] == STRASBOURG);
    assert(history[2] == UNKNOWN_LOCATION);
    giveMeTheTrail(hv,PLAYER_DR_SEWARD,history);
    assert(history[0] == ATLANTIC_OCEAN);
    assert(history[1] == UNKNOWN_LOCATION);
    printf("passed\n");
    disposeHunterView(hv);

    printf("Test for Dracula doubling back at sea, and losing blood points (Hunter View)\n");
    PlayerMessage messages4[] = {"Hello","Rubbish","Stuff","","Mwahahah","Aha!","","","","Back I go"};
    hv = newHunterView("GGE.... SGE.... HGE.... MGE.... DS?.... "
                       "GST.... SST.... HST.... MST.... DD1....", messages4);
    assert(whereIs(hv,PLAYER_DRACULA) == DOUBLE_BACK_1);
    giveMeTheTrail(hv,PLAYER_DRACULA,history);
    assert(history[0] == DOUBLE_BACK_1);
    assert(history[1] == SEA_UNKNOWN);
    assert(howHealthyIs(hv,PLAYER_DRACULA) == GAME_START_BLOOD_POINTS - 4);
    assert(whoAmI(hv) == 0);
    printf("passed\n");
    disposeHunterView(hv);

    printf("Test for connections\n");
    int size, seen[NUM_MAP_LOCATIONS], *edges;

    printf("Checking Galatz road connections\n");
    PlayerMessage messages5[] = {"Gone to Galatz"};
    hv = newHunterView("GGA....", messages5);
    edges = whereCanTheyGo(hv,&size,PLAYER_LORD_GODALMING,1,0,0);
    memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int));
    for (i = 0; i< size ; i++) seen[edges[i]] = 1;
    assert(size == 5); assert(seen[GALATZ]); assert(seen[CONSTANTA]);
    assert(seen[BUCHAREST]); assert(seen[KLAUSENBURG]); assert(seen[CASTLE_DRACULA]);
    free(edges);
    disposeHunterView(hv);

    printf("Checking Ionian Sea sea connections\n");
    PlayerMessage messages6[] = {"Sailing the Ionian"};
    hv = newHunterView("GIO....", messages6);
    edges = whereCanTheyGo(hv,&size,PLAYER_LORD_GODALMING,0,0,1);
    memset(seen, 0, NUM_MAP_LOCATIONS*sizeof(int));
    for (i = 0; i < size; i++) seen[edges[i]] = 1;
    assert(size == 7); assert(seen[IONIAN_SEA]); assert(seen[BLACK_SEA]);
    assert(seen[ADRIATIC_SEA]); assert(seen[TYRRHENIAN_SEA]);
    assert(seen[ATHENS]); assert(seen[VALONA]); assert(seen[SALONICA]);
    free(edges);
    disposeHunterView(hv);

    printf("Checking Athens rail connections (none)\n");
    PlayerMessage messages7[] = {"Leaving Athens by train"};
    hv = newHunterView("GAT....", messages7);
    edges = whereCanTheyGo(hv,&size,PLAYER_LORD_GODALMING,0,1,0);
    assert(size == 1);
    assert(edges[0] == ATHENS);
    free(edges);
    disposeHunterView(hv);

    printf("passed\n");
    return 0;
}
コード例 #18
0
int main()
{
    DracView gv;
 
    printf("\t\tTest From PastPlays in Bugfixes\n");

    printf("\n\tGame #0 samples, End of Round 1\n");
    PlayerMessage messages2[] = {"Hello", "There", "This", "Should", "Be Good", 
                                 "Yas", "I'm Getting", "A", "Bit" };
    gv = newDracView("GMN.... SPL.... HAM.... MPA.... DZU.V.. "
                     "GLV.... SLO.... HNS.... MST....", messages2);
    printf("Round/Score Tests\n");
    assert(giveMeTheRound(gv) == 1);
    assert(giveMeTheScore(gv) == 365);
    printf("passed\n");
    printf("Location History Tests\n");
    LocationID history[TRAIL_SIZE];
    giveMeTheTrail(gv, 0, history);
    assert(history[0] == LIVERPOOL);
    assert(history[1] == MANCHESTER); 
    assert(history[2] == UNKNOWN_LOCATION);
    giveMeTheTrail(gv,1,history);
    assert(history[0] == LONDON);
    assert(history[1] == PLYMOUTH);
    assert(history[2] == UNKNOWN_LOCATION);
    giveMeTheTrail(gv,2,history);
    assert(history[0] == NORTH_SEA);
    assert(history[1] == AMSTERDAM);
    assert(history[2] == UNKNOWN_LOCATION);
    giveMeTheTrail(gv,3,history);
    assert(history[0] == STRASBOURG);
    assert(history[1] == PARIS);
    assert(history[2] == UNKNOWN_LOCATION);
    giveMeTheTrail(gv,4,history);
    assert(history[0] == ZURICH);
    assert(history[1] == UNKNOWN_LOCATION);
    printf("Passed Location History Tests\n");
    printf("Vampire/Trap Location Tests\n");
    int nT, nV;
    whatsThere(gv, ADRIATIC_SEA, &nT, &nV);
    assert(nT == 0 && nV == 0);
    whatsThere(gv, ZURICH, &nT, &nV);
    assert(nT == 0 && nV == 1);
    whatsThere(gv, ZURICH, &nT, &nV);
    assert(nT == 0 && nV == 1);
    whatsThere(gv, MANCHESTER, &nT, &nV);
    assert(nT == 0 && nV == 0);
    printf("Passed Vampire/Trap Tests\n");
    disposeDracView(gv);

    printf("\n\tGame #1, Dracula's Turn, 5 complete Rounds\n");
    PlayerMessage messages3[]={""};
    gv = newDracView("GMN.... SPL.... HAM.... MPA.... DGA.V.. "
                     "GLV.... SLO.... HNS.... MST.... DHIT... "
                     "GIR.... SPL.... HAO.... MZU.... DCDT... "
                     "GSW.... SLO.... HNS.... MFR.... DKLT... "
                     "GLV.... SPL.... HAO.... MZU.... DBCT... "
                     "GSW.... SLO.... HNS.... MMR....", messages3);
    printf("Score And Round Number tests\n");
    assert(giveMeTheRound(gv) == 5);
    assert(giveMeTheScore(gv) == GAME_START_SCORE - 5);
    assert(howHealthyIs(gv, 4) == GAME_START_BLOOD_POINTS + LIFE_GAIN_CASTLE_DRACULA);
    printf("Passed Score/Round tests\n");
    printf("Location History Tests\n");
    giveMeTheTrail(gv,0,history);
    assert(history[0] == SWANSEA);
    assert(history[1] == LIVERPOOL);
    assert(history[2] == SWANSEA);
    assert(history[3] == IRISH_SEA);
    assert(history[4] == LIVERPOOL);
    assert(history[5] == MANCHESTER);
    
    giveMeTheTrail(gv,1,history);
    assert(history[0] == LONDON);
    assert(history[1] == PLYMOUTH);
    assert(history[2] == LONDON);
    assert(history[3] == PLYMOUTH);
    assert(history[4] == LONDON);
    assert(history[5] == PLYMOUTH);

    giveMeTheTrail(gv,2,history);
    assert(history[0] == NORTH_SEA);
    assert(history[1] == ATLANTIC_OCEAN);
    assert(history[2] == NORTH_SEA);
    assert(history[3] == ATLANTIC_OCEAN);
    assert(history[4] == NORTH_SEA);
    assert(history[5] == AMSTERDAM);

    giveMeTheTrail(gv,3,history);
    assert(history[0] == MARSEILLES);
    assert(history[1] == ZURICH);
    assert(history[2] == FRANKFURT);
    assert(history[3] == ZURICH);
    assert(history[4] == STRASBOURG);
    assert(history[5] == PARIS);

    giveMeTheTrail(gv,4,history);
    assert(history[0] == BUCHAREST);
    assert(history[1] == KLAUSENBURG);
    assert(history[2] == CASTLE_DRACULA);
    assert(history[3] == GALATZ);
    assert(history[4] == GALATZ);
    printf("Passed Location History Tests\n");
    
    printf("Vampire/Trap Location Tests\n");
    whatsThere(gv, GALATZ, &nT, &nV);
    assert(nT == 1 && nV == 1);
    whatsThere(gv, CASTLE_DRACULA, &nT, &nV);
    assert(nT == 1 && nV == 0); 
    whatsThere(gv, KLAUSENBURG, &nT, &nV);
    assert(nT == 1 && nV == 0);
    whatsThere(gv, BUCHAREST, &nT, &nV);
    assert(nT == 1 && nV == 0);
    whatsThere(gv, HAMBURG, &nT, &nV);
    assert(nT == nV && nV == 0);
    printf("passed Vampire/Trap Location Tests\n");
    disposeDracView(gv);

    printf(" ================= LEGENDARY ===============\n");
    return 0;
}