Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. std::vector<Edge> NimLearner::playRandomGame() const {
  2.   vector<Edge> path;
  3.  /* Your code goes here! */
  4.  unsigned tokens = numTokens;
  5.  Vertex curr = startingVertex_;
  6.  Vertex next;
  7.  int starting_player = 1;
  8.  int curr_player = starting_player;
  9.  
  10.  while(tokens > 0){
  11.    int nextMove = rand() % 2;
  12.    nextMove++;
  13.    if(nextMove == 1){
  14.      if(tokens >= 1){
  15.        if(curr_player == 1){
  16.          next = "p2-" + std::to_string(tokens - nextMove);
  17.          curr_player = 2;
  18.        }else{
  19.          next = "p1-" + std::to_string(tokens - nextMove);
  20.          curr_player = 1;
  21.        }
  22.        path.push_back(Edge(curr, next));
  23.        curr = next;
  24.        tokens -= nextMove;
  25.      }
  26.    }else if(nextMove == 2){
  27.      if(tokens >= 2){
  28.        if(curr_player == 1){
  29.          next = "p2-" + std::to_string(tokens - nextMove);
  30.          curr_player = 2;
  31.        }else{
  32.          next = "p1-" + std::to_string(tokens - nextMove);
  33.          curr_player = 1;
  34.        }
  35.        path.push_back(Edge(curr, next));
  36.        curr = next;
  37.        tokens -= nextMove;
  38.      }
  39.    }
  40.  }
  41.  
  42.   return path;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement