// File: ljc2154[P]Rummy/rummy.cpp
// Function: removeWorstCard(State&)
int removeWorstCard(State &state)
{
	State testState = state;

	/* Empty agent hand of testState */
	while (testState.agentHand.empty() == false)
		testState.agentHand.pop_back();

	int maxEval = 0;
	int maxEvalIndex = 0;
	int eval = 0;

	/* Find the card that when removed produces the highest score */
	for (int i = 0; i < state.agentHand.size(); i++)
	{
		for (int j = 0; j < state.agentHand.size(); j++)
		{
			if (i != j)
				testState.agentHand.push_back(state.agentHand[j]);
		}

		eval = evaluate(testState);
		if (eval > maxEval)
		{
			maxEval = eval;
			maxEvalIndex = i;
		}

		/* Empty agent hand of testState */
		while (testState.agentHand.empty() == false)
			testState.agentHand.pop_back();
	}

	int returnVal = state.agentHand[maxEvalIndex];

	/* Remove worst card */
	state.agentHand.erase(state.agentHand.begin() + maxEvalIndex);

	return returnVal;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x70(%rbp), %rdi
callq 0x3fe0
leaq -0x70(%rbp), %rdi
addq $0x18, %rdi
callq 0x48b0
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x3d82
leaq -0x70(%rbp), %rdi
addq $0x18, %rdi
callq 0x4300
jmp 0x3d5c
movl $0x0, -0x74(%rbp)
movl $0x0, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movl $0x0, -0x80(%rbp)
movslq -0x80(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x8(%rbp), %rdi
addq $0x18, %rdi
callq 0x4130
movq %rax, %rcx
movq -0x130(%rbp), %rax
cmpq %rcx, %rax
jae 0x3f13
movl $0x0, -0x84(%rbp)
movslq -0x84(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x8(%rbp), %rdi
addq $0x18, %rdi
callq 0x4130
movq %rax, %rcx
movq -0x138(%rbp), %rax
cmpq %rcx, %rax
jae 0x3e67
movl -0x80(%rbp), %eax
cmpl -0x84(%rbp), %eax
je 0x3e51
leaq -0x58(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x8(%rbp), %rdi
addq $0x18, %rdi
movslq -0x84(%rbp), %rsi
callq 0x4110
movq -0x140(%rbp), %rdi
movq %rax, %rsi
callq 0x4170
jmp 0x3e38
jmp 0x3e51
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x3fbf
jmp 0x3e53
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x3dd3
leaq -0x100(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x3fe0
jmp 0x3e79
leaq -0x100(%rbp), %rdi
callq 0x3100
movl %eax, -0x144(%rbp)
jmp 0x3e8d
movl -0x144(%rbp), %eax
movl %eax, -0x7c(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x40c0
movl -0x7c(%rbp), %eax
cmpl -0x74(%rbp), %eax
jle 0x3edb
movl -0x7c(%rbp), %eax
movl %eax, -0x74(%rbp)
movl -0x80(%rbp), %eax
movl %eax, -0x78(%rbp)
jmp 0x3edb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x40c0
jmp 0x3fbf
jmp 0x3edd
leaq -0x70(%rbp), %rdi
addq $0x18, %rdi
callq 0x48b0
andb $0x1, %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x3f03
leaq -0x70(%rbp), %rdi
addq $0x18, %rdi
callq 0x4300
jmp 0x3edd
jmp 0x3f05
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x3d9e
movq -0x8(%rbp), %rdi
addq $0x18, %rdi
movslq -0x78(%rbp), %rsi
callq 0x4110
movl (%rax), %eax
movl %eax, -0x104(%rbp)
movq -0x8(%rbp), %rdi
addq $0x18, %rdi
movq %rdi, -0x158(%rbp)
callq 0x4620
movq %rax, -0x120(%rbp)
movslq -0x78(%rbp), %rsi
leaq -0x120(%rbp), %rdi
callq 0x4650
movq %rax, -0x118(%rbp)
leaq -0x110(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x46d0
movq -0x158(%rbp), %rdi
movq -0x110(%rbp), %rsi
callq 0x45b0
movq %rax, -0x150(%rbp)
jmp 0x3f8d
movq -0x150(%rbp), %rax
movq %rax, -0x128(%rbp)
movl -0x104(%rbp), %eax
movl %eax, -0x15c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x40c0
movl -0x15c(%rbp), %eax
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
leaq -0x70(%rbp), %rdi
callq 0x40c0
movq -0x90(%rbp), %rdi
callq 0x1170
nopw %cs:(%rax,%rax)
nop