// File: /workspace/github_cpp_makefile_star2_O2/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 0x2cce
movq 0x55b5(%rip), %rdi      # 0x7fd0
leaq 0x263b(%rip), %rsi      # 0x505d
callq 0x2160
pushq $0x1
popq %rdi
pushq $0x2
popq %rsi
callq 0x494d
leaq 0xd0(%rbx), %rcx
leaq 0xa8(%rbx), %r15
leaq 0x28(%rbx), %r12
cmpl $0x1, %eax
movq %r12, -0x30(%rbp)
movq %rcx, -0x38(%rbp)
cmoveq %rcx, %r12
movq %r15, %r14
cmoveq %rbx, %r14
leaq -0x80(%rbp), %r13
movq %rbx, %rdi
callq 0x3112
cmpl $0x2, %eax
jne 0x2bc0
movq %r14, %rdi
callq 0x488c
testb %al, %al
je 0x2a85
movq %r12, %rsi
callq 0x3150
jmp 0x2ad3
movq %r13, %rdi
movq %r14, %rsi
callq 0x47fc
movq %rbx, %rdi
movq %r13, %rsi
callq 0x31b2
movq %r13, %rdi
callq 0x20a0
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3282
leaq -0x128(%rbp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x47fc
movq %rbx, %rdi
movq %r12, %rsi
callq 0x31b2
movq %r12, %rdi
callq 0x20a0
movq %r14, %rdi
callq 0x4896
movl %eax, %r14d
movq %rbx, %rdi
callq 0x488c
cmpl $0x1, %r14d
jne 0x2b14
movq -0x30(%rbp), %r12
movq %r15, %r14
testb %al, %al
jne 0x2a5e
movq %r15, %rdi
callq 0x488c
movq -0x30(%rbp), %r12
movq %r15, %r14
testb %al, %al
jne 0x2a5e
jmp 0x2b75
movq -0x38(%rbp), %r12
movq %rbx, %r14
testb %al, %al
jne 0x2a5e
movq %r15, %rdi
callq 0x488c
movq -0x38(%rbp), %r12
movq %rbx, %r14
testb %al, %al
jne 0x2a5e
leaq -0xc0(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x4874
leaq -0xa0(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4874
movq %r13, %rsi
movq %r14, %rdx
callq 0x3384
movq %r14, %rdi
movq -0x38(%rbp), %r12
movq %rbx, %r14
jmp 0x2bae
leaq -0x100(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4874
leaq -0xe0(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x4874
movq %r13, %rsi
movq %r14, %rdx
callq 0x3384
movq %r14, %rdi
movq -0x30(%rbp), %r12
movq %r15, %r14
callq 0x20a0
movq %r13, %rdi
callq 0x20a0
jmp 0x2a5a
movq %rbx, %rdi
callq 0x3112
testl %eax, %eax
je 0x2c03
leaq -0x58(%rbp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4874
movq 0x53ee(%rip), %rdi      # 0x7fd0
movq %rbx, %rsi
callq 0x2130
leaq 0x24a3(%rip), %rsi      # 0x5094
movq %rax, %rdi
callq 0x2160
movq %rax, %rdi
callq 0x20b0
jmp 0x2c38
leaq -0x58(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4874
movq 0x53b7(%rip), %rdi      # 0x7fd0
movq %r14, %rsi
callq 0x2130
leaq 0x246c(%rip), %rsi      # 0x5094
movq %rax, %rdi
callq 0x2160
movq %rax, %rdi
callq 0x20b0
leaq -0x58(%rbp), %rdi
callq 0x20a0
movq 0x5388(%rip), %rdi      # 0x7fd0
leaq 0x244e(%rip), %rsi      # 0x509d
callq 0x2160
movb $0x1, %al
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2c6a
movq %rax, %rbx
leaq -0x58(%rbp), %rdi
jmp 0x2cc0
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x20a0
jmp 0x2c87
movq %rax, %rbx
leaq -0x100(%rbp), %rdi
jmp 0x2cc0
movq %rax, %rbx
jmp 0x2ca4
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x20a0
leaq -0xc0(%rbp), %rdi
jmp 0x2cc0
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
jmp 0x2cc0
movq %rax, %rbx
leaq -0x128(%rbp), %rdi
callq 0x20a0
movq %rbx, %rdi
callq 0x2230
nop