// File: /workspace/github_cpp_makefile_star2_O3/cb92[P]Battleship/Game.cpp
// Function: Game::playGame()
bool Game::playGame()
{
	int firstPlayer, currentPlayer, toPlay;
	Board * bptr;
	Player * pptr;

	startGame();

	std::cout<<"Which player will make the first move (enter 1 or 2)?\n";
	firstPlayer=getInt(1,2);


	// hold pointers for current player/board objects
	if (firstPlayer==1)
	{
		pptr = &p1; 
		bptr = &p2Board;
	}
	else {
		pptr = &p2;
		bptr = &p1Board;
	}

	while(gameCondition()==UNFINISHED)
	{
		if ((*pptr).isPlayerAutomatic())
		{
			getNextMoveAuto(*(bptr));
		}
		else
		{
			printGameState(*(pptr));
			getNextMove(*(bptr));
			printGameState(*(pptr));
		}

		// switch pointers at the end of each turn
		if ((*pptr).getPlayerNum()==1)
		{
			if (!p1.isPlayerAutomatic() && !p2.isPlayerAutomatic()) 
			{
				switchPlayers(p1.getName(), p2.getName());
			}
			pptr = &p2; 
			bptr = &p1Board;
		}
		else {
			if (!p1.isPlayerAutomatic() && !p2.isPlayerAutomatic())
			{
				switchPlayers(p2.getName(), p1.getName());
			}
			pptr = &p1;
			bptr = &p2Board;
		}
	}

	if (gameCondition()==P1_WIN)
		std::cout<<p1.getName()<<" wins!!!"<<std::endl;
	else 
		std::cout<<p2.getName()<<" wins!!!"<<std::endl;

	std::cout<<"I hope you enjoyed the Battleship game. Bye!\n\n";
	return true;

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdi, %rbx
callq 0x2f80
movq 0x64a1(%rip), %rdi      # 0x8fd0
leaq 0x34fd(%rip), %rsi      # 0x6033
movl $0x36, %edx
callq 0x2150
movl $0x1, %edi
movl $0x2, %esi
callq 0x53cd
movl %eax, %r14d
leaq 0xa8(%rbx), %r15
movq %rbx, %rdi
callq 0x35c6
cmpl $0x2, %eax
jne 0x2d7c
leaq 0xd0(%rbx), %rax
cmpl $0x1, %r14d
movq %r15, %r14
cmoveq %rbx, %r14
leaq 0x28(%rbx), %r12
movq %r12, -0x30(%rbp)
movq %rax, -0x38(%rbp)
cmoveq %rax, %r12
movq %r14, %rdi
callq 0x5228
testb %al, %al
je 0x2ba5
movq %r12, %rsi
callq 0x3606
jmp 0x2c2e
leaq -0x128(%rbp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x516c
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3698
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0x2be4
movq -0x118(%rbp), %rsi
incq %rsi
callq 0x2140
movq %rbx, %rdi
movq %r12, %rsi
callq 0x37d8
leaq -0x100(%rbp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x516c
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3698
movq -0x100(%rbp), %rdi
leaq -0xf0(%rbp), %rax
cmpq %rax, %rdi
je 0x2c2e
movq -0xf0(%rbp), %rsi
incq %rsi
callq 0x2140
movq %r14, %rdi
callq 0x5232
movl %eax, %r14d
movq %rbx, %rdi
callq 0x5228
cmpl $0x1, %r14d
jne 0x2cdc
movq -0x30(%rbp), %r12
movq %r15, %r14
testb %al, %al
jne 0x2d6b
movq %r15, %rdi
callq 0x5228
movq -0x30(%rbp), %r12
movq %r15, %r14
testb %al, %al
jne 0x2d6b
leaq -0xd8(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x51fc
leaq -0x98(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x51fc
movq %r14, %rsi
movq %r12, %rdx
callq 0x3908
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x2cc2
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rcx
movq %rcx, %rax
movq -0x30(%rbp), %r12
movq %r15, %r14
jmp 0x2d5b
movq -0x38(%rbp), %r12
movq %rbx, %r14
testb %al, %al
jne 0x2d6b
movq %r15, %rdi
callq 0x5228
movq -0x38(%rbp), %r12
movq %rbx, %r14
testb %al, %al
jne 0x2d6b
leaq -0xb8(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x51fc
leaq -0x78(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x51fc
movq %r14, %rsi
movq %r12, %rdx
callq 0x3908
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x2d43
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rcx
movq %rcx, %rax
movq -0x38(%rbp), %r12
movq %rbx, %r14
cmpq %rcx, %rdi
je 0x2d6b
movq (%rax), %rsi
incq %rsi
callq 0x2140
movq %rbx, %rdi
callq 0x35c6
cmpl $0x2, %eax
je 0x2b8c
movq %rbx, %rdi
callq 0x35c6
testl %eax, %eax
je 0x2dea
leaq -0x58(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x51fc
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0x622b(%rip), %rdi      # 0x8fd0
callq 0x2150
movq %rax, %rbx
leaq 0x32b6(%rip), %rsi      # 0x606a
movl $0x8, %edx
movq %rax, %rdi
callq 0x2150
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20b0
jmp 0x2e4a
leaq -0x58(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x51fc
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x61c9(%rip), %rdi      # 0x8fd0
callq 0x2150
movq %rax, %rbx
leaq 0x3254(%rip), %rsi      # 0x606a
movl $0x8, %edx
movq %rax, %rdi
callq 0x2150
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2120
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20b0
leaq -0x48(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2e63
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2140
movq 0x6166(%rip), %rdi      # 0x8fd0
leaq 0x3202(%rip), %rsi      # 0x6073
movl $0x2e, %edx
callq 0x2150
movb $0x1, %al
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2f1e
movq %rax, %rbx
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x2ebe
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x2140
jmp 0x2ebe
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
leaq -0xc8(%rbp), %rax
cmpq %rax, %rdi
je 0x2f78
movq -0xc8(%rbp), %rsi
jmp 0x2f70
movq %rax, %rbx
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x2f02
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2140
jmp 0x2f02
movq %rax, %rbx
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x2f78
movq -0xa8(%rbp), %rsi
jmp 0x2f70
movq %rax, %rbx
leaq -0x48(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f78
movq -0x48(%rbp), %rsi
jmp 0x2f70
movq %rax, %rbx
movq -0x100(%rbp), %rdi
leaq -0xf0(%rbp), %rax
cmpq %rax, %rdi
je 0x2f78
movq -0xf0(%rbp), %rsi
jmp 0x2f70
movq %rax, %rbx
movq -0x128(%rbp), %rdi
leaq -0x118(%rbp), %rax
cmpq %rax, %rdi
je 0x2f78
movq -0x118(%rbp), %rsi
incq %rsi
callq 0x2140
movq %rbx, %rdi
callq 0x21f0