//  Geoff Hagopian : PPP4 Ex. 10

#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
//#include <algorithm>

using namespace std;

/*
10. Write a program that plays the game “Rock,
Paper, Scissors.” If you are not familiar with 
the game do some research (e.g., on the web 
using Startpage). Research is a common task 
for programmers. Use a switch-statement to 
solve this exercise. Also, the machine should 
give random answers (i.e., select the next 
rock, paper, or scissors randomly). Real 
randomness is too hard to provide just now, 
so just build a vector with a sequence of 
values to be used as “the next value.” If you 
build the vector into the program, it will 
always play the same game, so maybe you should 
let the user enter some values. Try variations 
to make it less easy for the user to guess 
which move the machine will make next.
*/

void showResults(int, int, int);

int main() {
	srand(time(0));
	int userChoice, computerChoice;
	int wins{ 0 }, losses{ 0 }, ties{ 0 };
	while (1) {
		cout << "Rock (0), Paper(1) or Scissors(2)? ";
		cin >> userChoice;
		computerChoice = rand() % 3;
		switch (userChoice) {
		case 0: {
			if (computerChoice == 1) {
				cout << "I lose!\n";
				++losses;
			}
			else if (computerChoice == 2) {
				cout << "I win!\n";
				++wins;
			}
			else ++ties;
			break;
		}
		case 1: {
			if (computerChoice == 0) {
				cout << "I win!\n";
				++wins;
			}
			else if (computerChoice == 2) {
				cout << "I lose!\n";
				++losses;
			}
			else ++ties;
			break;
		}
		case 2: {
			if (computerChoice == 1) {
				cout << "I win!\n";
				++wins;
			}
			else if (computerChoice == 0) {
				cout << "I lose!\n";
				++losses;
			}
			else ++ties;
			break;
		}
		default:
			cout << "bad choice, try again:\n";
		}
		showResults(wins, losses, ties);
	}
}

void showResults(int w, int l, int t) {
	cout << "So far, wins: " << w
		<< ", losses: " << l
		<< ", ties: " << t << endl;
}