// File: cb92[P]Battleship/Board.cpp
// Function: Board::placeShip(int, int, int, bool)
bool Board::placeShip(int shipNum, int x, int y, bool isHorizontal)
{
	//if x or y is out of bounds, return false
	if (x>=BOARD_DIM || y>=BOARD_DIM)
		return false;

	//if ship has already been placed, return false
	if (shipVec[shipNum].getX()>=0 && shipVec[shipNum].getY()>=0)
		return false;

	//loop through the positions required for the ship
	for (int i=0; i<shipVec[shipNum].getSize(); i++)
	{
		//if any of the desired spaces are filled, return false
		if ((isHorizontal && gameBoard[y][x+i]!=isWATER) || 
							(!isHorizontal && gameBoard[y+i][x]!=isWATER))
			return false;
		//if any of the desired spaces are out of bounds, return false
		if ((isHorizontal && (x+i)>=BOARD_DIM) || 
							(!isHorizontal && (y+i)>=BOARD_DIM))
			return false;
	}

	//if the for loop finishes, and all the positions are empty, 
	//1. place the Ship in the desired position on the board
	for (int i=0; i<shipVec[shipNum].getSize(); i++)
	{
		if (isHorizontal)
			gameBoard[y][x+i]=isSAFESHIP;
		else 
			gameBoard[y+i][x]=isSAFESHIP;
	}

	//2. set the x/y parameters for the Ship object 
	shipVec[shipNum].setPosition(x, y, isHorizontal);

	//... and return true
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movb %r8b, %al
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
andb $0x1, %al
movb %al, -0x1d(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpl $0xa, -0x18(%rbp)
jge 0x5451
cmpl $0xa, -0x1c(%rbp)
jl 0x545a
movb $0x0, -0x1(%rbp)
jmp 0x560b
movq -0x30(%rbp), %rdi
addq $0x68, %rdi
movslq -0x14(%rbp), %rsi
callq 0x5920
movq %rax, %rdi
callq 0x7450
cmpl $0x0, %eax
jl 0x549f
movq -0x30(%rbp), %rdi
addq $0x68, %rdi
movslq -0x14(%rbp), %rsi
callq 0x5920
movq %rax, %rdi
callq 0x7470
cmpl $0x0, %eax
jl 0x549f
movb $0x0, -0x1(%rbp)
jmp 0x560b
movl $0x0, -0x24(%rbp)
movq -0x30(%rbp), %rdi
movl -0x24(%rbp), %eax
movl %eax, -0x34(%rbp)
addq $0x68, %rdi
movslq -0x14(%rbp), %rsi
callq 0x5920
movq %rax, %rdi
callq 0x7400
movl %eax, %ecx
movl -0x34(%rbp), %eax
cmpl %ecx, %eax
jge 0x5564
testb $0x1, -0x1d(%rbp)
je 0x54f9
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0xa, %rcx, %rcx
addq %rcx, %rax
movl -0x18(%rbp), %ecx
addl -0x24(%rbp), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x77, %eax
jne 0x5520
testb $0x1, -0x1d(%rbp)
jne 0x5529
movq -0x30(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl -0x24(%rbp), %ecx
movslq %ecx, %rcx
imulq $0xa, %rcx, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x77, %eax
je 0x5529
movb $0x0, -0x1(%rbp)
jmp 0x560b
testb $0x1, -0x1d(%rbp)
je 0x553a
movl -0x18(%rbp), %eax
addl -0x24(%rbp), %eax
cmpl $0xa, %eax
jge 0x554b
testb $0x1, -0x1d(%rbp)
jne 0x5554
movl -0x1c(%rbp), %eax
addl -0x24(%rbp), %eax
cmpl $0xa, %eax
jl 0x5554
movb $0x0, -0x1(%rbp)
jmp 0x560b
jmp 0x5556
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x54a6
movl $0x0, -0x28(%rbp)
movq -0x30(%rbp), %rdi
movl -0x28(%rbp), %eax
movl %eax, -0x38(%rbp)
addq $0x68, %rdi
movslq -0x14(%rbp), %rsi
callq 0x5920
movq %rax, %rdi
callq 0x7400
movl %eax, %ecx
movl -0x38(%rbp), %eax
cmpl %ecx, %eax
jge 0x55e0
testb $0x1, -0x1d(%rbp)
je 0x55b7
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0xa, %rcx, %rcx
addq %rcx, %rax
movl -0x18(%rbp), %ecx
addl -0x28(%rbp), %ecx
movslq %ecx, %rcx
movb $0x5f, (%rax,%rcx)
jmp 0x55d3
movq -0x30(%rbp), %rax
movl -0x1c(%rbp), %ecx
addl -0x28(%rbp), %ecx
movslq %ecx, %rcx
imulq $0xa, %rcx, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
movb $0x5f, (%rax,%rcx)
jmp 0x55d5
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x556b
movq -0x30(%rbp), %rdi
addq $0x68, %rdi
movslq -0x14(%rbp), %rsi
callq 0x5920
movq %rax, %rdi
movl -0x18(%rbp), %esi
movl -0x1c(%rbp), %edx
movb -0x1d(%rbp), %al
andb $0x1, %al
movzbl %al, %ecx
callq 0x7650
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)