// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $0x10
popq %rax
leaq (%rax,%rbp), %rcx
addq $-0x80, %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
addq $0x20, %rax
cmpq $0x50, %rax
jne 0x3759
leaq 0xaab(%rip), %rsi       # 0x4229
leaq -0x80(%rbp), %rdi
callq 0x2200
leaq -0x60(%rbp), %rdi
leaq 0xa9a(%rip), %rsi       # 0x422c
callq 0x2200
movq %rsp, %rax
leaq -0x10(%rax), %rcx
movq %rcx, -0x30(%rbp)
movq %rcx, %rsp
andq $0x0, -0x10(%rax)
pushq $0x28
popq %rdi
callq 0x2130
movq %rax, %r14
pushq $0x3
popq %rdx
movq %rax, %rdi
movl %edx, %esi
callq 0x2600
movq %r14, %rdi
callq 0x291c
pushq $0x10
popq %rdi
callq 0x2130
movq %rax, %r12
movq %rax, %rdi
callq 0x39da
xorl %eax, %eax
leaq -0xa0(%rbp), %r13
movl %eax, %eax
movq %rax, -0x38(%rbp)
shlq $0x5, %rax
leaq (%rax,%rbp), %r15
addq $-0x80, %r15
movq %r14, %rdi
callq 0x2912
testb %al, %al
jne 0x3855
movq %r13, %rdi
movq %r15, %rsi
callq 0x2160
movq %r13, %rdi
movq %r14, %rbx
movq %r14, %rsi
movq %r12, %rdx
pushq $0x3
popq %rcx
movl %ecx, %r8d
callq 0x3410
movl %eax, %r14d
movq %r13, %rdi
callq 0x2070
testl %r14d, %r14d
je 0x3847
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
addl %r14d, (%rax,%rcx,4)
movq %rbx, %r14
jmp 0x37f8
movq -0x38(%rbp), %rax
notl %eax
andl $0x1, %eax
movq %rbx, %r14
jmp 0x37e6
movq %r14, %rdi
callq 0x291c
movq 0x376c(%rip), %rdi      # 0x6fd0
leaq 0x9c4(%rip), %rsi       # 0x422f
callq 0x2120
movq %rax, %rdi
callq 0x2080
movq -0x30(%rbp), %rcx
movl 0x4(%rcx), %eax
cmpl %eax, (%rcx)
jne 0x38b7
movq 0x3746(%rip), %rdi      # 0x6fd0
leaq -0x80(%rbp), %rsi
callq 0x2110
leaq 0x9c4(%rip), %rsi       # 0x425e
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
leaq -0x60(%rbp), %rsi
callq 0x2110
leaq 0x9af(%rip), %rsi       # 0x4264
jmp 0x38d6
leaq -0x60(%rbp), %rsi
leaq -0x80(%rbp), %rax
cmovgq %rax, %rsi
movq 0x3706(%rip), %rdi      # 0x6fd0
callq 0x2110
leaq 0x995(%rip), %rsi       # 0x426b
movq %rax, %rdi
callq 0x2120
movq %rax, %rdi
callq 0x2080
movq %r12, %rdi
callq 0x3a34
pushq $0x10
popq %rsi
movq %r12, %rdi
callq 0x2140
movq %r14, %rdi
callq 0x2858
pushq $0x28
popq %rsi
movq %r14, %rdi
callq 0x2140
pushq $0x20
popq %rbx
leaq (%rbx,%rbp), %rdi
addq $-0x80, %rdi
callq 0x2070
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0x390f
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
pushq $0x10
popq %rsi
movq %r12, %rdi
jmp 0x394d
jmp 0x396d
movq %rax, %r15
pushq $0x28
popq %rsi
movq %r14, %rdi
callq 0x2140
jmp 0x3970
jmp 0x396d
jmp 0x396d
jmp 0x396d
movq %rax, %r15
leaq -0xa0(%rbp), %rdi
callq 0x2070
jmp 0x3970
jmp 0x396d
movq %rax, %r15
pushq $0x20
popq %rbx
leaq (%rbx,%rbp), %rdi
addq $-0x80, %rdi
callq 0x2070
addq $-0x20, %rbx
cmpq $-0x20, %rbx
jne 0x3973
movq %r15, %rdi
callq 0x21c0