// File: /workspace/github_cpp_makefile_star2_O1/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 0x2f7a
movq 0x64a1(%rip), %rdi      # 0x8fd0
leaq 0x34fd(%rip), %rsi      # 0x6033
movl $0x36, %edx
callq 0x2150
movl $0x1, %edi
movl $0x2, %esi
callq 0x53dd
movl %eax, %r14d
leaq 0xa8(%rbx), %r15
movq %rbx, %rdi
callq 0x35c0
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 0x5238
testb %al, %al
je 0x2ba5
movq %r12, %rsi
callq 0x3600
jmp 0x2c2e
leaq -0xe8(%rbp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x517c
movq %rbx, %rdi
movq %r13, %rsi
callq 0x36a2
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x2be4
movq -0xd8(%rbp), %rsi
incq %rsi
callq 0x2140
movq %rbx, %rdi
movq %r12, %rsi
callq 0x37e2
leaq -0xc0(%rbp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x517c
movq %rbx, %rdi
movq %r12, %rsi
callq 0x36a2
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x2c2e
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x2140
movq %r14, %rdi
callq 0x5242
movl %eax, %r14d
movq %rbx, %rdi
callq 0x5238
cmpl $0x1, %r14d
jne 0x2cdc
movq -0x30(%rbp), %r12
movq %r15, %r14
testb %al, %al
jne 0x2d6b
movq %r15, %rdi
callq 0x5238
movq -0x30(%rbp), %r12
movq %r15, %r14
testb %al, %al
jne 0x2d6b
leaq -0x128(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x520c
leaq -0x98(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x520c
movq %r14, %rsi
movq %r12, %rdx
callq 0x3918
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0x2cc2
movq -0x88(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0x128(%rbp), %rdi
leaq -0x118(%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 0x5238
movq -0x38(%rbp), %r12
movq %rbx, %r14
testb %al, %al
jne 0x2d6b
leaq -0x108(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x520c
leaq -0x78(%rbp), %r12
movq %r12, %rdi
movq %rbx, %rsi
callq 0x520c
movq %r14, %rsi
movq %r12, %rdx
callq 0x3918
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x2d43
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2140
movq -0x108(%rbp), %rdi
leaq -0xf8(%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 0x35c0
cmpl $0x2, %eax
je 0x2b8c
movq %rbx, %rdi
callq 0x35c0
testl %eax, %eax
je 0x2dea
leaq -0x58(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x520c
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 0x520c
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 0x2f18
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
leaq -0x118(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f72
movq -0x118(%rbp), %rsi
jmp 0x2f6a
movq %rax, %rbx
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x2eff
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2140
jmp 0x2eff
movq %rax, %rbx
leaq -0xf8(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f72
movq -0xf8(%rbp), %rsi
jmp 0x2f6a
movq %rax, %rbx
leaq -0x48(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f72
movq -0x48(%rbp), %rsi
jmp 0x2f6a
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x2f72
movq -0xb0(%rbp), %rsi
jmp 0x2f6a
movq %rax, %rbx
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x2f72
movq -0xd8(%rbp), %rsi
incq %rsi
callq 0x2140
movq %rbx, %rdi
callq 0x21f0