// File: /workspace/github_cpp_makefile_star2_O2/Doug0855[P]TigerZone/main.cpp
// Function: moveProtocol(Client&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, Game&, Game&, int&, int&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
int moveProtocol(Client &client, std::string &message_list, Game &game1, Game &game2, int &success1, int &success2, std::string OPPONENT_ID)
{
	/*
	This protocol is called whenever a move needs to be made.
	It takes a reference to both games being played and two success values.
	These success values are used to calculate the number of iterations needed in the processing loop
	*/
	std::string message_to_send;
	std::string message;
	values_t message_info;
	Adapter adapter;
	int runTime = 3;
	Tile tmpTile;

	message = getMesssage(client, message_list);
	std::cout << GREEN << "Server sent: " << RESET << message << std::endl;

	if ((success1 == -1 || success2 == -1) && message.compare(0,1,"M") == 0) //Need to make a move
		runTime = 2;
	else if ((success1 == -1 || success2 == -1) && message.compare(0,1,"G") == 0) //Need to get a game piece
		runTime = 1;
	else if (success1 == -1 && success2 == -1) //Do nothing
		runTime = 0;

	for (int i = 0; i < runTime; i++)
	{
		if (message.compare(0,1,"M") == 0)
		{
			std::cout<<"	SERVER ASKING FOR A MOVE"<<std::endl;
			message_info = adapter.translate(message);
			if (game1.getID() == "")
				game1.setID(message_info.gameId);
			if (message_info.gameId == game1.getID())
			{
				//std::cout << "sent our move for tile: " << message_info.tile_num <<  " and game: " << message_info.gameId << std::endl;
				tmpTile = Tile(message_info.tile_num);
				message_to_send = game1.makeMove(tmpTile, message_info.moveNumber);
			}
			else if (message_info.gameId == game2.getID())
			{
				//std::cout << "sent our move for tile: " << message_info.tile_num <<  " and game: " << message_info.gameId << std::endl;
				tmpTile = Tile(message_info.tile_num);
				message_to_send = game2.makeMove(tmpTile, message_info.moveNumber);
			}
			std::cout << RED << "	We sent: " << RESET << message_to_send << std::endl;
			client.sendMessage(message_to_send);
			message = getMesssage(client, message_list);
			std::cout << GREEN << "Server sent: " << RESET << message << std::endl;
		}
		else if (message.compare(0,1,"G") == 0)
		{
			std::cout << "	GAME MOVES INFORMATION" << std::endl;
			message_info = adapter.translate(message);
			if (message_info.gameId != game1.getID() && game2.getID() == "")
				game2.setID(message_info.gameId);
			if (message_info.forfeit == -1)
			{
				if (game2.getID() == message_info.gameId)
					success2 = -1;
				else if (game1.getID() == message_info.gameId)
					success1 = -1;
				if (success1 == -1 && success2 == -1)
					break;
			}
			else
			{
				if (message_info.playerId == OPPONENT_ID)
				{
					tmpTile = Tile(message_info.tile_num);
					int i = message_info.coordinates.first;
					int j = message_info.coordinates.second;
					int orientation = message_info.rotation;

					if (message_info.gameId == game1.getID())
					{
						//std::cout << "	Received opponent move for tile: " << message_info.tile_num <<  " in game: " << message_info.gameId << std::endl;
						//std::cout << "		tile placed at <" << i << ", " << j << "> " << "with rotation: " << orientation << std::endl;
						//std::cout << "		croc? " << message_info.croc << " tiger? " << message_info.tiger << " zone " << "[" <<message_info.tiger_spot.first << ", " << message_info.tiger_spot.second << "] " << std::endl;
						tmpTile = Tile(message_info.tile_num);
						game1.enemyMove(tmpTile, i, j, orientation, message_info.tiger, message_info.croc, message_info.tiger_spot);
					}
					else if (message_info.gameId == game2.getID())
					{
						//std::cout << "	Received opponent move for tile: " << message_info.tile_num <<  " in game: " << message_info.gameId << std::endl;
						//std::cout << "		tile placed at <" << i << ", " << j << "> :" << "with rotation: " << orientation << std::endl;
						//std::cout << "		croc? " << message_info.croc << " tiger? " << message_info.tiger << " zone " << "[" <<message_info.tiger_spot.first << ", " << message_info.tiger_spot.second << "] " << std::endl;
						//tmpTile = Tile(message_info.tile_num);
						//debugging std::cout << "DEBUG FLAG" << std::endl;
						game2.enemyMove(tmpTile, i, j, orientation, message_info.tiger, message_info.croc, message_info.tiger_spot);
						//debugging std::cout << "DEBUG FLAG 2" << std::endl;
					}
				}
			}
			if (i < runTime-1) //if it isn't the final message, display the message the server sent.
			{
				message = getMesssage(client, message_list);
				std::cout << GREEN << "Server sent: " << RESET << message << std::endl;
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x8a8, %rsp            # imm = 0x8A8
movq %r9, -0x58(%rbp)
movq %r8, -0x50(%rbp)
movq %rcx, -0x60(%rbp)
movq %rdx, -0x68(%rbp)
leaq -0xa8(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
leaq -0x80(%rbp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movq %rsi, -0x70(%rbp)
leaq -0x118(%rbp), %rdx
xorps %xmm0, %xmm0
movups %xmm0, -0x28(%rdx)
movups %xmm0, -0x38(%rdx)
andq $0x0, -0x18(%rdx)
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movq %rdi, %r14
xorl %esi, %esi
movb %sil, (%rdx)
leaq -0xf8(%rbp), %rdx
movq %rdx, -0x10(%rdx)
andq $0x0, -0x8(%rdx)
movb %sil, (%rax)
movb %sil, (%rcx)
movb %sil, (%rdx)
leaq -0xd8(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %sil, (%rax)
andl $0x0, 0x14(%rax)
leaq -0x530(%rbp), %rdi
callq 0x7668
leaq -0x418(%rbp), %rdi
callq 0x10d92
leaq -0x330(%rbp), %rdi
movq %r14, %rsi
movq -0x70(%rbp), %rdx
callq 0x3b80
leaq -0x90(%rbp), %rdi
leaq -0x330(%rbp), %rbx
movq %rbx, %rsi
callq 0x3280
movq %rbx, %rdi
callq 0x3120
movq 0x152b3(%rip), %rdi     # 0x18fc0
leaq 0xe332(%rip), %rsi      # 0x12046
callq 0x3200
leaq 0xe34e(%rip), %rsi      # 0x1206e
movq %rax, %rdi
callq 0x3200
leaq 0xe323(%rip), %rsi      # 0x12052
movq %rax, %rdi
callq 0x3200
leaq -0x90(%rbp), %rsi
movq %rax, %rdi
callq 0x31e0
movq %rax, %rdi
callq 0x3140
movq -0x50(%rbp), %rax
cmpl $-0x1, (%rax)
pushq $0x3
popq %rax
movl %eax, -0x2c(%rbp)
je 0x3d66
movq -0x58(%rbp), %rax
cmpl $-0x1, (%rax)
jne 0x3da4
leaq 0xe30f(%rip), %rcx      # 0x1207c
leaq -0x90(%rbp), %rdi
pushq $0x1
popq %rdx
xorl %esi, %esi
callq 0x32b0
testl %eax, %eax
jne 0x3d8a
pushq $0x2
popq %rax
movl %eax, -0x2c(%rbp)
jmp 0x3da4
movq -0x50(%rbp), %rax
cmpl $-0x1, (%rax)
je 0x43f5
movq -0x58(%rbp), %rax
cmpl $-0x1, (%rax)
je 0x43f5
movq %r14, -0x98(%rbp)
leaq -0x128(%rbp), %r15
movq -0x68(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x38(%rbp)
movq -0x60(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x40(%rbp)
decl -0x2c(%rbp)
xorl %r13d, %r13d
leaq -0x330(%rbp), %r14
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
leaq 0xe292(%rip), %rcx      # 0x1207c
callq 0x32b0
testl %eax, %eax
je 0x3efe
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
leaq 0xe730(%rip), %rcx      # 0x1253a
callq 0x32b0
testl %eax, %eax
jne 0x43ed
movq 0x151a2(%rip), %rdi     # 0x18fc0
leaq 0xe284(%rip), %rsi      # 0x120a9
callq 0x3200
movq %rax, %rdi
callq 0x3140
leaq -0x1e8(%rbp), %rbx
movq %rbx, %rdi
leaq -0x90(%rbp), %rsi
callq 0x32c0
movq %r14, %rdi
leaq -0x530(%rbp), %rsi
movq %rbx, %rdx
callq 0x8298
leaq -0x168(%rbp), %rdi
movq %r14, %rsi
callq 0x6198
movq %r14, %rdi
callq 0x6228
movq %rbx, %rdi
callq 0x3120
movq %r14, %rdi
movq -0x38(%rbp), %rsi
callq 0x32c0
movq %r15, %rdi
movq %r14, %rsi
callq 0x6321
testb %al, %al
je 0x4189
leaq -0x438(%rbp), %r12
movq %r12, %rdi
movq -0x40(%rbp), %rsi
callq 0x32c0
movq %r12, %rdi
leaq 0xe860(%rip), %rsi      # 0x12715
callq 0x6261
movl %eax, %ebx
movq %r12, %rdi
callq 0x3120
movq %r14, %rdi
callq 0x3120
testb %bl, %bl
je 0x4191
leaq -0x188(%rbp), %rdi
movq %r15, %rsi
callq 0x32c0
movq -0x40(%rbp), %rdi
leaq -0x188(%rbp), %rbx
movq %rbx, %rsi
callq 0x3160
movq %rbx, %rdi
jmp 0x418c
movq 0x150bb(%rip), %rdi     # 0x18fc0
leaq 0xe172(%rip), %rsi      # 0x1207e
callq 0x3200
movq %rax, %rdi
callq 0x3140
leaq -0x248(%rbp), %rbx
movq %rbx, %rdi
leaq -0x90(%rbp), %rsi
callq 0x32c0
movq %r14, %rdi
leaq -0x530(%rbp), %rsi
movq %rbx, %rdx
callq 0x8298
leaq -0x168(%rbp), %rdi
movq %r14, %rsi
callq 0x6198
movq %r14, %rdi
callq 0x6228
movq %rbx, %rdi
callq 0x3120
movq %r14, %rdi
movq -0x38(%rbp), %rsi
callq 0x32c0
movq %r14, %rdi
leaq 0xe79f(%rip), %rsi      # 0x12715
callq 0x6261
movl %eax, %ebx
movq %r14, %rdi
callq 0x3120
testb %bl, %bl
je 0x3fb3
leaq -0x1c8(%rbp), %rdi
movq %r15, %rsi
callq 0x32c0
movq -0x38(%rbp), %rdi
leaq -0x1c8(%rbp), %rbx
movq %rbx, %rsi
callq 0x3160
movq %rbx, %rdi
callq 0x3120
movq %r14, %rdi
movq -0x38(%rbp), %rsi
callq 0x32c0
movq %r15, %rdi
movq %r14, %rsi
callq 0x6271
movl %eax, %ebx
movq %r14, %rdi
callq 0x3120
testb %bl, %bl
je 0x4043
movl -0x164(%rbp), %esi
movq %r14, %rdi
callq 0xffb0
leaq -0x418(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6294
movq %r14, %rdi
callq 0x10e3c
leaq -0x8d0(%rbp), %rdi
movq %rbx, %rsi
callq 0x60b0
leaq -0x228(%rbp), %r12
movq %r12, %rdi
leaq -0x108(%rbp), %rsi
callq 0x32c0
movq %r14, %rdi
movq -0x68(%rbp), %rsi
leaq -0x8d0(%rbp), %rbx
movq %rbx, %rdx
movq %r12, %rcx
callq 0x9ce6
jmp 0x40d2
movq %r14, %rdi
movq -0x40(%rbp), %rsi
callq 0x32c0
movq %r15, %rdi
movq %r14, %rsi
callq 0x6271
movl %eax, %ebx
movq %r14, %rdi
callq 0x3120
testb %bl, %bl
je 0x40f9
movl -0x164(%rbp), %esi
movq %r14, %rdi
callq 0xffb0
leaq -0x418(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6294
movq %r14, %rdi
callq 0x10e3c
leaq -0x7e8(%rbp), %rdi
movq %rbx, %rsi
callq 0x60b0
leaq -0x208(%rbp), %r12
movq %r12, %rdi
leaq -0x108(%rbp), %rsi
callq 0x32c0
movq %r14, %rdi
movq -0x60(%rbp), %rsi
leaq -0x7e8(%rbp), %rbx
movq %rbx, %rdx
movq %r12, %rcx
callq 0x9ce6
leaq -0xb8(%rbp), %rdi
movq %r14, %rsi
callq 0x3280
movq %r14, %rdi
callq 0x3120
movq %r12, %rdi
callq 0x3120
movq %rbx, %rdi
callq 0x10e3c
movq 0x14ec0(%rip), %rdi     # 0x18fc0
leaq 0xdf91(%rip), %rsi      # 0x12098
callq 0x3200
movq %rax, %rdi
leaq 0xdf88(%rip), %rsi      # 0x1209e
callq 0x3200
movq %rax, %rdi
leaq 0xdf2d(%rip), %rsi      # 0x12052
callq 0x3200
movq %rax, %rdi
leaq -0xb8(%rbp), %rsi
callq 0x31e0
movq %rax, %rdi
callq 0x3140
leaq -0x1a8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x32c0
movq -0x98(%rbp), %rbx
movq %rbx, %rdi
leaq -0x1a8(%rbp), %r12
movq %r12, %rsi
callq 0xaf76
movq %r12, %rdi
callq 0x3120
movq %r14, %rdi
movq %rbx, %rsi
movq -0x70(%rbp), %rdx
callq 0x3b80
jmp 0x438e
movq %r14, %rdi
callq 0x3120
cmpl $-0x1, -0xc4(%rbp)
je 0x4294
leaq -0xe8(%rbp), %rdi
movq 0x10(%rbp), %rsi
callq 0x6271
testb %al, %al
je 0x436e
movl -0x164(%rbp), %esi
movq %r14, %rdi
callq 0xffb0
leaq -0x418(%rbp), %rdi
movq %r14, %rsi
callq 0x6294
movq %r14, %rdi
callq 0x10e3c
movl -0x160(%rbp), %ebx
movl -0x138(%rbp), %r15d
movl -0x134(%rbp), %eax
movl %eax, -0x44(%rbp)
movq %r14, %rdi
movq -0x38(%rbp), %rsi
callq 0x32c0
leaq -0x128(%rbp), %rdi
movq %r14, %rsi
callq 0x6271
movl %eax, %r12d
movq %r14, %rdi
callq 0x3120
testb %r12b, %r12b
je 0x42f1
movl -0x164(%rbp), %esi
movq %r14, %rdi
callq 0xffb0
leaq -0x418(%rbp), %rdi
movq %r14, %rsi
callq 0x6294
movl %ebx, %r12d
movq %r14, %rdi
callq 0x10e3c
leaq -0x700(%rbp), %rdi
leaq -0x418(%rbp), %rsi
callq 0x60b0
movzbl -0xc7(%rbp), %r9d
movzbl -0xc8(%rbp), %eax
movq -0x68(%rbp), %rdi
leaq -0x700(%rbp), %rbx
movq %rbx, %rsi
movl %r15d, %edx
movl -0x44(%rbp), %ecx
movl %r12d, %r8d
pushq -0x130(%rbp)
pushq %rax
callq 0x9c0c
popq %rax
popq %rcx
jmp 0x4366
movq %r14, %rdi
movq -0x40(%rbp), %rsi
callq 0x32c0
movq %r14, %rdi
movq %r15, %rsi
callq 0x6271
movl %eax, %ebx
movq %r14, %rdi
callq 0x3120
testb %bl, %bl
je 0x42bf
movq -0x58(%rbp), %rax
jmp 0x42ec
movq %r14, %rdi
movq -0x38(%rbp), %rsi
callq 0x32c0
movq %r14, %rdi
movq %r15, %rsi
callq 0x6271
movl %eax, %ebx
movq %r14, %rdi
callq 0x3120
testb %bl, %bl
je 0x436e
movq -0x50(%rbp), %rax
orl $-0x1, (%rax)
jmp 0x436e
movq %r14, %rdi
movq -0x40(%rbp), %rsi
callq 0x32c0
leaq -0x128(%rbp), %rdi
movq %r14, %rsi
callq 0x6271
movl %eax, %r12d
movq %r14, %rdi
callq 0x3120
testb %r12b, %r12b
je 0x436e
movl %ebx, %r12d
leaq -0x618(%rbp), %rdi
leaq -0x418(%rbp), %rsi
callq 0x60b0
movzbl -0xc7(%rbp), %r9d
movzbl -0xc8(%rbp), %eax
movq -0x60(%rbp), %rdi
leaq -0x618(%rbp), %rbx
movq %rbx, %rsi
movl %r15d, %edx
movl -0x44(%rbp), %ecx
movl %r12d, %r8d
pushq -0x130(%rbp)
pushq %rax
callq 0x9c0c
popq %rax
popq %rcx
movq %rbx, %rdi
callq 0x10e3c
cmpl -0x2c(%rbp), %r13d
leaq -0x128(%rbp), %r15
jge 0x43ed
movq %r14, %rdi
movq -0x98(%rbp), %rsi
movq -0x70(%rbp), %rdx
callq 0x3b80
leaq -0x90(%rbp), %rdi
movq %r14, %rsi
callq 0x3280
movq %r14, %rdi
callq 0x3120
movq 0x14c14(%rip), %rdi     # 0x18fc0
leaq 0xdc93(%rip), %rsi      # 0x12046
callq 0x3200
movq %rax, %rdi
leaq 0xdcac(%rip), %rsi      # 0x1206e
callq 0x3200
movq %rax, %rdi
leaq 0xdc81(%rip), %rsi      # 0x12052
callq 0x3200
movq %rax, %rdi
leaq -0x90(%rbp), %rsi
callq 0x31e0
movq %rax, %rdi
callq 0x3140
incl %r13d
jmp 0x3dd7
leaq 0xe13e(%rip), %rcx      # 0x1253a
leaq -0x90(%rbp), %rdi
pushq $0x1
popq %rdx
xorl %esi, %esi
callq 0x32b0
testl %eax, %eax
jne 0x4418
pushq $0x1
jmp 0x3d84
movq -0x58(%rbp), %rax
movl (%rax), %eax
movq -0x50(%rbp), %rcx
andl (%rcx), %eax
xorl %ecx, %ecx
cmpl $-0x1, %eax
setne %cl
leal (%rcx,%rcx,2), %eax
jmp 0x3d85
movq %rax, %rbx
leaq -0x618(%rbp), %rdi
jmp 0x44ee
movq %rax, %rbx
leaq -0x700(%rbp), %rdi
jmp 0x44ee
jmp 0x44e4
jmp 0x453e
jmp 0x453e
jmp 0x453e
jmp 0x453e
movq %rax, %rbx
leaq -0x188(%rbp), %rdi
jmp 0x4531
jmp 0x453e
jmp 0x44e4
jmp 0x453e
jmp 0x453e
movq %rax, %rbx
leaq -0x208(%rbp), %rdi
callq 0x3120
jmp 0x449f
movq %rax, %rbx
leaq -0x7e8(%rbp), %rdi
jmp 0x44ee
jmp 0x453e
jmp 0x44e4
jmp 0x453e
jmp 0x453e
movq %rax, %rbx
leaq -0x330(%rbp), %rdi
jmp 0x4531
movq %rax, %rbx
leaq -0x228(%rbp), %rdi
callq 0x3120
jmp 0x44d9
movq %rax, %rbx
leaq -0x8d0(%rbp), %rdi
jmp 0x44ee
jmp 0x453e
movq %rax, %rbx
leaq -0x330(%rbp), %rdi
callq 0x10e3c
jmp 0x4541
jmp 0x453e
jmp 0x453e
movq %rax, %rbx
leaq -0x1c8(%rbp), %rdi
jmp 0x4531
jmp 0x453e
movq %rax, %rbx
leaq -0x1e8(%rbp), %rdi
jmp 0x4531
jmp 0x453e
jmp 0x453e
movq %rax, %rbx
leaq -0x1a8(%rbp), %rdi
jmp 0x4531
jmp 0x453e
jmp 0x453e
movq %rax, %rbx
leaq -0x248(%rbp), %rdi
callq 0x3120
jmp 0x4541
jmp 0x453e
jmp 0x453e
jmp 0x453e
movq %rax, %rbx
leaq -0x418(%rbp), %rdi
callq 0x10e3c
jmp 0x4552
movq %rax, %rbx
leaq -0x530(%rbp), %rdi
callq 0x7716
jmp 0x4563
movq %rax, %rbx
leaq -0x168(%rbp), %rdi
callq 0x6228
leaq -0x90(%rbp), %rdi
callq 0x3120
leaq -0xb8(%rbp), %rdi
callq 0x3120
movq %rbx, %rdi
callq 0x33c0