Advertisement
BenjaminH

Rock Paper Scissors AI

Oct 20th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <fstream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     string answer;
  11.     string name;
  12.     float playerscore = 0;
  13.     float AIscore = 0;
  14.     int playerpick;
  15.     int AIpick;
  16.     cout << "Welcome to Rock Paper Scissors!" << endl;
  17.     Sleep(2000);
  18.     cout<< "I don't know your name yet. "<<endl;
  19.     Sleep(1000);
  20.     cout << "What's your name?" << endl;
  21.     cin >> name;
  22.     cout << "Hey, " << name << ". I'm Benjamin's AI." << endl;
  23.     Sleep(2000);
  24.     cout << "Do you want to play Rock Paper Scissors?" << endl << "1: Of course!" << endl << "0: Why would I want to play Rock Paper Scissors? It's a boring game." << endl;
  25.     cin >> answer;
  26.     if (answer == "1") {
  27.         cout << "Great! I love Rock Paper Scissors. Let's play!" << endl;
  28.         Sleep(2000);
  29.         AIpick = 2;
  30.         while (true) {
  31.             cout << "Pick:" << endl << "1: Rock" << endl << "2: Paper" << endl << "3: Scissors" << endl << "So what'll it be?" << endl;
  32.             cin >> playerpick;
  33.             cout << endl;
  34.             switch(playerpick) {
  35.                 case 1: if (AIpick == 1) {
  36.                         cout << "Tie! We both picked Rock!";
  37.                         playerscore += 0.5;
  38.                         AIscore += 0.5;
  39.                     } else if (AIpick == 2) {
  40.                         cout << "I won that time! I picked Paper!";
  41.                         AIscore++;
  42.                     } else {
  43.                         cout << "You got me! I picked Scissors!";
  44.                         playerscore++;
  45.                     }
  46.                     AIpick = 2;
  47.                     break;
  48.                 case 2: if (AIpick == 2) {
  49.                         cout << "Tie! We both picked Paper!";
  50.                         playerscore += 0.5;
  51.                         AIscore += 0.5;
  52.                     } else if (AIpick == 3) {
  53.                         cout << "Got you! My pick was Scissors.";
  54.                         AIscore++;
  55.                     } else {
  56.                         cout << "Great job! You won that round! I shouldn't have picked Rock...";
  57.                         playerscore++;
  58.                     }
  59.                     AIpick = 3;
  60.                     break;
  61.                 case 3: if (AIpick == 3) {
  62.                         cout << "Tie! We both picked Scissors!";
  63.                         playerscore += 0.5;
  64.                         AIscore += 0.5;
  65.                     } else if (AIpick == 2) {
  66.                         cout << "Whoops! I meant to pick Rock... Oh well, you won that time! I picked Paper.";
  67.                         playerscore++;
  68.                     } else {
  69.                         cout << "Better luck next time! I picked Rock!";
  70.                         AIscore++;
  71.                     }
  72.                     AIpick = 1;
  73.                     break;
  74.                 default:
  75.                     cout << "You didn't pick a valid choice. I assume you cheated, and therefore I got that point.";
  76.                     AIscore++;
  77.             }
  78.             cout << endl << "Score: " << endl << name << " " << playerscore << " - " << AIscore << " " << "Benjamin's AI" << endl;
  79.             if (playerscore < AIscore) {
  80.                 cout << "I'm winning! You have your work cut out for you to catch up! Good luck!" << endl;
  81.             } else if (AIscore < playerscore) {
  82.                 cout << "You're winning! Keep it up!" << endl;
  83.             } else {
  84.                 cout << "Looks like we're tied! You could cut the tension with a butter knife!" << endl;
  85.             }
  86.             cout << "Want to keep playing?" << endl << "1: Yes" << endl << "0: No" << endl;
  87.             cin >> answer;
  88.             if (answer == "1") {
  89.                 cout << "Great!" << endl;
  90.             } else {
  91.                 if (playerscore > AIscore) {
  92.                     cout << "You won! Great Job!" << endl;
  93.                     system("PAUSE");
  94.                     break;
  95.                 } else if (AIscore > playerscore) {
  96.                     cout << "I won! Better luck next time!" << endl;
  97.                     system("PAUSE");
  98.                     break;
  99.                 } else {
  100.                     cout << "It was a tie! Better keep practicing..." << endl;
  101.                     system("PAUSE");
  102.                     break;
  103.                 }
  104.             }
  105.         }
  106.     } else if (answer == "0") {
  107.         cout << "Oh well... Can we still be friends?"<< endl << "1: Of course!" << endl << "0: Why would I want to be friends with a computer? No." << endl;
  108.         cin >> answer;
  109.         if (answer == "1") {
  110.             cout << "Thanks! Hopefully I'll see you again sometime soon!" << endl;
  111.             system("PAUSE");
  112.         } else {
  113.             cout << "You're so mean. Bye." << endl;
  114.             system("PAUSE");
  115.         }
  116.     } else {
  117.        cout << "I couldn't understand you. I assume that you don't want to play. ";
  118.        Sleep(1000);
  119.        cout << "Bye!" << endl;
  120.        system("PAUSE");
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement