Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include <ctime>
- using namespace std;
- struct Player {
- string name;
- int number_games;
- int * games;
- int playerscore = 0;
- Player(int number_of_games)
- {
- number_games = number_of_games;
- games = new int[number_of_games];
- }
- };
- int games[] = {
- 1 /* Rock */,
- 2 /* paper */,
- 3 /* Scissor */,
- 4 /* lizard */,
- 5 /* spock */
- };
- int element_to_number(string val)
- {
- //
- if (val == "Rock" || val == "Rock,")
- return 1;
- else if (val == "Paper" || val == "Paper,")
- return 2;
- else if (val == "Scissor" || val == "Scissor,")
- return 3;
- else if (val == "Lizard" || val == "Lizard,")
- return 4;
- else
- return 5;
- //
- }
- int SimulateGame(int PlayerChoice, int CompChoice)
- {
- if ((PlayerChoice == 1 && CompChoice == 1) ||
- (PlayerChoice == 2 && CompChoice == 2) ||
- (PlayerChoice == 3 && CompChoice == 3) ||
- (PlayerChoice == 4 && CompChoice == 4) ||
- (PlayerChoice == 5 && CompChoice == 5))
- {
- return 2;
- }
- else if ((PlayerChoice == 3 && CompChoice == 2) ||
- (PlayerChoice == 2 && CompChoice == 1) ||
- (PlayerChoice == 1 && CompChoice == 4) ||
- (PlayerChoice == 4 && CompChoice == 5) ||
- (PlayerChoice == 5 && CompChoice == 3) ||
- (PlayerChoice == 3 && CompChoice == 4) ||
- (PlayerChoice == 4 && CompChoice == 2) ||
- (PlayerChoice == 2 && CompChoice == 5) ||
- (PlayerChoice == 5 && CompChoice == 1) ||
- (PlayerChoice == 1 && CompChoice == 3))
- {
- return 1;
- }
- else if ((PlayerChoice == 2 && CompChoice == 3) ||
- (PlayerChoice == 1 && CompChoice == 2) ||
- (PlayerChoice == 4 && CompChoice == 1) ||
- (PlayerChoice == 5 && CompChoice == 4) ||
- (PlayerChoice == 3 && CompChoice == 5) ||
- (PlayerChoice == 4 && CompChoice == 3) ||
- (PlayerChoice == 2 && CompChoice == 4) ||
- (PlayerChoice == 5 && CompChoice == 2) ||
- (PlayerChoice == 1 && CompChoice == 5) ||
- (PlayerChoice == 3 && CompChoice == 1))
- {
- return 0;
- }
- }
- int computerplay() {
- srand(time(NULL));
- int r = (rand() % 5) + 1;
- return r;
- }
- int main()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- int a;
- cin >> a;
- Player **players = new Player*[a];
- for (int i = 0; i < a; i++)
- {
- string name;
- int number_games;
- cin >> name >> number_games;
- players[i] = new Player(number_games);
- players[i]->name = name;
- for (int j = 0; j < number_games; j++) {
- string val;
- cin >> val;
- players[i]->games[j] = element_to_number(val);
- }
- }
- for (int i = 0; i < a; i++)
- {
- for (int j = 0; j < players[i]->number_games; j++) {
- bool replay = false;
- int pcgame = computerplay();
- int winScore = SimulateGame(*players[i]->games, pcgame);
- while (winScore == 2)
- {
- replay = true;
- int pcgame = computerplay();
- winScore = SimulateGame(*players[i]->games, pcgame);
- if (winScore != 2)
- players[i]->playerscore += winScore;
- }
- if (replay == false)
- players[i]->playerscore += winScore;
- players[i]->games[j];
- }
- float winLuck = float(players[i]->playerscore) / float(players[i]->number_games);
- cout << players[i]->name << " - " << winLuck << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement