Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.72 KB | None | 0 0
  1. action getARCaction (Game g) {
  2.    action a;
  3.    a.actionCode = OBTAIN_ARC;
  4.  
  5.    // initialise array of possible paths
  6.    char * possibilities[PATH_LIMIT]; // Array of strings
  7.    char * testPath[PATH_LIMIT]; // A single path
  8.    
  9.    int x = 0;
  10.    while (x < PATH_LIMIT) {
  11.       possibilities[x] = " ";
  12.       testPath[x] = " ";
  13.       x++;
  14.    }
  15.    
  16.    // Here is the path that goes through all possible edges
  17.    path allARC = "RRLRLBRLRLRRRRLRLRLLLLRLRLRLRRRRLRLRLRLLLLRLRLRRRRL"
  18.                  "RLRRLRLRRRRLRLRLLLLRLRLRLRRRRLRLRLRLLLLRLRLRRRRLRL";
  19.                  
  20.    // Iterate through all edges to record possibilities
  21.    int possibilitiesPosition = 0; // stores where we store possibilties
  22.    int maxARCposition = (strlen (allARC)); // stops overflow
  23.    int position = 6; // move path to starting edge
  24.  
  25.    while (position <= maxARCposition) {
  26.       strncpy (*testPath, allARC, position); // put new test string in
  27.       // using position as index since position is a count, and we want
  28.       // to reach the next index in the array.
  29.       // testPath[position] = EOF;
  30.       strcpy (a.destination, *testPath); // put test string into action
  31.  
  32.       // if the path is a legal move, put it into possibilities
  33.       if (isLegalAction (g, a) == TRUE) {
  34.          strcpy (possibilities[possibilitiesPosition], *testPath);
  35.          possibilitiesPosition++;
  36.       }
  37.       // try one more step in the path
  38.       position++;
  39.    }
  40.  
  41.    // make sure atleast one possibility, if not return empty path
  42.    if (strcmp (possibilities[0], " ") == 0) {
  43.       strcpy (a.destination, " ");
  44.    // otherwise, literally go and put the path into the action
  45.    } else {
  46.       strcpy (a.destination, possibilities[0]);
  47.    }
  48.    
  49.    return a;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement