Example #1
0
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);
}
Example #2
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.");
    }
}
Example #3
0
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);
}
Example #4
0
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");
}
Example #5
0
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");
    }
    
    }

}
Example #6
0
void decideMove (HunterView gameState) {
    printf("at start of code\n"); fflush(stdout);
	Graph g = newGraph();
    char *locations[] = {
        "AL", "AM", "AT", "BA", "BI", "BE", "BR", "BO", "BU", "BC", 
        "BD", "CA", "CG", "CD", "CF", "CO", "CN", "DU", "ED", "FL",
        "FR", "GA", "GW", "GE", "GO", "GR", "HA", "JM", "KL", "LE",
        "LI", "LS", "LV", "LO", "MA", "MN", "MR", "MI", "MU", "NA",
        "NP", "NU", "PA", "PL", "PR", "RO", "SA", "SN", "SR", "SJ",
        "SO", "ST", "SW", "SZ", "TO", "VA", "VR", "VE", "VI", "ZA",
        "ZU", "NS", "EC", "IS", "AO", "BB", "MS", "TS", "IO", "AS", 
        "BS", "C?", "S?", "HI", "D1", "D2", "D3", "D4", "D5", "TP"
	};
	int round = getRound(gameState);
	PlayerID id = getCurrentPlayer(gameState);
    LocationID move = getLocation(gameState, id);
    printf("the original loc is %d and health %d\n",move,getHealth(gameState,id));
	char * msg = "";
    printf("initialised all variables\n"); fflush(stdout);
	//set initial locations
	if (round - id == 0) {
	    if (id == PLAYER_LORD_GODALMING) {move = CASTLE_DRACULA; msg = "camping";}
	    else if (id == PLAYER_DR_SEWARD)  move = BELGRADE;
	    else if (id == PLAYER_VAN_HELSING) move = STRASBOURG;
	    else if (id == PLAYER_MINA_HARKER) move = MADRID;
	    registerBestPlay(locations[move], msg);
	    destroyGraph(g);
	    return;
    }
    printf("done initial moves\n"); fflush(stdout);

    //below code will throw errors if LG is killed
    //if (id == PLAYER_LORD_GODALMING) { registerBestPlay("CD","I'm camping MAN!!!"); return; }
	srand (time(NULL));
	int path[NUM_MAP_LOCATIONS];
    int amtLocs = 0;
    LocationID * adj = connectedLocations(&amtLocs, getLocation(gameState, id), id, round, ANY, g);
    LocationID target = UNKNOWN_LOCATION;
    int camper = 0, i, j;
    printf("setting up connected locs etc\n"); fflush(stdout);

    // check for campers
    // if the current player is camping, then the player
    // will stay camping and ai will return
    
    for (i = 0; i < NUM_HUNTERS; i++) {
        if (getLocation(gameState, i) == CASTLE_DRACULA) {
            camper = 1;
            if (id == i) {
	            registerBestPlay("CD", "Staying camping");
                destroyGraph(g);
                free(adj);
                return; 
            }
        }
    } 

    if (!camper) { //if no camper and hunter is shortest dist to castle dracula, move towards castle dracula
        int hunterDist[NUM_HUNTERS] = {UNKNOWN_LOCATION,UNKNOWN_LOCATION,UNKNOWN_LOCATION,UNKNOWN_LOCATION};
        int closestHunter = PLAYER_LORD_GODALMING;
        for (i = PLAYER_LORD_GODALMING; i < NUM_HUNTERS; i++) {
            hunterDist[i] = findShortestPath(getLocation(gameState, i), CASTLE_DRACULA, path, ANY, round);
            if (hunterDist[i] == -1) hunterDist[i] = 1000; //-1 is when there is no path, so don't want him to be shortest
            if ((hunterDist[closestHunter] > hunterDist[i]) || (hunterDist[closestHunter] == UNKNOWN_LOCATION)) closestHunter = i;
        }
        if (closestHunter == id) move = path[1];
    } else {
        LocationID draculaLoc[TRAIL_SIZE];
        getHistory (gameState, PLAYER_DRACULA, draculaLoc); //updates Dracula trail

        for (i = TRAIL_SIZE - 1; i >= 0 ; i--) //locations newer in trail will override older ones
            target = dracTarget(draculaLoc, i); //we have any useful info on his location...

        if (target != UNKNOWN_LOCATION) {
            //Note: Dracula cannot visit any location currently in his trail - hunters should not visit target itself!
            int pathLen = findShortestPath(getLocation(gameState, id), target, path, ANY, round); //success is any number not -1
        	if (getLocation(gameState, id) != target && pathLen != -1) { //path found, and not at rest on target (Drac's trail)
                if (path[1] != target) move = path[1]; 
                //don't move into Dracula's trail (see note above)
                else move = adj[rand() % amtLocs];
                for (i = 0; i < TRAIL_SIZE ; i++) if (path[1] == dracTarget(draculaLoc, i)) move = adj[rand() % amtLocs];
            } else move = adj[rand() % amtLocs];
		} else { //prevents doubling up of hunters when making a random move, since Dracula 404
            int occupied = 0, newLoc = UNKNOWN_LOCATION;
            move = adj[rand() % amtLocs];
            for (j = 0; j < NUM_HUNTERS; j++) if (move == getLocation(gameState, j)) occupied = 1;
            if (occupied) { 
                for (i = 0; i < amtLocs; i++) { 
                    occupied = 0;
                    for (j = 0; j < NUM_HUNTERS; j++) if (adj[i] == getLocation(gameState, j)) occupied = 1;
                    if (!occupied) {newLoc = i; break;}
                }
            }
            if (newLoc != UNKNOWN_LOCATION) move = adj[newLoc]; 
        }
    } 
    if (target != UNKNOWN_LOCATION) printf("*Moving from %s (%d) to target %s (%d) via %s (%d)*\n", locations[getLocation(gameState, id)], getLocation(gameState, id), locations[target], target, locations[move], move);
    else printf("*No target - moving from %s (%d) to %s (%d)*\n", locations[getLocation(gameState, id)], getLocation(gameState, id), locations[move], move);
    
	if (isLegalMove(gameState, id, move, round, g)) registerBestPlay(locations[move], "");
	else {
        printf("ERROR: Location is invalid! Registering default rest move...");
        registerBestPlay(locations[getLocation(gameState, id)], "");
    }
    destroyGraph(g);
    free(adj);
}