Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 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(pastP[lastPlay] != player){
  14. lastPlay = lastPlay - PLAY_LEN;
  15. }//latest play by player
  16.  
  17. //now we fill in the trail, finally.
  18. int countr = 0;
  19. while(countr < TRAIL_SIZE){
  20. char currLoc[2];
  21. //extract location abbreviation
  22. currLoc[0] = pastP[lastPlay+1];
  23. currLoc[1] = pastP[lastplay+2];
  24. currLoc[2] = '\0';
  25.  
  26. //turn location abbreviation to locationID
  27. LocationID currLocation = abbrevToID(currLoc);
  28.  
  29. //finally, add locationID to trail
  30. pushToTrail(trail, currLocation);
  31.  
  32. lastPlay = lastPlay - LINE_LEN;//go back to the previous round
  33. countr++;//will only go to 6 to ensure trail is at most last 6 plays.
  34. }
  35. //after all of this the trail array should be updated for
  36. //whichever player was parsed into the function.
  37. }
  38. }
  39.  
  40. //local function to push location onto trail. oldest location falls off trail.
  41. static void pushToTrail(LocationID trail[TRAIL_SIZE], LocationID location){
  42. assert(trail != NULL);
  43. int i = 0;
  44. LocationID temp = trail[i];
  45. while(trail[i] != '\0'){
  46. //tests to see if were adding to end of array
  47. if(i+1 == TRAIL_SIZE){
  48. trail[i] = location;
  49. i++;//increments and then loop ends.
  50.  
  51. } else {//operation to shift numbers along array.
  52. trail[i] = location;
  53. location = temp;
  54. temp = trail[i+1];
  55. i++;
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement