Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.13 KB | None | 0 0
  1. void
  2. getHistory (GameView gv, PlayerID player, LocationID trail[TRAIL_SIZE])
  3. {
  4.     //Check if its the beginning of the game
  5.     if (gv->roundNumber == 0) {
  6.         int trailC = 0;
  7.         while(trailC < TRAIL_SIZE){//add UNKNOWN_LOCATION to entire trail
  8.             trail[trailC] = UNKNOWN_LOCATION;
  9.             trailC++;
  10.         }
  11.     } else {
  12.         //find latest play index in pastP
  13.         int lastPlay = latestPlay(gv);
  14.         while(gv->pastP[lastPlay] != player){
  15.             lastPlay = lastPlay - PLAY_LEN;
  16.         }//latest play by player
  17.        
  18.         //Dracula case:---------------
  19.         if(player == PLAYER_DRACULA){
  20.             int count = 0;
  21.             while(count < TRAIL_SIZE){
  22.                 char tempLoc[2];
  23.                 tempLoc[0] = gv->pastP[lastPlay+1];
  24.                 tempLoc[1] = gv->pastP[lastPlay+2];
  25.                
  26.                 int trailAdd;
  27.                
  28.                 if(tempLoc[0]=='C' && tempLoc[1]=='?'){//if unknown city location
  29.                     trailAdd = CITY_UNKNOWN;
  30.                 } else if(tempLoc[0]=='S' && tempLoc[1]=='?'){//if unknown sea location
  31.                     trailAdd = SEA_UNKNOWN;
  32.                 } else if(tempLoc[0]=='H' && tempLoc[1]=='I'){
  33.                     trailAdd = HIDE;
  34.                 } else if(tempLoc[0]=='T' && tempLoc[1]=='P'){
  35.                     trailAdd = TELEPORT;
  36.                 }
  37.                 else if(tempLoc[0]=='D' && tempLoc[1]=='1'){
  38.                     trailAdd = DOUBLE_BACK_1;
  39.                 } else if(tempLoc[0]=='D' && tempLoc[1]=='2'){
  40.                     trailAdd = DOUBLE_BACK_2;
  41.                 } else if(tempLoc[0]=='D' && tempLoc[1]=='3'){
  42.                     trailAdd = DOUBLE_BACK_3;
  43.                 } else if(tempLoc[0]=='D' && tempLoc[1]=='4'){
  44.                     trailAdd = DOUBLE_BACK_4;
  45.                 } else /*tempLoc[0]=='D' && tempLoc[1]=='5'*/{
  46.                     trailAdd = DOUBLE_BACK_5;
  47.                 }
  48.                
  49.                 pushToTrail(trail, trailAdd);//add to trail
  50.                 lastPlay = lastPlay - LINE_LEN;
  51.                 count++;
  52.             }
  53.         }//-----------------
  54.         else {
  55.             //hunter case:
  56.            
  57.             //now we fill in the trail, finally.
  58.             int countr = 0;
  59.             while(countr < TRAIL_SIZE){
  60.                 char currLoc[2];//current location
  61.                 //extract location abbreviation
  62.                 currLoc[0] = gv->pastP[lastPlay+1];
  63.                 currLoc[1] = gv->pastP[lastPlay+2];
  64.                
  65.                 //turn location abbreviation to locationID using places.c
  66.                 LocationID currLocation = abbrevToID(currLoc);
  67.                
  68.                 //finally, add locationID to trail
  69.                 pushToTrail(trail, currLocation);
  70.                
  71.                 lastPlay = lastPlay - LINE_LEN;//go back to the previous round
  72.                 countr++;//will only go to 6 to ensure trail is at most last 6 plays.
  73.             }
  74.             //after all of this the trail array should be updated for
  75.             //whichever player was parsed into the function.
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement