// File: /workspace/github_cpp_makefile_star2_O2/Doug0855[P]TigerZone/main.cpp
// Function: matchProtocol(Client&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)
void matchProtocol(Client &client, std::string &message_list)
{ //This protocol is called once for each match.
	Adapter adapter;
	values_t message_info;
	int number_of_tiles, game1_success, game2_success;
	int count = 0;
	bool lastMessage = true;
	std::string OPPONENT_ID;
	std::string message = getMesssage(client, message_list);
	std::cout << GREEN << "Server sent: " << RESET << message << std::endl;
	Tile tile1;
	TileStack tStack;

	while (lastMessage) //while Game is not over
	{
		if (message.compare(0,1,"Y") == 0) //getting opponent player id
		{
			std::cout << "	OPPONENT PLAYER INFO" << std::endl;
			//message_info = adapter.translate(message);
			//OPPONENT_ID = message_info.playerId; 					//use opponent player id
			OPPONENT_ID = message.substr(24, std::string::npos-24);
			std::cout << "	Opponent ID is: " << OPPONENT_ID << std::endl;
			message = getMesssage(client, message_list);
			std::cout << GREEN << "Server sent: " << RESET << message << std::endl;
		}
		else if (message.compare(0,1,"S") == 0) //getting starting tile information
		{
			std::cout << "	STARTING TILE INFO " << std::endl;
			message_info = adapter.translate(message);
			tile1 = Tile(message_info.tile_num); //getting first tile
			message = getMesssage(client, message_list);
			std::cout << GREEN << "Server sent: " << RESET << message << std::endl;
		}
		else if (message.compare(0,1,"T") == 0) //get tile stack
		{
			std::cout << "	TILE STACK INFO" << std::endl;
			message_info = adapter.translate(message);
			number_of_tiles = message_info.number_of_tiles; //gettting the number of tiles
			tStack = TileStack(message_info.tile_stack); //getting tile stack
			message = getMesssage(client, message_list);
			std::cout << GREEN << "Server sent: " << RESET << message << std::endl;
		}
		else if (message.compare(0,1,"M") == 0)
		{
			std::cout << "	MATCH BEGINS SOON" << std::endl;
			message_info = adapter.translate(message);
			//use planning time
			Player ai, opponent;
			Game game1("", ai, opponent, tStack, tile1, std::pair<int,int> (72,72));
			Game game2("", opponent, ai, tStack, tile1, std::pair<int,int> (72,72));
			game1_success = 0;
			game2_success = 0;
			for (int i = 0; i < number_of_tiles; i++)
			{
				std::cout<<"	Running moveProtocol: Game success for game 1 and 2 are " << game1_success << " and " << game2_success << std::endl;
				moveProtocol(client, message_list, game1, game2, game1_success, game2_success, OPPONENT_ID); //client, message_list, game1 and game2
				if (game1_success == -1 && game2_success == -1)
				{
					break;
				}
					//move must return a value to break from for loop in case of forfeit
				//std::cout<<"Running moveProtocol second time."<<std::endl;
				//moveProtocol(client, message_list, game1, game2, game1_success, game2_success); //client, message_list, game1 and game2
			}
			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 OVER MESSAGE RECEIVED #" << count << std::endl;
			count++;
			if (count == 2)
				lastMessage = false;
			else
			{
				message = getMesssage(client, message_list);
				std::cout << GREEN << "Server sent: " << RESET << message << std::endl;
			}
		}
		else //hopefully this is never reached
		{
			std::cout << "	ERROR: previous message could not be processed correctly. Message skipped!" << std::endl;
			std::cout << "		ERROR message: " << message << std::endl;
			message = getMesssage(client, message_list);
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x858, %rsp            # imm = 0x858
movq %rsi, %rbx
movq %rdi, %r14
leaq -0x6a8(%rbp), %rdi
callq 0x7668
leaq -0x2f0(%rbp), %rax
xorps %xmm0, %xmm0
movups %xmm0, -0x28(%rax)
movups %xmm0, -0x38(%rax)
andq $0x0, -0x18(%rax)
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq -0x2d0(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq -0x2b0(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
andl $0x0, 0x14(%rax)
leaq -0x98(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq -0x88(%rbp), %rdi
movq %r14, -0x38(%rbp)
movq %r14, %rsi
movq %rbx, -0x30(%rbp)
movq %rbx, %rdx
callq 0x3b80
movq 0x1498c(%rip), %rdi     # 0x18fc0
leaq 0xda0b(%rip), %rsi      # 0x12046
callq 0x3200
leaq 0xda27(%rip), %rsi      # 0x1206e
movq %rax, %rdi
callq 0x3200
leaq 0xd9fc(%rip), %rsi      # 0x12052
movq %rax, %rdi
callq 0x3200
leaq -0x88(%rbp), %rsi
movq %rax, %rdi
callq 0x31e0
movq %rax, %rdi
callq 0x3140
leaq -0x5b0(%rbp), %rdi
callq 0x10d92
leaq -0x68(%rbp), %rdi
callq 0xf810
movq $0x0, -0x40(%rbp)
leaq -0x88(%rbp), %r13
leaq -0x4c8(%rbp), %rbx
leaq -0x150(%rbp), %r12
leaq -0x118(%rbp), %r15
movb $0x1, %r14b
testb $0x1, %r14b
je 0x4db4
movq %r13, %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
leaq 0xdb84(%rip), %rcx      # 0x1224e
callq 0x32b0
testl %eax, %eax
je 0x47b0
movq %r13, %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
leaq 0xdb5e(%rip), %rcx      # 0x12244
callq 0x32b0
testl %eax, %eax
je 0x4832
movq %r13, %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
leaq 0xde4a(%rip), %rcx      # 0x1254c
callq 0x32b0
testl %eax, %eax
je 0x4ca0
movq %r13, %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
leaq 0xd95e(%rip), %rcx      # 0x1207c
callq 0x32b0
testl %eax, %eax
je 0x4921
movq %r13, %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
leaq 0xde00(%rip), %rcx      # 0x1253a
callq 0x32b0
testl %eax, %eax
je 0x4be7
movq 0x14872(%rip), %rdi     # 0x18fc0
leaq 0xda2b(%rip), %rsi      # 0x12180
callq 0x3200
movq %rax, %rdi
callq 0x3140
movq 0x14857(%rip), %rdi     # 0x18fc0
leaq 0xda5c(%rip), %rsi      # 0x121cc
callq 0x3200
movq %rax, %rdi
movq %r13, %rsi
callq 0x31e0
movq %rax, %rdi
callq 0x3140
movq %rbx, %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x3b80
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3280
movq %rbx, %rdi
callq 0x3120
jmp 0x46bb
movq 0x14809(%rip), %rdi     # 0x18fc0
leaq 0xd903(%rip), %rsi      # 0x120c1
callq 0x3200
movq %rax, %rdi
callq 0x3140
movq %rbx, %rdi
movq %r13, %rsi
pushq $0x18
popq %rdx
pushq $-0x19
popq %rcx
callq 0x3220
leaq -0xa8(%rbp), %rdi
movq %rbx, %rsi
callq 0x3280
movq %rbx, %rdi
callq 0x3120
movq 0x147c6(%rip), %rdi     # 0x18fc0
leaq 0xd8d6(%rip), %rsi      # 0x120d7
callq 0x3200
movq %rax, %rdi
leaq -0xa8(%rbp), %rsi
callq 0x31e0
movq %rax, %rdi
callq 0x3140
movq %rbx, %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x3b80
jmp 0x48c5
movq 0x14787(%rip), %rdi     # 0x18fc0
leaq 0xd8a9(%rip), %rsi      # 0x120e9
callq 0x3200
movq %rax, %rdi
callq 0x3140
leaq -0x290(%rbp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x32c0
movq %rbx, %rdi
leaq -0x6a8(%rbp), %rsi
movq %r14, %rdx
callq 0x8298
leaq -0x340(%rbp), %rdi
movq %rbx, %rsi
callq 0x6198
movq %rbx, %rdi
callq 0x6228
movq %r14, %rdi
callq 0x3120
movl -0x33c(%rbp), %esi
movq %rbx, %rdi
callq 0xffb0
leaq -0x5b0(%rbp), %rdi
movq %rbx, %rsi
callq 0x6294
movq %rbx, %rdi
callq 0x10e3c
movq %rbx, %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x3b80
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3280
movq %rbx, %rdi
callq 0x3120
movq 0x146e1(%rip), %rdi     # 0x18fc0
leaq 0xd760(%rip), %rsi      # 0x12046
callq 0x3200
movq %rax, %rdi
leaq 0xd779(%rip), %rsi      # 0x1206e
callq 0x3200
movq %rax, %rdi
leaq 0xd74e(%rip), %rsi      # 0x12052
callq 0x3200
movq %rax, %rdi
movq %r13, %rsi
callq 0x31e0
movq %rax, %rdi
callq 0x3140
jmp 0x46bb
movq 0x14698(%rip), %rdi     # 0x18fc0
leaq 0xd7e0(%rip), %rsi      # 0x1210f
callq 0x3200
movq %rax, %rdi
callq 0x3140
leaq -0x250(%rbp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x32c0
movq %rbx, %rdi
leaq -0x6a8(%rbp), %rsi
movq %r14, %rdx
callq 0x8298
leaq -0x340(%rbp), %rdi
movq %rbx, %rsi
callq 0x6198
movq %rbx, %rdi
callq 0x6228
movq %r14, %rdi
callq 0x3120
leaq -0xe8(%rbp), %rdi
callq 0xf79c
leaq -0xc8(%rbp), %rdi
callq 0xf79c
leaq -0x190(%rbp), %rdi
leaq 0xdd70(%rip), %rsi      # 0x12715
leaq -0x3e0(%rbp), %rdx
callq 0x30e0
leaq -0x170(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x6386
movq %r12, %rdi
leaq -0xc8(%rbp), %rsi
callq 0x6386
movq %r15, %rdi
leaq -0x68(%rbp), %rsi
callq 0x73b6
leaq -0x878(%rbp), %r13
movq %r13, %rdi
leaq -0x5b0(%rbp), %rsi
callq 0x60b0
movabsq $0x4800000048, %rax     # imm = 0x4800000048
movq %rax, (%rsp)
movq %rbx, %rdi
leaq -0x190(%rbp), %r14
movq %r14, %rsi
movq %r12, %rbx
leaq -0x170(%rbp), %r12
movq %r12, %rdx
movq %rbx, %rcx
movq %r15, %r8
movq %r13, %r9
callq 0x9574
movq %r13, %rdi
callq 0x10e3c
movq %r15, %rdi
callq 0xfaae
movq %rbx, %rdi
callq 0xf7ae
movq %r12, %rdi
callq 0xf7ae
movq %r14, %rdi
callq 0x3120
leaq -0x230(%rbp), %rbx
movq %rbx, %rdi
leaq 0xdcb1(%rip), %rsi      # 0x12715
leaq -0x1b0(%rbp), %rdx
callq 0x30e0
leaq -0x210(%rbp), %r15
movq %r15, %rdi
leaq -0xc8(%rbp), %rsi
callq 0x6386
leaq -0x1f0(%rbp), %r12
movq %r12, %rdi
leaq -0xe8(%rbp), %rsi
callq 0x6386
leaq -0x100(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x73b6
leaq -0x790(%rbp), %r14
movq %r14, %rdi
leaq -0x5b0(%rbp), %rsi
callq 0x60b0
movabsq $0x4800000048, %rax     # imm = 0x4800000048
movq %rax, (%rsp)
leaq -0x3e0(%rbp), %rdi
movq %rbx, %rsi
movq %r15, %rdx
movq %r12, %rcx
leaq -0x100(%rbp), %r13
movq %r13, %r8
movq %r14, %r9
callq 0x9574
movq %r14, %rdi
callq 0x10e3c
movq %r13, %rdi
callq 0xfaae
movq %r12, %rdi
callq 0xf7ae
movq %r15, %rdi
callq 0xf7ae
movq %rbx, %rdi
callq 0x3120
cmpl $0x0, -0x48(%rbp)
jg 0x4e0b
leaq -0x1b0(%rbp), %rbx
movq %rbx, %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x3b80
leaq -0x88(%rbp), %rdi
movq %rbx, %rsi
callq 0x3280
movq %rbx, %rdi
callq 0x3120
movq 0x14467(%rip), %rdi     # 0x18fc0
leaq 0xd4e6(%rip), %rsi      # 0x12046
callq 0x3200
movq %rax, %rdi
leaq 0xd4ff(%rip), %rsi      # 0x1206e
callq 0x3200
movq %rax, %rdi
leaq 0xd4d4(%rip), %rsi      # 0x12052
callq 0x3200
movq %rax, %rdi
leaq -0x88(%rbp), %rsi
callq 0x31e0
movq %rax, %rdi
callq 0x3140
leaq -0x3e0(%rbp), %rdi
callq 0x96a6
leaq -0x4c8(%rbp), %rbx
movq %rbx, %rdi
callq 0x96a6
leaq -0xc8(%rbp), %rdi
callq 0xf7ae
leaq -0xe8(%rbp), %rdi
callq 0xf7ae
leaq -0x150(%rbp), %r12
leaq -0x88(%rbp), %r13
leaq -0x118(%rbp), %r15
jmp 0x46bb
movq 0x143d2(%rip), %rdi     # 0x18fc0
leaq 0xd56d(%rip), %rsi      # 0x12162
callq 0x3200
movq %rax, %rdi
movq -0x40(%rbp), %rsi
callq 0x3390
movq %rax, %rdi
callq 0x3140
movq -0x40(%rbp), %rax
movl %eax, %ecx
incl %ecx
pushq $0x2
popq %rax
movq %rax, -0x40(%rbp)
movl %ecx, -0x44(%rbp)
cmpl $0x2, %ecx
setne %r14b
je 0x46b1
movq %rbx, %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x3b80
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3280
movq %rbx, %rdi
callq 0x3120
movq 0x14369(%rip), %rdi     # 0x18fc0
leaq 0xd3e8(%rip), %rsi      # 0x12046
callq 0x3200
movq %rax, %rdi
leaq 0xd401(%rip), %rsi      # 0x1206e
callq 0x3200
movq %rax, %rdi
leaq 0xd3d6(%rip), %rsi      # 0x12052
callq 0x3200
movq %rax, %rdi
movq %r13, %rsi
callq 0x31e0
movq %rax, %rdi
callq 0x3140
movl -0x44(%rbp), %eax
movq %rax, -0x40(%rbp)
jmp 0x46b1
movq 0x14319(%rip), %rdi     # 0x18fc0
leaq 0xd450(%rip), %rsi      # 0x120fe
callq 0x3200
movq %rax, %rdi
callq 0x3140
leaq -0x270(%rbp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x32c0
movq %rbx, %rdi
leaq -0x6a8(%rbp), %rsi
movq %r14, %rdx
callq 0x8298
leaq -0x340(%rbp), %rdi
movq %rbx, %rsi
callq 0x6198
movq %rbx, %rdi
callq 0x6228
movq %r14, %rdi
callq 0x3120
movl -0x340(%rbp), %eax
movl %eax, -0x48(%rbp)
leaq -0x130(%rbp), %r14
movq %r14, %rdi
leaq -0x328(%rbp), %rsi
callq 0x632e
movq %rbx, %rdi
movq %r14, %rsi
callq 0xf9ea
leaq -0x68(%rbp), %rdi
movq %rbx, %rsi
callq 0x6ea0
movq %rbx, %rdi
callq 0xfaae
leaq -0x130(%rbp), %rdi
callq 0x75ce
movq %rbx, %rdi
movq -0x38(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x3b80
movq %r13, %rdi
movq %rbx, %rsi
callq 0x3280
movq %rbx, %rdi
callq 0x3120
movq 0x1424e(%rip), %rdi     # 0x18fc0
leaq 0xd2cd(%rip), %rsi      # 0x12046
callq 0x3200
movq %rax, %rdi
leaq 0xd2e6(%rip), %rsi      # 0x1206e
callq 0x3200
movq %rax, %rdi
leaq 0xd2bb(%rip), %rsi      # 0x12052
callq 0x3200
movq %rax, %rdi
movq %r13, %rsi
callq 0x31e0
movq %rax, %rdi
callq 0x3140
jmp 0x46ae
leaq -0x68(%rbp), %rdi
callq 0xfaae
leaq -0x5b0(%rbp), %rdi
callq 0x10e3c
leaq -0x88(%rbp), %rdi
callq 0x3120
leaq -0xa8(%rbp), %rdi
callq 0x3120
leaq -0x340(%rbp), %rdi
callq 0x6228
leaq -0x6a8(%rbp), %rdi
callq 0x7716
addq $0x858, %rsp            # imm = 0x858
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
andl $0x0, -0x50(%rbp)
andl $0x0, -0x4c(%rbp)
movq 0x141a6(%rip), %rdi     # 0x18fc0
leaq 0xd301(%rip), %rsi      # 0x12122
callq 0x3200
movq %rax, %rdi
xorl %esi, %esi
callq 0x3390
leaq 0xd325(%rip), %rsi      # 0x1215c
movq %rax, %rdi
callq 0x3200
movq %rax, %rdi
xorl %esi, %esi
callq 0x3390
movq %rax, %rdi
callq 0x3140
leaq -0x1d0(%rbp), %rbx
leaq -0xa8(%rbp), %rsi
movq %rbx, %rdi
callq 0x32c0
movq %rbx, (%rsp)
leaq -0x4c8(%rbp), %rdx
leaq -0x3e0(%rbp), %rcx
leaq -0x50(%rbp), %r8
leaq -0x4c(%rbp), %r9
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0x3c20
movq %rax, %rbx
jmp 0x506b
jmp 0x4eb4
movq %rax, %rbx
jmp 0x5083
movq %rax, %rbx
leaq -0x1d0(%rbp), %rdi
callq 0x3120
jmp 0x502d
movq %rax, %rbx
jmp 0x5077
jmp 0x505f
movq %rax, %rbx
leaq -0x270(%rbp), %rdi
jmp 0x501f
jmp 0x505f
jmp 0x505f
movq %rax, %rbx
jmp 0x4ef3
jmp 0x505f
movq %rax, %rbx
leaq -0x4c8(%rbp), %rdi
callq 0xfaae
leaq -0x130(%rbp), %rdi
callq 0x75ce
jmp 0x5062
jmp 0x505f
jmp 0x505f
jmp 0x502a
jmp 0x505f
movq %rax, %rbx
jmp 0x4fd6
movq %rax, %rbx
leaq -0x878(%rbp), %rdi
callq 0x10e3c
jmp 0x4f79
movq %rax, %rbx
jmp 0x4f9d
movq %rax, %rbx
leaq -0x250(%rbp), %rdi
jmp 0x501f
movq %rax, %rbx
jmp 0x4f91
movq %rax, %rbx
jmp 0x4fee
movq %rax, %rbx
jmp 0x4f85
movq %rax, %rbx
jmp 0x5051
movq %rax, %rbx
jmp 0x5039
movq %rax, %rbx
jmp 0x4fca
jmp 0x502a
movq %rax, %rbx
jmp 0x4fe2
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
callq 0xfaae
leaq -0x150(%rbp), %rdi
callq 0xf7ae
leaq -0x170(%rbp), %rdi
callq 0xf7ae
leaq -0x190(%rbp), %rdi
callq 0x3120
jmp 0x5045
movq %rax, %rbx
jmp 0x5045
jmp 0x505f
movq %rax, %rbx
leaq -0x790(%rbp), %rdi
callq 0x10e3c
leaq -0x100(%rbp), %rdi
callq 0xfaae
leaq -0x1f0(%rbp), %rdi
callq 0xf7ae
leaq -0x210(%rbp), %rdi
callq 0xf7ae
leaq -0x230(%rbp), %rdi
callq 0x3120
jmp 0x5039
jmp 0x505f
movq %rax, %rbx
leaq -0x4c8(%rbp), %rdi
callq 0x10e3c
jmp 0x5062
jmp 0x505f
jmp 0x505f
jmp 0x505f
movq %rax, %rbx
leaq -0x290(%rbp), %rdi
callq 0x3120
jmp 0x5062
jmp 0x505f
jmp 0x505f
movq %rax, %rbx
leaq -0x3e0(%rbp), %rdi
callq 0x96a6
leaq -0x4c8(%rbp), %rdi
callq 0x96a6
leaq -0xc8(%rbp), %rdi
callq 0xf7ae
leaq -0xe8(%rbp), %rdi
callq 0xf7ae
jmp 0x5062
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0xfaae
leaq -0x5b0(%rbp), %rdi
callq 0x10e3c
leaq -0x88(%rbp), %rdi
callq 0x3120
leaq -0xa8(%rbp), %rdi
callq 0x3120
leaq -0x340(%rbp), %rdi
callq 0x6228
leaq -0x6a8(%rbp), %rdi
callq 0x7716
movq %rbx, %rdi
callq 0x33c0