// File: /workspace/github_cpp_makefile_star2_O1/juancalaca[P]dotsboxes/main.cc
// Function: main
int main ()
{
	// Number of players
	int num_players = 2;
	
	// declare player data
	string player_names[num_players];
	player_names[0] = "P1";
	player_names[1] = "P2";

	int player_scores[num_players];
	
	//initialize player data
	for (int i = 0; i < num_players; i++)
	{
		player_scores[i] = 0;
	}
	
	// Board size
	int board_columns = 3;
	int board_rows = 3;
	
	// Make game Board
	DotsBoard *board = new DotsBoard(board_rows, board_columns);
	
	//print initial state of the game board
	board->PrintBoard();
	
	
	// Zedboard instance to control the game
	ZedBoard *zed = new ZedBoard();
 	
 	// run the game	
 	int current = 0;
 	
 	while (!board->GameOver())
 	{
		int claimed = TakeTurn(player_names[current], board, zed, board_rows, board_columns);
 		if (claimed > 0)
 		{
 			player_scores[current] += claimed;
 		}
 		else {
 			// update whose turn it is
 			current = (current + 1) % num_players;	
		}	
 	}
	
	//print final state of board
	board->PrintBoard();

	//tell user the game is over
	cout << "The game is now over, all the boxes are taken!" << endl;
	
	// Find winner & print
	if (player_scores[0] == player_scores[1])
	{
		cout << player_names[0] << " and " << player_names[1] << " Tied!" << endl;
	}
	else if ( player_scores[0] > player_scores[1])
	{
		cout << player_names[0] << " won this game!" << endl;
	}
	else
	{
		cout << player_names[1] << " won this game!" << endl;
	}
	
	
	// Delete game board, controller, players, zedboard
	delete zed;
	delete board;
	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl $0x10, %eax
leaq (%rax,%rbp), %rcx
addq $-0xa0, %rcx
movq %rcx, -0x10(%rcx)
movq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x50, %rax
jne 0x3df3
leaq -0xa0(%rbp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x13f8(%rip), %rcx      # 0x5221
movl $0x2, %r8d
xorl %esi, %esi
callq 0x21a0
leaq -0x80(%rbp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x13df(%rip), %rcx      # 0x5224
movl $0x2, %r8d
xorl %esi, %esi
callq 0x21a0
movq %rsp, %rax
leaq -0x10(%rax), %rcx
movq %rcx, -0x30(%rbp)
movq %rcx, %rsp
movq $0x0, -0x10(%rax)
movl $0x28, %edi
callq 0x2130
movq %rax, %r12
movq %rax, %rdi
movl $0x3, %esi
movl $0x3, %edx
callq 0x27a4
movq %r12, %rdi
callq 0x2b3a
movl $0x10, %edi
callq 0x2130
movq %rax, %rbx
movq %rax, %rdi
callq 0x418a
movq %rbx, -0x38(%rbp)
xorl %r13d, %r13d
leaq -0x58(%rbp), %r15
movl %r13d, %r13d
movq %r13, %rax
shlq $0x5, %rax
leaq (%rax,%rbp), %rbx
addq $-0xa0, %rbx
movq %r12, %rdi
callq 0x2b30
testb %al, %al
jne 0x3f44
leaq -0x48(%rbp), %rax
movq %rax, -0x58(%rbp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x25bc
movq %r15, %rdi
movq %r12, %r14
movq %r12, %rsi
movq -0x38(%rbp), %rdx
movl $0x3, %ecx
movl $0x3, %r8d
callq 0x385c
movl %eax, %r12d
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x3f23
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2140
testl %r12d, %r12d
je 0x3f35
movq -0x30(%rbp), %rax
addl %r12d, (%rax,%r13,4)
movq %r14, %r12
jmp 0x3ec4
notl %r13d
andl $0x1, %r13d
movq %r14, %r12
jmp 0x3eaf
movq %r12, %rdi
callq 0x2b3a
movq -0x38(%rbp), %rbx
movq 0x4079(%rip), %r15      # 0x7fd0
leaq 0x12c9(%rip), %rsi      # 0x5227
movl $0x2e, %edx
movq %r15, %rdi
callq 0x2150
movq (%r15), %rax
addq -0x18(%rax), %r15
movq %r15, %rdi
movl $0xa, %esi
callq 0x2110
movsbl %al, %esi
movq 0x4047(%rip), %rdi      # 0x7fd0
callq 0x2030
movq %rax, %rdi
callq 0x20b0
movq -0x30(%rbp), %rcx
movl 0x4(%rcx), %eax
cmpl %eax, (%rcx)
jne 0x4012
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
movq 0x401a(%rip), %rdi      # 0x7fd0
callq 0x2150
movq %rax, %r15
leaq 0x1291(%rip), %rsi      # 0x5256
movl $0x5, %edx
movq %rax, %rdi
callq 0x2150
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq %r15, %rdi
callq 0x2150
movq %rax, %r15
leaq 0x1270(%rip), %rsi      # 0x525c
movl $0x6, %edx
movq %rax, %rdi
callq 0x2150
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2110
jmp 0x409a
jle 0x405b
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
movq 0x3fa7(%rip), %rdi      # 0x7fd0
callq 0x2150
movq %rax, %r15
leaq 0x122b(%rip), %rsi      # 0x5263
movl $0xf, %edx
movq %rax, %rdi
callq 0x2150
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2110
jmp 0x409a
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq 0x3f66(%rip), %rdi      # 0x7fd0
callq 0x2150
movq %rax, %r15
leaq 0x11ea(%rip), %rsi      # 0x5263
movl $0xf, %edx
movq %rax, %rdi
callq 0x2150
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2110
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20b0
movq %rbx, %rdi
callq 0x41ec
movl $0x10, %esi
movq %rbx, %rdi
callq 0x2140
movq %r12, %rdi
callq 0x2a4a
movl $0x28, %esi
movq %r12, %rdi
callq 0x2140
leaq -0x70(%rbp), %rbx
xorl %r14d, %r14d
movq -0x80(%rbp,%r14), %rdi
leaq (%rbx,%r14), %rax
cmpq %rdi, %rax
je 0x40f7
movq (%rax), %rsi
incq %rsi
callq 0x2140
addq $-0x20, %r14
cmpq $-0x40, %r14
jne 0x40de
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
movl $0x10, %esi
movq %rbx, %rdi
jmp 0x414b
jmp 0x4154
movq %rax, %r15
movl $0x28, %esi
movq %r12, %rdi
jmp 0x414b
jmp 0x4154
jmp 0x4154
jmp 0x4154
movq %rax, %r15
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x4157
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2140
jmp 0x4157
jmp 0x4154
movq %rax, %r15
leaq -0x70(%rbp), %rbx
xorl %r14d, %r14d
movq -0x80(%rbp,%r14), %rdi
leaq (%rbx,%r14), %rax
cmpq %rdi, %rax
je 0x4177
movq (%rax), %rsi
incq %rsi
callq 0x2140
addq $-0x20, %r14
cmpq $-0x40, %r14
jne 0x415e
movq %r15, %rdi
callq 0x21d0
nop