// File: 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
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x39f0
movq 0x9a72(%rip), %rdi      # 0xcfc8
leaq 0x5b00(%rip), %rsi      # 0x905d
callq 0x2180
movl $0x1, %edi
movl $0x2, %esi
callq 0x7bd0
movl %eax, -0xc(%rbp)
cmpl $0x1, -0xc(%rbp)
jne 0x3591
movq -0x150(%rbp), %rax
movq %rax, -0x28(%rbp)
addq $0xd0, %rax
movq %rax, -0x20(%rbp)
jmp 0x35ae
movq -0x150(%rbp), %rax
movq %rax, %rcx
addq $0xa8, %rcx
movq %rcx, -0x28(%rbp)
addq $0x28, %rax
movq %rax, -0x20(%rbp)
jmp 0x35b0
movq -0x150(%rbp), %rdi
callq 0x4270
cmpl $0x2, %eax
jne 0x3880
movq -0x28(%rbp), %rdi
callq 0x7a40
testb $0x1, %al
jne 0x35d4
jmp 0x35e9
movq -0x150(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x42d0
jmp 0x369c
movq -0x28(%rbp), %rsi
leaq -0x50(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x7940
movq -0x150(%rbp), %rdi
movq -0x158(%rbp), %rsi
callq 0x4360
jmp 0x3612
leaq -0x50(%rbp), %rdi
callq 0x4cc0
movq -0x150(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x44c0
movq -0x28(%rbp), %rsi
leaq -0x88(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x7940
movq -0x150(%rbp), %rdi
movq -0x160(%rbp), %rsi
callq 0x4360
jmp 0x3657
leaq -0x88(%rbp), %rdi
callq 0x4cc0
jmp 0x369c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x4cc0
jmp 0x39e0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x4cc0
jmp 0x39e0
movq -0x28(%rbp), %rdi
callq 0x7a60
cmpl $0x1, %eax
jne 0x379b
movq -0x150(%rbp), %rdi
callq 0x7a40
testb $0x1, %al
jne 0x3779
movq -0x150(%rbp), %rdi
addq $0xa8, %rdi
callq 0x7a40
testb $0x1, %al
jne 0x3779
movq -0x150(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x7a10
movq -0x150(%rbp), %rsi
addq $0xa8, %rsi
leaq -0xc8(%rbp), %rdi
callq 0x7a10
jmp 0x370c
movq -0x150(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
leaq -0xc8(%rbp), %rdx
callq 0x4660
jmp 0x3728
leaq -0xc8(%rbp), %rdi
callq 0x20e0
leaq -0xa8(%rbp), %rdi
callq 0x20e0
jmp 0x3779
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x3768
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x20e0
leaq -0xa8(%rbp), %rdi
callq 0x20e0
jmp 0x39e0
movq -0x150(%rbp), %rax
movq %rax, %rcx
addq $0xa8, %rcx
movq %rcx, -0x28(%rbp)
addq $0x28, %rax
movq %rax, -0x20(%rbp)
jmp 0x387b
movq -0x150(%rbp), %rdi
callq 0x7a40
testb $0x1, %al
jne 0x3866
movq -0x150(%rbp), %rdi
addq $0xa8, %rdi
callq 0x7a40
testb $0x1, %al
jne 0x3866
movq -0x150(%rbp), %rsi
addq $0xa8, %rsi
leaq -0xe8(%rbp), %rdi
callq 0x7a10
movq -0x150(%rbp), %rsi
leaq -0x108(%rbp), %rdi
callq 0x7a10
jmp 0x37f9
movq -0x150(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
leaq -0x108(%rbp), %rdx
callq 0x4660
jmp 0x3815
leaq -0x108(%rbp), %rdi
callq 0x20e0
leaq -0xe8(%rbp), %rdi
callq 0x20e0
jmp 0x3866
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x3855
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x20e0
leaq -0xe8(%rbp), %rdi
callq 0x20e0
jmp 0x39e0
movq -0x150(%rbp), %rax
movq %rax, -0x28(%rbp)
addq $0xd0, %rax
movq %rax, -0x20(%rbp)
jmp 0x35b0
movq -0x150(%rbp), %rdi
callq 0x4270
cmpl $0x0, %eax
jne 0x392a
movq -0x150(%rbp), %rsi
leaq -0x128(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x7a10
movq -0x170(%rbp), %rsi
movq 0x970b(%rip), %rdi      # 0xcfc8
callq 0x2150
movq %rax, -0x168(%rbp)
jmp 0x38cb
movq -0x168(%rbp), %rdi
leaq 0x57bb(%rip), %rsi      # 0x9094
callq 0x2180
movq %rax, -0x178(%rbp)
jmp 0x38e7
movq -0x178(%rbp), %rdi
movq 0x96c3(%rip), %rsi      # 0xcfb8
callq 0x21b0
jmp 0x38fc
leaq -0x128(%rbp), %rdi
callq 0x20e0
jmp 0x39c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x20e0
jmp 0x39e0
movq -0x150(%rbp), %rsi
addq $0xa8, %rsi
leaq -0x148(%rbp), %rdi
movq %rdi, -0x188(%rbp)
callq 0x7a10
movq -0x188(%rbp), %rsi
movq 0x966f(%rip), %rdi      # 0xcfc8
callq 0x2150
movq %rax, -0x180(%rbp)
jmp 0x3967
movq -0x180(%rbp), %rdi
leaq 0x571f(%rip), %rsi      # 0x9094
callq 0x2180
movq %rax, -0x190(%rbp)
jmp 0x3983
movq -0x190(%rbp), %rdi
movq 0x9627(%rip), %rsi      # 0xcfb8
callq 0x21b0
jmp 0x3998
leaq -0x148(%rbp), %rdi
callq 0x20e0
jmp 0x39c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x20e0
jmp 0x39e0
movq 0x9601(%rip), %rdi      # 0xcfc8
leaq 0x56cf(%rip), %rsi      # 0x909d
callq 0x2180
movb $0x1, %al
andb $0x1, %al
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x22d0
nopl (%rax)