// File: /workspace/github_cpp_makefile_star2_O2/fredericmarchand[P]TexasHoldem/Game.cpp
// Function: Game::playRound(Player*, bool)
bool Game::playRound(Player *me, bool firstRound)
{
    Player *last = NULL;
    Player *turn = NULL;

    //If its the first round, the players turn is the player after the big blind
    if (firstRound)
    {
        turn = getNextPlayer(getBigBlindPlayer());
        last = getBigBlindPlayer();
    }
    else //Otherwise its the small blind player who goes first
    {
        turn = getSmallBlindPlayer();
        last = getDealer();
    }

    int raiseCount = 0;
    while (1)
    {

        if (checkLastPlayerRemaining(turn) == true)
        {
            break;
        }

        if (turn->getState().move == FOLD)
        {
            turn = getNextPlayer(turn);
            continue;
        }

        Move move = CHECK;
        if (turn == me && !me->isAI())
        {
            move = getMove();
            me->doMove(move, getPlayerIndex(me), getPreviousPlayer(turn), false);
        }
        else
        {
            NodeState *state = new NodeState(this, turn);
            move = UCTSearch(state, UCT_DEPTH);
            if (move == BET)
            {
                raiseCount++;
            }
            if (raiseCount > 5)
            {
                raiseCount = 0;
                move = CHECK;
            }
            move = turn->doMove(move, getPlayerIndex(turn), getPreviousPlayer(turn), false);
            delete state;
        }

        // Change last player to make a move
        if (move == BET)
        {
            last = getPreviousPlayer(turn);
        }

        // Exit condition
        if (turn == last)
        {
            break;
        }

        turn = getNextPlayer(turn);
    }

    addBetsToPot();
    setPlayerStates();

    for (int i = 0; i < numPlayers; ++i)
    {
        if (checkLastPlayerRemaining(players[i]) == true)
        {
            return true;
        }
    }

    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r12
movq %rdi, %r15
testl %edx, %edx
je 0x4174
callq 0x3912
movq %r15, %rdi
movq %rax, %rsi
callq 0x39c6
movq %rax, %r13
movq %r15, %rdi
callq 0x3912
jmp 0x4184
callq 0x3982
movq %rax, %r13
movq %r15, %rdi
callq 0x38ce
movq %rax, %rbx
movl $0x0, -0x2c(%rbp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x3ea6
testb %al, %al
jne 0x44ca
movq %r13, %rdi
callq 0x2b2a
testl %eax, %eax
jne 0x41bd
movq %r15, %rdi
movq %r13, %rsi
callq 0x39c6
movq %rax, %r13
jmp 0x418e
cmpq %r12, %r13
movq %rbx, -0x58(%rbp)
jne 0x41d6
movq %r12, %rdi
callq 0x28b2
testb %al, %al
je 0x4495
pushq $0x30
popq %rdi
callq 0x2170
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
movq %r13, -0x50(%rbp)
movq %r13, %rdx
callq 0x5060
movq %r12, -0x40(%rbp)
movq %r15, -0x48(%rbp)
pushq $0x50
popq %rdi
callq 0x2170
movq %rax, %r13
movq %rax, %rdi
movq %r14, -0x38(%rbp)
movq %r14, %rsi
callq 0x4998
xorl %eax, %eax
cmpl $0x3, %eax
je 0x438f
movl %eax, -0x30(%rbp)
movq %r13, %rdi
callq 0x4bd2
movq %rax, %r14
movq %rax, %rdi
callq 0x5578
movq %r13, %r12
movq %r12, %rdi
callq 0x4bee
movq (%rax), %rcx
cmpq 0x8(%rax), %rcx
jne 0x427a
movq %r12, %rdi
callq 0x4bf8
movq (%rax), %rcx
cmpq 0x8(%rax), %rcx
je 0x427a
movq %r12, %rdi
callq 0x4aec
movq %rax, %r12
movq %rax, %rdi
callq 0x4bc8
movq %r14, %rdi
movl %eax, %esi
callq 0x53f8
jmp 0x4239
movq %r12, %rdi
callq 0x4bee
movq (%rax), %rcx
cmpq 0x8(%rax), %rcx
je 0x4345
xorl %edi, %edi
callq 0x2140
movl %eax, %edi
callq 0x2150
movq %r12, %rdi
callq 0x4bee
movq %rax, %rbx
callq 0x2040
movslq %eax, %r15
movq %r12, %rdi
callq 0x4bee
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
movq %r15, %rax
xorl %edx, %edx
divq %rcx
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x48e6
movl (%rax), %ebx
movq %r14, %rdi
movl %ebx, %esi
callq 0x53f8
movq %r12, %rdi
movl %ebx, %esi
movq %r14, %rdx
callq 0x4c0e
movq %rax, %r12
jmp 0x4345
xorl %edi, %edi
callq 0x2140
movl %eax, %edi
callq 0x2150
movq %r14, %rdi
callq 0x53ee
movq %rax, %rbx
callq 0x2040
movslq %eax, %r15
movq %r14, %rdi
callq 0x53ee
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
movq %r15, %rax
xorl %edx, %edx
divq %rcx
movq %rbx, %rdi
movq %rdx, %rsi
callq 0x48e6
movl (%rax), %esi
movq %r14, %rdi
callq 0x53f8
movq %r14, %rdi
callq 0x53ee
movq (%rax), %rcx
cmpq 0x8(%rax), %rcx
jne 0x42f4
jmp 0x4380
movq %r12, %rdi
callq 0x4be6
movzbl %al, %esi
movq %r14, %rdi
callq 0x548e
movq %r12, %rdi
movl %eax, %esi
callq 0x4c02
movq %r12, %rdi
callq 0x4bdc
movq %rax, %r12
testq %r12, %r12
jne 0x4358
movl -0x30(%rbp), %eax
incl %eax
jmp 0x4217
xorl %r12d, %r12d
xorl %r14d, %r14d
movq %r13, %rdi
callq 0x4bf8
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x3, %rcx
movq %r13, %rdi
cmpq %r12, %rcx
jbe 0x43eb
callq 0x4bf8
movq %rax, %rdi
movq %r12, %rsi
callq 0x4908
movq (%rax), %rbx
movq %rbx, %rdi
callq 0x4bbe
cmpl %r14d, %eax
jle 0x43e6
movq %rbx, %rdi
callq 0x4bbe
movl %eax, %r14d
movq %rbx, %rdi
callq 0x4bc8
movl %eax, %r15d
incq %r12
jmp 0x4395
callq 0x4a6a
movq %r13, %rdi
pushq $0x50
popq %rsi
callq 0x2180
xorl %eax, %eax
cmpl $0x2, %r15d
sete %al
movl -0x2c(%rbp), %ecx
addl %eax, %ecx
cmpl $0x6, %ecx
movl $0x0, %eax
cmovgel %eax, %ecx
movl %ecx, -0x2c(%rbp)
pushq $0x1
popq %rax
cmovgel %eax, %r15d
movl %r15d, %r14d
movq -0x48(%rbp), %r15
movq %r15, %rdi
movq -0x50(%rbp), %r13
movq %r13, %rsi
callq 0x3a5e
movl %eax, %ebx
movq %r15, %rdi
movq %r13, %rsi
callq 0x39fa
movq %r13, %rdi
movl %r14d, %esi
movl %ebx, %edx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0x2b7e
movl %eax, %r14d
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
callq 0x53e0
movq %rbx, %rdi
pushq $0x30
popq %rsi
callq 0x2180
movq -0x40(%rbp), %r12
cmpl $0x2, %r14d
movq -0x58(%rbp), %rbx
jne 0x448a
movq %r15, %rdi
movq %r13, %rsi
callq 0x39fa
movq %rax, %rbx
cmpq %rbx, %r13
jne 0x41ad
jmp 0x44ca
callq 0x4536
movl %eax, %r14d
movq %r15, %rdi
movq %r12, %rsi
callq 0x3a5e
movl %eax, %ebx
movq %r15, %rdi
movq %r13, %rsi
callq 0x39fa
movq %r12, %rdi
movl %r14d, %esi
movl %ebx, %edx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0x2b7e
jmp 0x4472
movq %r15, %rdi
callq 0x4642
movq %r15, %rdi
callq 0x4676
xorl %ecx, %ecx
movq %rcx, %rbx
movslq 0x8(%r15), %r14
cmpq %r14, %rcx
jge 0x44ff
movq (%r15), %rax
movq (%rax,%rbx,8), %rsi
movq %r15, %rdi
callq 0x3ea6
leaq 0x1(%rbx), %rcx
testb %al, %al
je 0x44dc
cmpq %r14, %rbx
setl %al
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
pushq $0x50
popq %rsi
movq %r13, %rdi
jmp 0x4528
movq %rax, %rbx
pushq $0x30
popq %rsi
movq %r14, %rdi
callq 0x2180
movq %rbx, %rdi
callq 0x21f0
nop