/* Kamil Kaminski
 * NetID: kkamin8
 *
 * CS340
 * Project 1, Poker Game
 *
 *
 */

#include "game.h"

int main(int argc, char *argv[])
{
    /* seed rand() */
    srand((unsigned int ) time(NULL));

    /* pokerGame instance */
    Game *pokerGame = new Game();
    PRINT_COLOR(ANSI_COLOR_GREEN, "\tWelcome to Poker Game\n\n");

    /* number of opponents user input */
    pokerGame->askForNumberOfOpponents();

    /* pokerGame loop */
    bool quit = false;
    while (!quit)
    {
        cout << "\n> The deck is being shuffled" << endl;
        pokerGame->shufflePile();

#ifdef DEBUG
        PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: deck after shuffle\n");
        pokerGame->printPile();
#endif

        /* all methods assume that cards are sorted, it is our responsibility to
         * to meet that, this results in simpler code */
        cout << "\n> Dealing cards to the user" << endl;
        pokerGame->dealUserCards();
        pokerGame->sortUserCards();

        cout << "> Dealing cards to opponent(s)" << endl << endl;
        pokerGame->dealOpponentCards();
        pokerGame->sortOpponentCards();

        cout << "Cards in your hand: ";
        pokerGame->printUserCards();

        pokerGame->userAI(pokerGame->getUserCards());
#ifdef DEBUG
        PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: opponents' cards:\n");
        pokerGame->printOpponentCards();
        PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: \"Computer's AI\"");
#endif

        /* perform AI for each opponent */
        int i;
        for (i = 0; i < pokerGame->numOfOpponents; i++)
            pokerGame->opponentAI(i+1);
        /* resort the cards after the AI */
        pokerGame->sortOpponentCards();

        cout << "\nFinal cards in your hand: ";
        pokerGame->sortUserCards();
        pokerGame->printUserCards();

        cout << "Final opponents' cards:" << endl;
        pokerGame->printOpponentCards();

#ifdef DEBUG
        PRINT_COLOR(ANSI_COLOR_CYAN, "\ndebug: deck after being delt to opponents and user\n");
        pokerGame->printPile();
#endif

        pokerGame->evaluateHand(pokerGame->getUserCards(), 0); /* user hand */
        for (i = 0; i < pokerGame->numOfOpponents; i++)        /* opponents hands */
            pokerGame->evaluateHand(pokerGame->getOpponentsCards(i+1), i+1);
        pokerGame->showHands();

        pokerGame->determineWinner();

        /* ask to repeat the game and reset the deck of cards */
        pokerGame->repeatGame(&quit);
        pokerGame->resetDeck();
    }

    cout << "\nThank you for playing\n" << pokerGame->handsPlayed << ": Hands played\n"
         << pokerGame->handsWon << ": Hands won" << endl;

    delete pokerGame;
    PRINT_COLOR(ANSI_COLOR_CYAN, "\tBye!\n");

    return 0;
}