// File: /workspace/github_cpp_makefile_star2_O1/ogghead[P]Moon_Boersma_Coe_CSCI2270_FinalProject/Blackjack.cpp
// Function: Blackjack::HitMe(player*, bool)
void Blackjack::HitMe(player* currentPlayer, bool secondHand)//this boolean checks
//if the hand to deal to is the 2nd one, if a player has split
{
    int index = deck.size() - 1;
    card* tmp = deck[index];

    if (secondHand == false) //if this was the first hand
    {
        currentPlayer->hand.push_back(tmp);
        if((tmp->value==11)&&(currentPlayer->handValue+11 > 21)) //if the ace being 11 would bust the player
        //than the ace would be worth 1
        {
            currentPlayer->handValue=currentPlayer->handValue+1;
        }
        else
        {
        currentPlayer->handValue=currentPlayer->handValue + tmp->value;
         if(currentPlayer->handValue>21){   //if the player busts, this would force them into stand position
             currentPlayer->stand=true;
         }
        }
    }

    else
    {
        currentPlayer->hand2.push_back(tmp);
        if((tmp->value==11)&&(currentPlayer->handValue2+11 > 21)){  //same as above but with hand 2
            currentPlayer->handValue2=currentPlayer->handValue2+1;
        }else{
        currentPlayer->handValue2=currentPlayer->handValue2 + tmp->value;
        }
         if(currentPlayer->handValue2>21){
             currentPlayer->stand2=true;
         }
    }

            //card counting math
    if (tmp->value == 2 || tmp->value == 3 || tmp->value == 4 ||
        tmp->value == 5 || tmp->value == 6)
        {
            cardCounter = cardCounter + 1;
        }
    else if (tmp->value == 7 || tmp->value == 8 || tmp->value == 9)
        {
            cardCounter = cardCounter;
        }
    else if (tmp->value >= 10)
        {
            cardCounter = cardCounter - 1;
        }
    deck.pop_back();
    //delete tmp;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rax
movq 0x8(%rdi), %rcx
subq %rax, %rcx
shlq $0x1d, %rcx
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
addq %rcx, %rsi
sarq $0x1d, %rsi
movq (%rax,%rsi), %rax
movq %rax, -0x18(%rbp)
testl %edx, %edx
je 0x2884
movq 0x58(%r14), %rsi
cmpq 0x60(%r14), %rsi
je 0x2898
movq %rax, (%rsi)
addq $0x8, 0x58(%r14)
jmp 0x28a5
movq 0x30(%r14), %rsi
cmpq 0x38(%r14), %rsi
je 0x28d3
movq %rax, (%rsi)
addq $0x8, 0x30(%r14)
jmp 0x28e0
leaq 0x50(%r14), %rdi
leaq -0x18(%rbp), %rdx
callq 0x30ce
movq -0x18(%rbp), %rax
movl (%rax), %eax
cmpl $0xb, %eax
jne 0x28c1
movl 0x4c(%r14), %ecx
cmpl $0xb, %ecx
jl 0x28c1
incl %ecx
movl %ecx, 0x4c(%r14)
jmp 0x28c5
addl %eax, 0x4c(%r14)
cmpl $0x16, 0x4c(%r14)
jl 0x290e
movb $0x1, 0x6d(%r14)
jmp 0x290e
leaq 0x28(%r14), %rdi
leaq -0x18(%rbp), %rdx
callq 0x30ce
movq -0x18(%rbp), %rax
movl (%rax), %eax
cmpl $0xb, %eax
jne 0x28fc
movl 0x24(%r14), %ecx
cmpl $0xb, %ecx
jl 0x28fc
incl %ecx
movl %ecx, 0x24(%r14)
jmp 0x290e
addl 0x24(%r14), %eax
movl %eax, 0x24(%r14)
cmpl $0x16, %eax
jl 0x290e
movb $0x1, 0x6c(%r14)
movq -0x18(%rbp), %rax
movl (%rax), %eax
movl $0x1, %ecx
leal -0x2(%rax), %edx
cmpl $0x5, %edx
jae 0x2926
addl %ecx, 0x30(%rbx)
jmp 0x292e
leal -0x7(%rax), %ecx
cmpl $0x3, %ecx
jae 0x293c
addq $-0x8, 0x8(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $0xa, %eax
jge 0x2921
jmp 0x292e