// File: 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
subq $0x140, %rsp            # imm = 0x140
movl $0x0, -0x4(%rbp)
movl $0x2, -0x8(%rbp)
movl -0x8(%rbp), %eax
movq %rax, -0x88(%rbp)
movq %rsp, %rcx
movq %rcx, -0x10(%rbp)
movq %rax, %rdx
shlq $0x5, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x80(%rbp)
movq %rcx, %rsp
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
je 0x684c
movq -0x80(%rbp), %rax
movq -0x88(%rbp), %rdx
shlq $0x5, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movq %rcx, -0x98(%rbp)
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x2200
movq -0xa0(%rbp), %rax
movq -0x98(%rbp), %rcx
addq $0x20, %rax
cmpq %rcx, %rax
movq %rax, -0x90(%rbp)
jne 0x681b
movq -0x80(%rbp), %rdi
leaq 0x9ae(%rip), %rsi       # 0x7205
callq 0x21f0
jmp 0x685e
movq -0x80(%rbp), %rdi
addq $0x20, %rdi
leaq 0x99b(%rip), %rsi       # 0x7208
callq 0x21f0
jmp 0x6874
movl -0x8(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xa8(%rbp)
movq %rcx, %rsp
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x68d4
movq -0xa8(%rbp), %rax
movslq -0x34(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x689e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x6c88
movl $0x3, -0x38(%rbp)
movl $0x3, -0x3c(%rbp)
movl $0x28, %edi
callq 0x2160
movq %rax, -0xb0(%rbp)
jmp 0x68f5
movq -0xb0(%rbp), %rdi
movl -0x3c(%rbp), %esi
movl -0x38(%rbp), %edx
callq 0x2a50
jmp 0x6909
movq -0xb0(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x2fa0
jmp 0x691f
movl $0x10, %edi
callq 0x2160
movq %rax, -0xb8(%rbp)
jmp 0x6932
movq -0xb8(%rbp), %rdi
callq 0x6da0
jmp 0x6940
movq -0xb8(%rbp), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movq -0x48(%rbp), %rdi
callq 0x2f80
movb %al, -0xb9(%rbp)
jmp 0x6963
movb -0xb9(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x6974
jmp 0x6a4c
movq -0x80(%rbp), %rsi
movslq -0x54(%rbp), %rax
shlq $0x5, %rax
addq %rax, %rsi
leaq -0x78(%rbp), %rdi
callq 0x2080
jmp 0x698e
movq -0x48(%rbp), %rsi
movq -0x50(%rbp), %rdx
movl -0x3c(%rbp), %ecx
movl -0x38(%rbp), %r8d
leaq -0x78(%rbp), %rdi
callq 0x6150
movl %eax, -0xc0(%rbp)
jmp 0x69ae
leaq -0x78(%rbp), %rdi
callq 0x20c0
movl -0xc0(%rbp), %eax
movl %eax, -0x58(%rbp)
cmpl $0x0, -0x58(%rbp)
jle 0x6a3a
movq -0xa8(%rbp), %rax
movl -0x58(%rbp), %edx
movslq -0x54(%rbp), %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
jmp 0x6a47
movq -0xb0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x28, %esi
callq 0x2170
jmp 0x6c88
movq -0xb8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x10, %esi
callq 0x2170
jmp 0x6c88
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x20c0
jmp 0x6c88
movl -0x54(%rbp), %eax
addl $0x1, %eax
cltd
idivl -0x8(%rbp)
movl %edx, -0x54(%rbp)
jmp 0x6952
movq -0x48(%rbp), %rdi
callq 0x2fa0
jmp 0x6a57
movq 0x4572(%rip), %rdi      # 0xafd0
leaq 0x7a6(%rip), %rsi       # 0x720b
callq 0x2150
movq %rax, -0xc8(%rbp)
jmp 0x6a73
movq -0xc8(%rbp), %rdi
movq 0x453f(%rip), %rsi      # 0xafc0
callq 0x2180
jmp 0x6a88
movq -0xa8(%rbp), %rcx
movl (%rcx), %eax
cmpl 0x4(%rcx), %eax
jne 0x6b22
movq -0x80(%rbp), %rsi
movq 0x452b(%rip), %rdi      # 0xafd0
callq 0x2140
movq %rax, -0xd0(%rbp)
jmp 0x6ab3
movq -0xd0(%rbp), %rdi
leaq 0x779(%rip), %rsi       # 0x723a
callq 0x2150
movq %rax, -0xd8(%rbp)
jmp 0x6acf
movq -0xd8(%rbp), %rdi
movq -0x80(%rbp), %rsi
addq $0x20, %rsi
callq 0x2140
movq %rax, -0xe0(%rbp)
jmp 0x6aec
movq -0xe0(%rbp), %rdi
leaq 0x746(%rip), %rsi       # 0x7240
callq 0x2150
movq %rax, -0xe8(%rbp)
jmp 0x6b08
movq -0xe8(%rbp), %rdi
movq 0x44aa(%rip), %rsi      # 0xafc0
callq 0x2180
jmp 0x6b1d
jmp 0x6bce
movq -0xa8(%rbp), %rcx
movl (%rcx), %eax
cmpl 0x4(%rcx), %eax
jle 0x6b7c
movq -0x80(%rbp), %rsi
movq 0x4495(%rip), %rdi      # 0xafd0
callq 0x2140
movq %rax, -0xf0(%rbp)
jmp 0x6b49
movq -0xf0(%rbp), %rdi
leaq 0x6f0(%rip), %rsi       # 0x7247
callq 0x2150
movq %rax, -0xf8(%rbp)
jmp 0x6b65
movq -0xf8(%rbp), %rdi
movq 0x444d(%rip), %rsi      # 0xafc0
callq 0x2180
jmp 0x6b7a
jmp 0x6bcc
movq -0x80(%rbp), %rsi
addq $0x20, %rsi
movq 0x4445(%rip), %rdi      # 0xafd0
callq 0x2140
movq %rax, -0x100(%rbp)
jmp 0x6b99
movq -0x100(%rbp), %rdi
leaq 0x6a0(%rip), %rsi       # 0x7247
callq 0x2150
movq %rax, -0x108(%rbp)
jmp 0x6bb5
movq -0x108(%rbp), %rdi
movq 0x43fd(%rip), %rsi      # 0xafc0
callq 0x2180
jmp 0x6bca
jmp 0x6bcc
jmp 0x6bce
movq -0x50(%rbp), %rax
movq %rax, -0x110(%rbp)
cmpq $0x0, %rax
je 0x6bfc
movq -0x110(%rbp), %rdi
callq 0x6e30
movq -0x110(%rbp), %rdi
movl $0x10, %esi
callq 0x2170
movq -0x48(%rbp), %rax
movq %rax, -0x118(%rbp)
cmpq $0x0, %rax
je 0x6c2a
movq -0x118(%rbp), %rdi
callq 0x2df0
movq -0x118(%rbp), %rdi
movl $0x28, %esi
callq 0x2170
movq -0x80(%rbp), %rcx
movq -0x88(%rbp), %rdx
shlq $0x5, %rdx
movq %rcx, %rax
addq %rdx, %rax
cmpq %rax, %rcx
movq %rax, -0x120(%rbp)
je 0x6c79
movq -0x120(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x128(%rbp)
callq 0x20c0
movq -0x80(%rbp), %rcx
movq -0x128(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x120(%rbp)
jne 0x6c4b
movq -0x10(%rbp), %rax
movq %rax, %rsp
movl -0x4(%rbp), %eax
movq %rbp, %rsp
popq %rbp
retq
movq -0x80(%rbp), %rcx
movq -0x88(%rbp), %rdx
shlq $0x5, %rdx
movq %rcx, %rax
addq %rdx, %rax
cmpq %rax, %rcx
movq %rax, -0x130(%rbp)
je 0x6cd7
movq -0x130(%rbp), %rdi
addq $-0x20, %rdi
movq %rdi, -0x138(%rbp)
callq 0x20c0
movq -0x80(%rbp), %rcx
movq -0x138(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0x130(%rbp)
jne 0x6ca9
jmp 0x6cd9
movq -0x20(%rbp), %rdi
callq 0x2260
nopw %cs:(%rax,%rax)
nopl (%rax)