// File: /workspace/github_cpp_makefile_star2_O2/fredericmarchand[P]TexasHoldem/main.cpp
// Function: main
int main(int argc, char** argv) 
{
    bool AI_game = true;
    Game *game = new Game(2);
    Player *me = game->getPlayers()[0];
    me->setDealer(true);

    if (argc > 1)
    {
        AI_game = false;
        me->setAI(false);
    }

    while (1)
    {
        //Check if the game is over
        if (game->getPlayers()[0]->getChipCount() == 0 || game->getPlayers()[1]->getChipCount() == 0)
        {
            break;
        }

        game->resetDeck();
        game->clearPlayerStates();
        game->rotateDealerChip();

        printLabel("Starting new game");
        cout << "Small Blind: $" << SMALL_BLIND << endl;
        cout << "Big Blind:   $" << BIG_BLIND << endl;
        cout << "Dealer: Player " << game->getPlayerIndex(game->getDealer()) << endl;
        game->shuffleDeck(0);

        //Blinds
        game->getSmallBlindPlayer()->bet(SMALL_BLIND);
        game->getBigBlindPlayer()->bet(BIG_BLIND);

        game->distributeCards();
        me->printHand();

        if (game->playRound(me, true) == true)
            goto end;

        //Finish blinds round
        game->printPot();
        
        //Flop
        printLabel("Flop");
        game->flipFlop(VERBOSE);

        //Round of betting
        if (game->playRound(me, false))
            goto end;

        game->printPot();

        //Turn
        printLabel("Turn");
        game->flipTurn(VERBOSE);

        //Round of betting
        if (game->playRound(me, false))
            goto end;

        game->printPot();

        //River
        printLabel("River");
        game->flipRiver(VERBOSE);

        //Final round of betting
        game->playRound(me, false);

        game->printPot();

end:
        //Check Results and give pot to winner
        cout << endl;
        int winnerIndex = game->determineWinner();
        if (winnerIndex == 0)
        {
            game->getPlayers()[0]->incHandsWon();
        }
        else if (winnerIndex == 1)
        {
            game->getPlayers()[1]->incHandsWon();
        }

        for (int i = 0; i < game->getPlayerCount(); ++i)
        {
            cout << "Player " << i << " has won " << game->getPlayers()[i]->getHandsWon() << " games" << endl;
        }
        
        cin.ignore();
        //break;
    }

    //Print winner
    cout << "The winner is: " << (game->getPlayers()[0]->getChipCount() == 0 ? "Player 1" : "Player 0") << endl;

    delete game;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %edi, %r15d
movl $0x1e0, %edi            # imm = 0x1E0
callq 0x2170
movq %rax, %rbx
pushq $0x2
popq %rsi
movq %rax, %rdi
callq 0x350c
movq %rbx, %rdi
callq 0x3748
movq (%rax), %r14
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x28c6
cmpl $0x1, %r15d
jle 0x5ad4
movq %r14, %rdi
xorl %esi, %esi
callq 0x28bc
jmp 0x5ad4
movq %rbx, %rdi
callq 0x3748
movq 0x8(%rax), %rdi
callq 0x2880
testl %eax, %eax
je 0x5aec
movq %rbx, %rdi
callq 0x360c
movq %rbx, %rdi
callq 0x46c4
movq %rbx, %rdi
callq 0x3876
leaq 0x9b5(%rip), %rsi       # 0x61d2
leaq -0xb0(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x270a
leaq -0xb0(%rbp), %rdi
callq 0x56fc
leaq -0xb0(%rbp), %rdi
callq 0x20a0
movq 0x3784(%rip), %r13      # 0x8fd0
leaq 0x991(%rip), %rsi       # 0x61e4
movq %r13, %rdi
callq 0x2160
pushq $0x32
popq %r15
movq %rax, %rdi
movl %r15d, %esi
callq 0x21e0
movq %rax, %rdi
callq 0x20b0
leaq 0x97a(%rip), %rsi       # 0x61f3
movq %r13, %rdi
callq 0x2160
pushq $0x64
popq %r12
movq %rax, %rdi
movl %r12d, %esi
callq 0x21e0
movq %rax, %rdi
callq 0x20b0
leaq 0x963(%rip), %rsi       # 0x6202
movq %r13, %rdi
callq 0x2160
movq %rax, %r13
movq %rbx, %rdi
callq 0x38ce
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3a5e
movq %r13, %rdi
movl %eax, %esi
callq 0x21e0
movq %rax, %rdi
callq 0x20b0
movq %rbx, %rdi
xorl %esi, %esi
callq 0x3d66
movq %rbx, %rdi
callq 0x3982
movq %rax, %rdi
movl %r15d, %esi
callq 0x2b40
movq %rbx, %rdi
callq 0x3912
movq %rax, %rdi
movl %r12d, %esi
callq 0x2b40
movq %rbx, %rdi
callq 0x3cfe
movq %r14, %rdi
callq 0x28d0
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x413c
testb %al, %al
jne 0x5a14
movq %rbx, %rdi
callq 0x4080
leaq 0x8de(%rip), %rsi       # 0x6212
leaq -0x90(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x270a
leaq -0x90(%rbp), %rdi
callq 0x56fc
leaq -0x90(%rbp), %rdi
callq 0x20a0
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x3a84
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x413c
testb %al, %al
jne 0x5a14
movq %rbx, %rdi
callq 0x4080
leaq 0x88c(%rip), %rsi       # 0x6217
leaq -0x70(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x270a
leaq -0x70(%rbp), %rdi
callq 0x56fc
leaq -0x70(%rbp), %rdi
callq 0x20a0
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x3cb2
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x413c
testb %al, %al
jne 0x5a14
movq %rbx, %rdi
callq 0x4080
leaq 0x847(%rip), %rsi       # 0x621c
leaq -0x50(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x270a
leaq -0x50(%rbp), %rdi
callq 0x56fc
leaq -0x50(%rbp), %rdi
callq 0x20a0
pushq $0x1
popq %rsi
movq %rbx, %rdi
callq 0x3cd8
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x413c
movq %rbx, %rdi
callq 0x4080
movq 0x35b5(%rip), %rdi      # 0x8fd0
callq 0x20b0
movq %rbx, %rdi
callq 0x3dc4
cmpl $0x1, %eax
je 0x5a3b
testl %eax, %eax
jne 0x5a4f
movq %rbx, %rdi
callq 0x3748
jmp 0x5a47
movq %rbx, %rdi
callq 0x3748
addq $0x8, %rax
movq (%rax), %rdi
callq 0x34f8
xorl %r15d, %r15d
movq %rbx, %rdi
callq 0x373e
cltq
cmpq %rax, %r15
jge 0x5ac8
movq 0x3568(%rip), %rdi      # 0x8fd0
leaq 0x79b(%rip), %rsi       # 0x620a
callq 0x2160
movq %rax, %rdi
movl %r15d, %esi
callq 0x21e0
leaq 0x79c(%rip), %rsi       # 0x6222
movq %rax, %rdi
callq 0x2160
movq %rax, %r12
movq %rbx, %rdi
callq 0x3748
movq (%rax,%r15,8), %rdi
callq 0x3502
movq %r12, %rdi
movl %eax, %esi
callq 0x21e0
leaq 0x779(%rip), %rsi       # 0x622c
movq %rax, %rdi
callq 0x2160
movq %rax, %rdi
callq 0x20b0
incq %r15
jmp 0x5a52
movq 0x3511(%rip), %rdi      # 0x8fe0
callq 0x2210
movq %rbx, %rdi
callq 0x3748
movq (%rax), %rdi
callq 0x2880
testl %eax, %eax
jne 0x57e5
movq 0x34dd(%rip), %rdi      # 0x8fd0
leaq 0x739(%rip), %rsi       # 0x6233
callq 0x2160
movq %rax, %r14
movq %rbx, %rdi
callq 0x3748
movq (%rax), %rdi
callq 0x2880
testl %eax, %eax
leaq 0x728(%rip), %rax       # 0x6243
leaq 0x72a(%rip), %rsi       # 0x624c
cmoveq %rax, %rsi
movq %r14, %rdi
callq 0x2160
movq %rax, %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x37e8
movl $0x1e0, %esi            # imm = 0x1E0
movq %rbx, %rdi
callq 0x2180
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movl $0x1e0, %esi            # imm = 0x1E0
movq %rbx, %rdi
callq 0x2180
jmp 0x5ba9
movq %rax, %r14
leaq -0x50(%rbp), %rdi
jmp 0x5ba4
jmp 0x5b95
movq %rax, %r14
leaq -0x70(%rbp), %rdi
jmp 0x5ba4
jmp 0x5b95
movq %rax, %r14
leaq -0x90(%rbp), %rdi
jmp 0x5ba4
jmp 0x5b95
movq %rax, %r14
jmp 0x5ba9
movq %rax, %r14
leaq -0xb0(%rbp), %rdi
callq 0x20a0
movq %r14, %rdi
callq 0x21f0