// File: /workspace/github_cpp_makefile_star2_O3/Matlock42[P]Jeopardy/jgameClass.cpp
// Function: Game::showQuestion(int)
bool Game::showQuestion(int aPrompt)
{	
	int lCatagory, lPrice;
	int lPrompt;
	bool lCorrect;
	// split 2 digit prompt into category and price (and make base zero)
	lCatagory = (aPrompt / 10 % 10) - 1;	// tens digit
	lPrice = (aPrompt % 10) - 1;			// ones digit

	// make sure selection is a valid choice
	if( lCatagory >= 0 && lCatagory < this->mSize && lPrice >= 0 && lPrice < this->mSize)
	{
		// make sure it hasn't been played before
		if(!mQuestionSet[lCatagory][lPrice]->hasBeenPlayed())
		{
			// display the question from the questionSet
			mQuestionSet[lCatagory][lPrice]->askQuestion();
			cout << "\n\n";
			mQuestionSet[lCatagory][lPrice]->showAnswers();
		}
		else // has been played
		{
			cout << "This question has already been played.\n";
			return false;
		}
	}
	else // not a valid choice
	{
		cout << "Invalid input: out of bounds.\n";
		return false;
	}

	// validate the input
	bool lInputError = false;
	do
	{
		cout << "What is your answer: \n";
	    if (cin >> lPrompt) // Sanitize input to an integer
	    {
	    	lInputError = false;
	    } 
	    else
	    {
	        cout << "Entered value is not an Integer.\n\n";
	        cin.clear();
	        cin.ignore(numeric_limits<streamsize>::max(), '\n');
	        lInputError = true;
	    }
	    // ensure that the prompt is 1,2,3,4
	    if (lPrompt > 4 || lPrompt < 1)
	    {
	    	cout << "Not a valid answer.\n\n";
	    	lInputError = true;
	    }
	} while (lInputError);

	// Play the user's answer
	lCorrect = mQuestionSet[lCatagory][lPrice]->play(lPrompt);
	
	if(lCorrect)
	{
		cout << "That is correct!\n";
		// add to the score
		mScore += ((lPrice + 1) * 100);
	}
	else
	{
		cout << "That is incorrect.\n";
	}
	
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
movslq %esi, %rax
imulq $0x66666667, %rax, %rcx # imm = 0x66666667
movq %rcx, %rax
shrq $0x3f, %rax
sarq $0x22, %rcx
addl %eax, %ecx
movslq %ecx, %rax
imulq $0x66666667, %rax, %rdx # imm = 0x66666667
movq %rdx, %rdi
shrq $0x3f, %rdi
sarq $0x22, %rdx
addl %edi, %edx
addl %edx, %edx
leal (%rdx,%rdx,4), %edx
subl %edx, %eax
testl %eax, %eax
jle 0x3489
addl %ecx, %ecx
leal (%rcx,%rcx,4), %ecx
movl %esi, %r14d
subl %ecx, %r14d
movl 0x8(%rbx), %edx
cmpl %edx, %r14d
jg 0x3489
testl %r14d, %r14d
jle 0x3489
cmpl %edx, %eax
jg 0x3489
decl %eax
negl %ecx
addl %esi, %ecx
decl %ecx
movq 0x10(%rbx), %rdx
movl %eax, %r15d
movq (%rdx,%r15,8), %rax
movl %ecx, %r12d
movq (%rax,%r12,8), %rdi
callq 0x5ddc
testb %al, %al
je 0x34b2
movq 0x5b45(%rip), %rdi      # 0x8fc0
leaq 0x2cb5(%rip), %rsi      # 0x6137
movl $0x27, %edx
jmp 0x349c
movq 0x5b30(%rip), %rdi      # 0x8fc0
leaq 0x2cc8(%rip), %rsi      # 0x615f
movl $0x1e, %edx
callq 0x2230
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %r14d, -0x30(%rbp)
movq 0x10(%rbx), %rax
movq (%rax,%r15,8), %rax
movq (%rax,%r12,8), %rdi
callq 0x5e36
movq 0x5af2(%rip), %r14      # 0x8fc0
leaq 0x2ce0(%rip), %rsi      # 0x61b5
movl $0x2, %edx
movq %r14, %rdi
callq 0x2230
movq %rbx, -0x48(%rbp)
movq 0x10(%rbx), %rax
movq %r15, -0x40(%rbp)
movq (%rax,%r15,8), %rax
movq %r12, -0x38(%rbp)
movq (%rax,%r12,8), %rdi
callq 0x5e52
leaq 0x2c78(%rip), %r15      # 0x617e
movq 0x5ac3(%rip), %r12      # 0x8fd0
leaq -0x2c(%rbp), %r13
leaq 0x2ca0(%rip), %rbx      # 0x61b8
movl $0x16, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2230
movq %r12, %rdi
movq %r13, %rsi
callq 0x2110
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
je 0x358b
movl $0x22, %edx
movq %r14, %rdi
leaq 0x2c45(%rip), %rsi      # 0x6195
callq 0x2230
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
xorl %esi, %esi
callq 0x2320
movq %r12, %rdi
movabsq $0x7fffffffffffffff, %rsi # imm = 0x7FFFFFFFFFFFFFFF
movl $0xa, %edx
callq 0x2120
movl -0x2c(%rbp), %eax
addl $-0x5, %eax
cmpl $-0x5, %eax
ja 0x3518
jmp 0x3596
movl -0x2c(%rbp), %esi
leal -0x5(%rsi), %eax
cmpl $-0x4, %eax
jae 0x35ab
movl $0x15, %edx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2230
jmp 0x3518
movq -0x48(%rbp), %rbx
movq 0x10(%rbx), %rax
movq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x5de8
movq 0x59f1(%rip), %rdi      # 0x8fc0
testb %al, %al
je 0x35ed
leaq 0x2bf4(%rip), %rsi      # 0x61ce
movl $0x11, %edx
callq 0x2230
imull $0x64, -0x30(%rbp), %eax
addl %eax, 0x4(%rbx)
jmp 0x35fe
leaq 0x2bec(%rip), %rsi      # 0x61e0
movl $0x13, %edx
callq 0x2230
movb $0x1, %al
jmp 0x34a3
nop