/* 
    CPSC-1011-003
    Lab 05
    Collaborators: Owen, Angelina, Drew
*/

#include <stdio.h> // Include stdio for printf() and scanf()
#include <stdlib.h> // Include stdlib for rand() and srand()

int main(void) { // Start main function

    char player1Name[40]; // Declare char array for player 1's name
    char player2Name[40]; // Declare char array for player 2's name
    int player1RandNum; // Declare int to store random number for player 1's plays
    int player2RandNum; // Declare int to store random number for player 2's plays
    int player1Wins = 0; // Declare and initialize number of player 1 wins to 0
    int player2Wins = 0; // Declare and initialize number of player 2 wins to 0

    int numRounds; // Declare int for number of rounds to be played
    int seedVal; // Declare int for srand() seed value to be given by user

    printf("Enter player 1: \n"); // Prompt for player 1's name
    scanf("%s", player1Name); // Store player 1's name
    printf("Enter player 2: \n"); // Prompt for player 2's name
    scanf("%s", player2Name); // Store player 2's name
    printf("How many rounds to play?\n"); // Prompt for number of rounds
    scanf("%d", &numRounds); // Store number of rounds
    printf("Pick a number to randomize game: \n"); // Prompt for seedVal
    scanf("%d", &seedVal); // Store seedVal
    printf("\n"); // Print new line for space

    if (numRounds < 1) { // Check to make sure at least 1 round is going to be played
        printf("Must play at least 1 round. Please try again.\n"); // Print error message if not >1 round
        return -1; // Return error code
    }

    srand(seedVal); // Set seedVal

    printf("Starting game with %s versus %s for %d rounds!\n", player1Name, player2Name, numRounds); // Print game starting with arguments
    for (int i = 1; i <= numRounds; ++i) { // Loop for each round
        player1RandNum = rand() % 3; // Generate random number for player 1's plays
        player2RandNum = rand() % 3; // Generate random number for player 2's plays
        
        // ROCK = 0, PAPER = 1, SCISSORS = 2
        if (player1RandNum == player2RandNum) { // If the two random numbers are equal
            printf("Round %d is a TIE\n", i); // Print tie
        } else if ((player1RandNum == 0) && (player2RandNum == 1)) { // If player 2 wins with paper
            printf("%s wins Round %d with PAPER\n", player2Name, i); // Print win
            ++player2Wins; // Add to player 2's win count
        } else if ((player1RandNum == 0) && (player2RandNum == 2)) { // If player 1 wins with rock
            printf("%s wins Round %d with ROCK\n", player1Name, i); // Print win
            ++player1Wins; // Add to player 1's win count
        } else if ((player1RandNum == 1) && (player2RandNum == 0)) { // If player 1 wins with paper
            printf("%s wins Round %d with PAPER\n", player1Name, i); // Print win
            ++player1Wins; // Add to player 1's win count
        } else if ((player1RandNum == 1) && (player2RandNum == 2)) { // If player 2 wins with scissors
            printf("%s wins Round %d with SCISSORS\n", player2Name, i); // Print win
            ++player2Wins; // Add to player 2's win count
        } else if ((player1RandNum == 2) && (player2RandNum == 0)) { // If player 2 wins with rock
            printf("%s wins Round %d with ROCK\n", player2Name, i); // Print win
            ++player2Wins; // Add to player 2's win count
        } else if ((player1RandNum == 2) && (player2RandNum == 1)) { // If player 1 wins with scissors
            printf("%s wins Round %d with SCISSORS\n", player1Name, i); // Print win
            ++player1Wins; // Add to player 1's win count
        }
    }

    printf("\n%s wins %d and %s wins %d\n", player1Name, player1Wins, player2Name, player2Wins); // Print final results

    return 0; // End code

}