// File: /workspace/github_cpp_makefile_star2_O3/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 0x4985
callq 0x3e68
movslq 0x8(%r15), %rdx
movq (%r15), %rcx
testq %rdx, %rdx
jle 0x49a0
movl %edx, %esi
xorl %edi, %edi
cmpq %rax, (%rcx,%rdi,8)
je 0x4997
incq %rdi
cmpq %rdi, %rsi
jne 0x4975
jmp 0x49a0
callq 0x3ed2
movq %rax, %r12
movq %r15, %rdi
callq 0x3e18
jmp 0x49ad
testq %rdi, %rdi
cmovnel %edi, %esi
movq %rsi, %rdx
movq -0x8(%rcx,%rdx,8), %r12
movq %r15, %rdi
callq 0x3e68
movq %rax, %rbx
movq %r15, %rdi
movq %r12, %rsi
callq 0x453c
testb %al, %al
je 0x4a04
movq %r15, %rdi
callq 0x4fd6
movq %r15, %rdi
callq 0x500e
cmpl $0x0, 0x8(%r15)
jle 0x4e29
xorl %ebx, %ebx
movq (%r15), %rax
movq (%rax,%rbx,8), %rsi
movq %r15, %rdi
callq 0x453c
testb %al, %al
jne 0x4e2b
incq %rbx
movslq 0x8(%r15), %rcx
cmpq %rcx, %rbx
jl 0x49dc
jmp 0x4e2b
movl $0x0, -0x30(%rbp)
movq %r12, %rdi
callq 0x2f52
testl %eax, %eax
jne 0x4a42
movslq 0x8(%r15), %rcx
movq (%r15), %rax
testq %rcx, %rcx
jle 0x4da6
movl %ecx, %edx
xorl %esi, %esi
cmpq %r12, (%rax,%rsi,8)
je 0x4d9d
incq %rsi
cmpq %rsi, %rdx
jne 0x4a2b
jmp 0x4da6
cmpq -0x38(%rbp), %r12
movq %rbx, -0x50(%rbp)
jne 0x4a5d
movq -0x38(%rbp), %rdi
callq 0x2a40
testb %al, %al
je 0x4dc3
movl $0x30, %edi
callq 0x2130
movq %rax, %r14
movq %rax, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x58b8
movq %r15, -0x48(%rbp)
movl $0x50, %edi
callq 0x2130
movq %rax, %r13
movq %rax, %rdi
movq %r14, %rsi
callq 0x52b6
movq %r14, -0x40(%rbp)
xorl %eax, %eax
movq %r13, -0x58(%rbp)
movl %eax, -0x2c(%rbp)
movq %r13, %rdi
callq 0x552e
movq %rax, %r14
movq %rax, %rdi
callq 0x5f12
movq %r13, %rdi
callq 0x554a
movq (%rax), %rcx
movq %r13, %r15
cmpq 0x8(%rax), %rcx
jne 0x4b0a
movq %r13, %r15
movq %r15, %rdi
callq 0x5554
movq (%rax), %rcx
cmpq 0x8(%rax), %rcx
je 0x4b0a
movq %r15, %rdi
callq 0x5444
movq %rax, %r15
movq %rax, %rdi
callq 0x5524
movq %r14, %rdi
movl %eax, %esi
callq 0x5d36
movq %r15, %rdi
callq 0x554a
movq (%rax), %rcx
cmpq 0x8(%rax), %rcx
je 0x4acb
movq %r15, %rdi
callq 0x554a
movq (%rax), %rcx
cmpq 0x8(%rax), %rcx
je 0x4bef
xorl %edi, %edi
callq 0x2100
movl %eax, %edi
callq 0x2110
movq %r15, %rdi
callq 0x554a
movq %rax, %rbx
callq 0x2050
movslq %eax, %r13
movq %r15, %rdi
callq 0x554a
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 0x4e3a
movl (%rcx,%rdx,4), %ebx
movq %r14, %rdi
movl %ebx, %esi
callq 0x5d36
movq %r15, %rdi
movl %ebx, %esi
movq %r14, %rdx
callq 0x556a
movq %rax, %r15
jmp 0x4bef
xorl %edi, %edi
callq 0x2100
movl %eax, %edi
callq 0x2110
movq %r14, %rdi
callq 0x5d2c
movq %rax, %rbx
callq 0x2050
movslq %eax, %r13
movq %r14, %rdi
callq 0x5d2c
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 0x4e3a
movl (%rcx,%rdx,4), %esi
movq %r14, %rdi
callq 0x5d36
movq %r14, %rdi
callq 0x5d2c
movq (%rax), %rcx
cmpq 0x8(%rax), %rcx
jne 0x4b91
testq %r15, %r15
je 0x4c32
movq %r15, %rdi
callq 0x5542
movzbl %al, %esi
movq %r14, %rdi
callq 0x5dfa
movq %r15, %rdi
movl %eax, %esi
callq 0x555e
movq %r15, %rdi
callq 0x5538
movq %rax, %r15
testq %rax, %rax
jne 0x4c05
movl -0x2c(%rbp), %eax
incl %eax
cmpl $0x3, %eax
movq -0x58(%rbp), %r13
jne 0x4a9e
movq %r13, %rdi
callq 0x5554
movq 0x8(%rax), %rcx
cmpq (%rax), %rcx
je 0x4cbc
xorl %r15d, %r15d
xorl %r14d, %r14d
movq %r13, %rdi
callq 0x5554
movq (%rax), %rcx
movq 0x8(%rax), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %r15, %rdx
jbe 0x4e4e
movq (%rcx,%r15,8), %rbx
movq %rbx, %rdi
callq 0x551a
cmpl %r14d, %eax
jle 0x4ca1
movq %rbx, %rdi
callq 0x551a
movl %eax, %r14d
movq %rbx, %rdi
callq 0x5524
movl %eax, -0x2c(%rbp)
incq %r15
movq %r13, %rdi
callq 0x5554
movq 0x8(%rax), %rcx
subq (%rax), %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
ja 0x4c5b
movq %r13, %rdi
callq 0x53b2
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 0x4d22
movq (%r15), %rdx
xorl %ecx, %ecx
cmpq %r12, (%rdx,%rcx,8)
je 0x4d1f
incq %rcx
cmpq %rcx, %rax
jne 0x4d0f
jmp 0x4d22
movl %ecx, %r14d
movq %r15, %rdi
movq %r12, %rsi
callq 0x3f4e
movq %r12, %rdi
movl %ebx, %esi
movl %r14d, %edx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0x2faa
movl %eax, %r14d
movq -0x40(%rbp), %rbx
movq %rbx, %rdi
callq 0x5d0c
movl $0x30, %esi
movq %rbx, %rdi
callq 0x2140
cmpl $0x2, %r14d
movq -0x50(%rbp), %rbx
jne 0x4d74
movq %r15, %rdi
movq %r12, %rsi
callq 0x3f4e
movq %rax, %rbx
cmpq %rbx, %r12
je 0x49bf
movslq 0x8(%r15), %rcx
movq (%r15), %rax
testq %rcx, %rcx
jle 0x4da6
movl %ecx, %edx
xorl %esi, %esi
cmpq %r12, (%rax,%rsi,8)
je 0x4d9d
incq %rsi
cmpq %rsi, %rdx
jne 0x4d8d
jmp 0x4da6
testq %rsi, %rsi
cmovnel %esi, %edx
movq %rdx, %rcx
movq -0x8(%rax,%rcx,8), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x453c
testb %al, %al
je 0x4a0b
jmp 0x49bf
callq 0x4e80
movl %eax, %r14d
movslq 0x8(%r15), %rax
movq %r15, %rcx
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
testq %rax, %rax
jle 0x4df9
movq %rcx, %rbx
movq (%rcx), %rdx
xorl %ecx, %ecx
movq -0x38(%rbp), %rsi
cmpq %rsi, (%rdx,%rcx,8)
je 0x4dfe
incq %rcx
cmpq %rcx, %rax
jne 0x4de9
jmp 0x4e01
movq %rcx, %rbx
jmp 0x4e01
movl %ecx, %r15d
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3f4e
movq -0x38(%rbp), %rdi
movl %r14d, %esi
movl %r15d, %edx
movq %rbx, %r15
movq %rax, %rcx
xorl %r8d, %r8d
callq 0x2faa
jmp 0x4d5c
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2316(%rip), %rdi      # 0x7157
movq %rdx, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x2180
leaq 0x2302(%rip), %rdi      # 0x7157
movq %r15, %rsi
jmp 0x4e47
movq %rax, %rbx
movl $0x50, %esi
movq %r13, %rdi
jmp 0x4e72
movq %rax, %rbx
movl $0x30, %esi
movq %r14, %rdi
callq 0x2140
movq %rbx, %rdi
callq 0x21c0
nop