Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::vector<Edge> NimLearner::playRandomGame() const {
- vector<Edge> path;
- /* Your code goes here! */
- unsigned tokens = numTokens;
- Vertex curr = startingVertex_;
- Vertex next;
- int starting_player = 1;
- int curr_player = starting_player;
- while(tokens > 0){
- int nextMove = rand() % 2;
- nextMove++;
- if(nextMove == 1){
- if(tokens >= 1){
- if(curr_player == 1){
- next = "p2-" + std::to_string(tokens - nextMove);
- curr_player = 2;
- }else{
- next = "p1-" + std::to_string(tokens - nextMove);
- curr_player = 1;
- }
- path.push_back(Edge(curr, next));
- curr = next;
- tokens -= nextMove;
- }
- }else if(nextMove == 2){
- if(tokens >= 2){
- if(curr_player == 1){
- next = "p2-" + std::to_string(tokens - nextMove);
- curr_player = 2;
- }else{
- next = "p1-" + std::to_string(tokens - nextMove);
- curr_player = 1;
- }
- path.push_back(Edge(curr, next));
- curr = next;
- tokens -= nextMove;
- }
- }
- }
- return path;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement