// File: 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
subq $0x30, %rsp
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x28(%rbp)
callq 0x3600
movq -0x28(%rbp), %rdi
subq $0x1, %rax
movl %eax, -0x18(%rbp)
movslq -0x18(%rbp), %rsi
callq 0x3620
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movb -0x11(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x29e2
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
leaq -0x20(%rbp), %rsi
callq 0x3460
movq -0x20(%rbp), %rax
cmpl $0xb, (%rax)
jne 0x29b8
movq -0x10(%rbp), %rax
movl 0x24(%rax), %eax
addl $0xb, %eax
cmpl $0x15, %eax
jle 0x29b8
movq -0x10(%rbp), %rax
movl 0x24(%rax), %ecx
addl $0x1, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
jmp 0x29e0
movq -0x10(%rbp), %rax
movl 0x24(%rax), %ecx
movq -0x20(%rbp), %rax
addl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rax
cmpl $0x15, 0x24(%rax)
jle 0x29de
movq -0x10(%rbp), %rax
movb $0x1, 0x6c(%rax)
jmp 0x29e0
jmp 0x2a46
movq -0x10(%rbp), %rdi
addq $0x50, %rdi
leaq -0x20(%rbp), %rsi
callq 0x3460
movq -0x20(%rbp), %rax
cmpl $0xb, (%rax)
jne 0x2a1e
movq -0x10(%rbp), %rax
movl 0x4c(%rax), %eax
addl $0xb, %eax
cmpl $0x15, %eax
jle 0x2a1e
movq -0x10(%rbp), %rax
movl 0x4c(%rax), %ecx
addl $0x1, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4c(%rax)
jmp 0x2a32
movq -0x10(%rbp), %rax
movl 0x4c(%rax), %ecx
movq -0x20(%rbp), %rax
addl (%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x4c(%rax)
movq -0x10(%rbp), %rax
cmpl $0x15, 0x4c(%rax)
jle 0x2a44
movq -0x10(%rbp), %rax
movb $0x1, 0x6d(%rax)
jmp 0x2a46
movq -0x20(%rbp), %rax
cmpl $0x2, (%rax)
je 0x2a73
movq -0x20(%rbp), %rax
cmpl $0x3, (%rax)
je 0x2a73
movq -0x20(%rbp), %rax
cmpl $0x4, (%rax)
je 0x2a73
movq -0x20(%rbp), %rax
cmpl $0x5, (%rax)
je 0x2a73
movq -0x20(%rbp), %rax
cmpl $0x6, (%rax)
jne 0x2a82
movq -0x28(%rbp), %rax
movl 0x30(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x30(%rax)
jmp 0x2ac3
movq -0x20(%rbp), %rax
cmpl $0x7, (%rax)
je 0x2a9d
movq -0x20(%rbp), %rax
cmpl $0x8, (%rax)
je 0x2a9d
movq -0x20(%rbp), %rax
cmpl $0x9, (%rax)
jne 0x2aa9
movq -0x28(%rbp), %rax
movl 0x30(%rax), %ecx
movl %ecx, 0x30(%rax)
jmp 0x2ac1
movq -0x20(%rbp), %rax
cmpl $0xa, (%rax)
jl 0x2abf
movq -0x28(%rbp), %rax
movl 0x30(%rax), %ecx
subl $0x1, %ecx
movl %ecx, 0x30(%rax)
jmp 0x2ac1
jmp 0x2ac3
movq -0x28(%rbp), %rdi
callq 0x3640
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)