// File: /workspace/github_cpp_makefile_star2_O1/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, -0x38(%rbp)
movq %rdi, %r15
testl %edx, %edx
je 0x4953
callq 0x3dc8
movslq 0x8(%r15), %rcx
testq %rcx, %rcx
jle 0x4937
movq (%r15), %rsi
xorl %edx, %edx
cmpq %rax, (%rsi,%rdx,8)
je 0x4939
incq %rdx
cmpq %rdx, %rcx
jne 0x4929
xorl %edx, %edx
testl %edx, %edx
movq (%r15), %rax
movl %edx, %edx
cmoveq %rcx, %rdx
movq -0x8(%rax,%rdx,8), %r12
movq %r15, %rdi
callq 0x3dc8
jmp 0x4963
callq 0x3e38
movq %rax, %r12
movq %r15, %rdi
callq 0x3d78
movq %rax, %rbx
movl $0x0, -0x30(%rbp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x44f6
testb %al, %al
jne 0x4da0
movq %r12, %rdi
callq 0x2e58
testl %eax, %eax
jne 0x49c0
movslq 0x8(%r15), %rax
xorl %ecx, %ecx
testq %rax, %rax
jle 0x49ae
movq (%r15), %rsi
xorl %edx, %edx
cmpq %r12, (%rsi,%rdx,8)
je 0x49ac
incq %rdx
cmpq %rdx, %rax
jne 0x499c
jmp 0x49ae
movl %edx, %ecx
testl %ecx, %ecx
movq (%r15), %rdx
movl %ecx, %ecx
cmoveq %rax, %rcx
movq -0x8(%rdx,%rcx,8), %r12
jmp 0x496d
cmpq -0x38(%rbp), %r12
movq %rbx, -0x50(%rbp)
jne 0x49db
movq -0x38(%rbp), %rdi
callq 0x2a3c
testb %al, %al
je 0x4d3a
movl $0x30, %edi
callq 0x2130
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x58ac
movq %r15, -0x48(%rbp)
movl $0x50, %edi
callq 0x2130
movq %rax, %r13
movq %rax, %rdi
movq %r14, %rsi
callq 0x52c2
movq %r14, -0x40(%rbp)
xorl %eax, %eax
movq %r13, -0x58(%rbp)
movl %eax, -0x2c(%rbp)
movq %r13, %rdi
callq 0x553c
movq %rax, %r14
movq %rax, %rdi
callq 0x5f00
movq %r13, %rdi
callq 0x5558
movq (%rax), %rcx
movq %r13, %r15
cmpq 0x8(%rax), %rcx
jne 0x4a88
movq %r13, %r15
movq %r15, %rdi
callq 0x5562
movq (%rax), %rcx
cmpq 0x8(%rax), %rcx
je 0x4a88
movq %r15, %rdi
callq 0x544c
movq %rax, %r15
movq %rax, %rdi
callq 0x5532
movq %r14, %rdi
movl %eax, %esi
callq 0x5d2a
movq %r15, %rdi
callq 0x5558
movq (%rax), %rcx
cmpq 0x8(%rax), %rcx
je 0x4a49
movq %r15, %rdi
callq 0x5558
movq (%rax), %rcx
cmpq 0x8(%rax), %rcx
je 0x4b6d
xorl %edi, %edi
callq 0x2100
movl %eax, %edi
callq 0x2110
movq %r15, %rdi
callq 0x5558
movq %rax, %rbx
callq 0x2050
movslq %eax, %r13
movq %r15, %rdi
callq 0x5558
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
movq %r13, %rax
xorl %edx, %edx
divq %rcx
movq (%rbx), %rcx
movq 0x8(%rbx), %rax
subq %rcx, %rax
sarq $0x2, %rax
cmpq %rdx, %rax
jbe 0x4e07
movl (%rcx,%rdx,4), %ebx
movq %r14, %rdi
movl %ebx, %esi
callq 0x5d2a
movq %r15, %rdi
movl %ebx, %esi
movq %r14, %rdx
callq 0x5578
movq %rax, %r15
jmp 0x4b6d
xorl %edi, %edi
callq 0x2100
movl %eax, %edi
callq 0x2110
movq %r14, %rdi
callq 0x5d20
movq %rax, %rbx
callq 0x2050
movslq %eax, %r13
movq %r14, %rdi
callq 0x5d20
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x2, %rcx
movq %r13, %rax
xorl %edx, %edx
divq %rcx
movq (%rbx), %rcx
movq 0x8(%rbx), %rax
subq %rcx, %rax
sarq $0x2, %rax
cmpq %rdx, %rax
jbe 0x4e07
movl (%rcx,%rdx,4), %esi
movq %r14, %rdi
callq 0x5d2a
movq %r14, %rdi
callq 0x5d20
movq (%rax), %rcx
cmpq 0x8(%rax), %rcx
jne 0x4b0f
testq %r15, %r15
je 0x4bb0
movq %r15, %rdi
callq 0x5550
movzbl %al, %esi
movq %r14, %rdi
callq 0x5dea
movq %r15, %rdi
movl %eax, %esi
callq 0x556c
movq %r15, %rdi
callq 0x5546
movq %rax, %r15
testq %rax, %rax
jne 0x4b83
movl -0x2c(%rbp), %eax
incl %eax
cmpl $0x3, %eax
movq -0x58(%rbp), %r13
jne 0x4a1c
movq %r13, %rdi
callq 0x5562
movq 0x8(%rax), %rcx
cmpq (%rax), %rcx
je 0x4c3a
xorl %r15d, %r15d
xorl %r14d, %r14d
movq %r13, %rdi
callq 0x5562
movq (%rax), %rcx
movq 0x8(%rax), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %r15, %rdx
jbe 0x4e1b
movq (%rcx,%r15,8), %rbx
movq %rbx, %rdi
callq 0x5528
cmpl %r14d, %eax
jle 0x4c1f
movq %rbx, %rdi
callq 0x5528
movl %eax, %r14d
movq %rbx, %rdi
callq 0x5532
movl %eax, -0x2c(%rbp)
incq %r15
movq %r13, %rdi
callq 0x5562
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x4bd9
movq %r13, %rdi
callq 0x53be
movl $0x50, %esi
movq %r13, %rdi
callq 0x2140
xorl %eax, %eax
movl -0x2c(%rbp), %ebx
cmpl $0x2, %ebx
sete %al
movl -0x30(%rbp), %esi
addl %eax, %esi
cmpl $0x6, %esi
movl $0x0, %eax
cmovgel %eax, %esi
movl $0x1, %eax
cmovgel %eax, %ebx
movq -0x48(%rbp), %r15
movslq 0x8(%r15), %rax
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
testq %rax, %rax
movl %esi, -0x30(%rbp)
jle 0x4ca0
movq (%r15), %rdx
xorl %ecx, %ecx
cmpq %r12, (%rdx,%rcx,8)
je 0x4c9d
incq %rcx
cmpq %rcx, %rax
jne 0x4c8d
jmp 0x4ca0
movl %ecx, %r14d
movq %r15, %rdi
movq %r12, %rsi
callq 0x3ebc
movq %r12, %rdi
movl %ebx, %esi
movl %r14d, %edx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0x2eba
movl %eax, %r14d
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
callq 0x5d00
movl $0x30, %esi
movq %rbx, %rdi
callq 0x2140
cmpl $0x2, %r14d
movq -0x50(%rbp), %rbx
jne 0x4cf2
movq %r15, %rdi
movq %r12, %rsi
callq 0x3ebc
movq %rax, %rbx
movq %r12, %rax
cmpq %rbx, %r12
je 0x4d2c
movslq 0x8(%r15), %rax
xorl %ecx, %ecx
testq %rax, %rax
jle 0x4d1c
movq (%r15), %rsi
xorl %edx, %edx
cmpq %r12, (%rsi,%rdx,8)
je 0x4d1a
incq %rdx
cmpq %rdx, %rax
jne 0x4d0a
jmp 0x4d1c
movl %edx, %ecx
testl %ecx, %ecx
movq (%r15), %rdx
movl %ecx, %ecx
cmoveq %rax, %rcx
movq -0x8(%rdx,%rcx,8), %rax
cmpq %rbx, %r12
movq %rax, %r12
jne 0x496d
jmp 0x4da0
callq 0x4e4c
movl %eax, %r14d
movslq 0x8(%r15), %rax
movq %r15, %rcx
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testq %rax, %rax
jle 0x4d70
movq %rcx, %rbx
movq (%rcx), %rdx
xorl %ecx, %ecx
movq -0x38(%rbp), %rsi
cmpq %rsi, (%rdx,%rcx,8)
je 0x4d75
incq %rcx
cmpq %rcx, %rax
jne 0x4d60
jmp 0x4d78
movq %rcx, %rbx
jmp 0x4d78
movl %ecx, %r15d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3ebc
movq -0x38(%rbp), %rdi
movl %r14d, %esi
movl %r15d, %edx
movq %rbx, %r15
movq %rax, %rcx
xorl %r8d, %r8d
callq 0x2eba
jmp 0x4cda
movq %r15, %rdi
callq 0x4fa2
movq %r15, %rdi
callq 0x4fda
cmpl $0x0, 0x8(%r15)
setg %r14b
jle 0x4df5
movq (%r15), %rax
movq (%rax), %rsi
movq %r15, %rdi
callq 0x44f6
testb %al, %al
jne 0x4df5
movl $0x1, %ebx
movslq 0x8(%r15), %rax
cmpq %rax, %rbx
setl %r14b
jge 0x4df5
movq (%r15), %rax
movq (%rax,%rbx,8), %rsi
movq %r15, %rdi
callq 0x44f6
incq %rbx
testb %al, %al
je 0x4dd2
movl %r14d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2349(%rip), %rdi      # 0x7157
movq %rdx, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2180
leaq 0x2335(%rip), %rdi      # 0x7157
movq %r15, %rsi
jmp 0x4e14
movq %rax, %rbx
movl $0x50, %esi
movq %r13, %rdi
jmp 0x4e3f
movq %rax, %rbx
movl $0x30, %esi
movq %r14, %rdi
callq 0x2140
movq %rbx, %rdi
callq 0x21c0