Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void getHistory (GameView gv, PlayerID player, LocationID trail[TRAIL_SIZE])
- {
- //Check if its the beginning of the game
- if (gv->roundNumber == 0) {
- int trailC = 0;
- while(trailC < TRAIL_SIZE){//add UNKNOWN_LOCATION to entire trail
- trail[trailC] = UNKNOWN_LOCATION;
- trailC++;
- }
- } else {
- //find latest play index in pastP
- int lastPlay = latestPlay(gv);
- while(pastP[lastPlay] != player){
- lastPlay = lastPlay - PLAY_LEN;
- }//latest play by player
- //now we fill in the trail, finally.
- int countr = 0;
- while(countr < TRAIL_SIZE){
- char currLoc[2];
- //extract location abbreviation
- currLoc[0] = pastP[lastPlay+1];
- currLoc[1] = pastP[lastplay+2];
- currLoc[2] = '\0';
- //turn location abbreviation to locationID
- LocationID currLocation = abbrevToID(currLoc);
- //finally, add locationID to trail
- pushToTrail(trail, currLocation);
- lastPlay = lastPlay - LINE_LEN;//go back to the previous round
- countr++;//will only go to 6 to ensure trail is at most last 6 plays.
- }
- //after all of this the trail array should be updated for
- //whichever player was parsed into the function.
- }
- }
- //local function to push location onto trail. oldest location falls off trail.
- static void pushToTrail(LocationID trail[TRAIL_SIZE], LocationID location){
- assert(trail != NULL);
- int i = 0;
- LocationID temp = trail[i];
- while(trail[i] != '\0'){
- //tests to see if were adding to end of array
- if(i+1 == TRAIL_SIZE){
- trail[i] = location;
- i++;//increments and then loop ends.
- } else {//operation to shift numbers along array.
- trail[i] = location;
- location = temp;
- temp = trail[i+1];
- i++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement