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."); } }
LocationID goToDrac(HunterView gameState, int myLocation, Round roundNum, PlayerID hunter){ int size, *goToArr; goToArr = whereCanIgo(gameState, &size, 1, 0, 0); printf("Size is %d\n", size); LocationID dracTrail[TRAIL_SIZE]; giveMeTheTrail(gameState, PLAYER_DRACULA, dracTrail); LocationID myTrail[TRAIL_SIZE]; giveMeTheTrail(gameState, hunter, myTrail); int i = 0; LocationID trailValue = NOWHERE; while(trailValue == NOWHERE && i < TRAIL_SIZE){ if(dracTrail[i] == HIDE && dracTrail[i+1] != CITY_UNKNOWN && dracTrail[i+1] != SEA_UNKNOWN){ if((i+1) < TRAIL_SIZE) trailValue = dracTrail[i+1]; }else if(dracTrail[i] >= DOUBLE_BACK_1 && dracTrail[i] <= DOUBLE_BACK_5){ int k = dracTrail[i] - DOUBLE_BACK_1 + 1 + i; if(dracTrail[k]!= CITY_UNKNOWN && dracTrail[k] != SEA_UNKNOWN && k < TRAIL_SIZE) trailValue = dracTrail[k]; }else if(dracTrail[i] != CITY_UNKNOWN && dracTrail[i] != SEA_UNKNOWN){ trailValue = dracTrail[i]; } i++; } while(i > 0 && trailValue != NOWHERE){ if(trailValue == myTrail[i] && trailValue != dracTrail[0]) trailValue = NOWHERE; i--; } LocationID goToID = NOWHERE; if(trailValue == dracTrail[0] && trailValue == myLocation){ goToID = myLocation; printf("Drac is here, I'm staying here"); } else if(trailValue != NOWHERE && trailValue != myLocation){ printf("Looking For Drac near me, drac is near %s\n", idToAbbrev(trailValue)); treeBase *B = newTree(gameState, whoAmI(gameState),goToArr,size); goToID = searchTree(B, trailValue); freeTree(B); if(goToID != NOWHERE) printf("Heading Towards Drac. Move: %s -> %s\n", idToAbbrev(myLocation), idToAbbrev(goToID)); }else if(trailValue == NOWHERE && (roundNum+1)%RESEARCH_ROUND == 0 && hunter != PLAYER_LORD_GODALMING){ goToID = myLocation; printf("Lets do research"); } int loopCount = 0; int choice = -1; while(goToID == NOWHERE){ choice = rand() % size; goToID = goToArr[choice]; printf("-- random choice is: %d. Move: %s -> %s\n", choice, idToAbbrev(myLocation), idToAbbrev(goToID)); i = 0; while(i<TRAIL_SIZE){ if((goToID == myTrail[i] && loopCount < (size*2)) || goToID == CASTLE_DRACULA) goToID = NOWHERE; i++; } loopCount++; } free(goToArr); return goToID; }
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"); }
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); }
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"); } } }