Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.80 KB | None | 0 0
  1. void getHistory (GameView gv, PlayerID player, LocationID trail[TRAIL_SIZE])
  2. {
  3.     //Check if its the beginning of the game
  4.     if (gv->roundNumber == 0) {
  5.         int trailC = 0;
  6.         while(trailC < TRAIL_SIZE){//add UNKNOWN_LOCATION to entire trail
  7.             trail[trailC] = UNKNOWN_LOCATION;
  8.             trailC++;
  9.         }
  10.     } else {
  11.         //find latest play index in pastP
  12.         int lastPlay = latestPlay(gv);
  13.         while(gv->pastP[lastPlay] != player){
  14.             lastPlay = lastPlay - PLAY_LEN;
  15.         }//latest play by player
  16.        
  17.         //Dracula case:---------------
  18.         if(player == 'D'){
  19.             int count = 0;
  20.             while(count < TRAIL_SIZE){
  21.                 char tempLoc[2];
  22.                 tempLoc[0] = gv->pastP[lastPlay+1];
  23.                 tempLoc[1] = gv->pastP[lastPlay+2];
  24.                 tempLoc[2] = '\0';
  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_ONE;
  39.                 } else if(tempLoc[0]=='D' && tempLoc[1]=='2'){
  40.                     trailAdd = DOUBLE_BACK_TWO;
  41.                 } else if(tempLoc[0]=='D' && tempLoc[1]=='3'){
  42.                     trailAdd = DOUBLE_BACK_THREE;
  43.                 } else if(tempLoc[0]=='D' && tempLoc[1]=='4'){
  44.                     trailAdd = DOUBLE_BACK_FOUR;
  45.                 } else if(tempLoc[0]=='D' && tempLoc[1]=='5'){
  46.                     trailAdd = DOUBLE_BACK_FIVE;
  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.                 currLoc[2] = '\0';
  65.            
  66.                 //turn location abbreviation to locationID using places.c
  67.                 LocationID currLocation = abbrevToID(currLoc);
  68.            
  69.                 //finally, add locationID to trail
  70.                 pushToTrail(trail, currLocation);
  71.            
  72.                 lastPlay = lastPlay - LINE_LEN;//go back to the previous round
  73.                 countr++;//will only go to 6 to ensure trail is at most last 6 plays.
  74.             }
  75.             //after all of this the trail array should be updated for
  76.             //whichever player was parsed into the function.
  77.         }
  78.     }
  79. }
  80.  
  81. //local function to push location onto trail. oldest location falls off trail.
  82. static void pushToTrail(LocationID trail[TRAIL_SIZE], LocationID location){
  83.     assert(trail != NULL);
  84.     int i = 0;
  85.     LocationID temp = trail[i];
  86.     while(trail[i] != '\0'){
  87.         //tests to see if were adding to end of array
  88.         if(i+1 == TRAIL_SIZE){
  89.             trail[i] = location;
  90.             i++;//increments and then loop ends.
  91.        
  92.         } else {//operation to shift numbers along array.
  93.             trail[i] = location;
  94.             location = temp;
  95.             temp = trail[i+1];
  96.             i++;
  97.         }
  98.     }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement