// File: Doug0855[P]TigerZone/Game.cpp
// Function: Game::makeMove(Tile, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
std::string Game::makeMove(Tile tile, std::string moveNumber) {
  std::string placement;
  std::string tiger = " NONE";
  Adapter adapter;

	// get all location the tile can be placed at
	std::vector<std::pair<int,int> > availableLocations = gameboard.display_positions(tile);
	// check if there are any available moves. If so then place at the optimal spot.
	if(availableLocations.size() > 0) {
		Tile *tmpTile = new Tile(tile.getNum());
		// get best place out of the available location according to our ai
		std::pair<int, int> optimalLocation = gameboard.getOptimalPlacement(*tmpTile, availableLocations);
		//place the tile
		gameboard.place_tile(optimalLocation, *tmpTile);
		// if we have tiger run the tiger ai
		if(numMeeples > 0)
		{
			// try to place a tiger
		  	tiger = meepleAi(optimalLocation.first, optimalLocation.second);
			// if we placed a tiger subtract from the number of tigers we have
			if (tiger != " NONE") numMeeples--;
		}

		std::pair<int,int> convertCoordinates = adapter.convertCoordinates(optimalLocation);
		//debugging std::cout << "DEBUG: Optimal location first: " << optimalLocation.first << std::endl;
		//debugging std::cout << "DEBUG: Optimal location second: " << optimalLocation.second << std::endl;
		placement = "GAME " + gameId + " MOVE " + moveNumber + " PLACE " + adapter.tileToExpr(tmpTile->getNum()) +" AT " + std::to_string(convertCoordinates.first) + " " + std::to_string(convertCoordinates.second)  + " " + std::to_string(tmpTile->getRotations() * 90);

		return placement + tiger + "\r\n";
	}
	else {
		return "GAME " + gameId + " MOVE " + moveNumber + " TILE " + adapter.tileToExpr(tile.getNum()) +" UNPLACEABLE PASS\r\n";
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x640, %rsp            # imm = 0x640
movq %rcx, -0x5c8(%rbp)
movq %rdx, -0x5c0(%rbp)
movq %rdi, -0x5b8(%rbp)
movq %rdi, %rax
movq %rax, -0x5b0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x5a8(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x33c0
leaq -0x61(%rbp), %rdi
movq %rdi, -0x5a0(%rbp)
callq 0x3500
movq -0x5a0(%rbp), %rdx
leaq 0x1562b(%rip), %rsi     # 0x29657
leaq -0x60(%rbp), %rdi
callq 0x33b0
jmp 0x14037
leaq -0x61(%rbp), %rdi
callq 0x32f0
leaq -0x170(%rbp), %rdi
callq 0xe260
jmp 0x1404e
movq -0x5c0(%rbp), %rsi
movq -0x5a8(%rbp), %rax
movq %rax, -0x5d0(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x82a0
jmp 0x14071
movq -0x5d0(%rbp), %rsi
leaq -0x188(%rbp), %rdi
leaq -0x270(%rbp), %rdx
callq 0x18760
jmp 0x1408d
leaq -0x270(%rbp), %rdi
callq 0x26870
leaq -0x188(%rbp), %rdi
callq 0x15160
cmpq $0x0, %rax
jbe 0x1478c
movl $0xe8, %edi
callq 0x32c0
movq %rax, -0x5d8(%rbp)
jmp 0x140c2
movq -0x5c0(%rbp), %rdi
callq 0x15100
movl %eax, -0x5dc(%rbp)
jmp 0x140d6
movl -0x5dc(%rbp), %esi
movq -0x5d8(%rbp), %rdi
callq 0x250d0
jmp 0x140ea
movq -0x5a8(%rbp), %rax
movq -0x5d8(%rbp), %rcx
movq %rcx, -0x278(%rbp)
movq %rax, -0x5f0(%rbp)
movq -0x278(%rbp), %rax
movq %rax, -0x5e8(%rbp)
leaq -0x298(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x15230
jmp 0x14129
movq -0x5e8(%rbp), %rsi
movq -0x5f0(%rbp), %rdi
leaq -0x298(%rbp), %rdx
callq 0x19e60
movq %rax, -0x5f8(%rbp)
jmp 0x1414c
movq -0x5f8(%rbp), %rax
movq %rax, -0x280(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x15320
movq -0x5a8(%rbp), %rdi
movq -0x280(%rbp), %rax
movq %rax, -0x2a0(%rbp)
movq -0x278(%rbp), %rdx
movq -0x2a0(%rbp), %rsi
callq 0x1b3d0
jmp 0x14190
movq -0x5a8(%rbp), %rax
cmpl $0x0, 0x18(%rax)
jle 0x142d1
movq -0x5a8(%rbp), %rsi
movl -0x280(%rbp), %edx
movl -0x27c(%rbp), %ecx
leaq -0x2c0(%rbp), %rdi
callq 0x149d0
jmp 0x141c2
leaq -0x60(%rbp), %rdi
movq %rdi, -0x608(%rbp)
leaq -0x2c0(%rbp), %rsi
movq %rsi, -0x610(%rbp)
callq 0x3360
movq -0x610(%rbp), %rdi
callq 0x3210
movq -0x608(%rbp), %rdi
leaq 0x1545d(%rip), %rsi     # 0x29657
callq 0x8ce0
movb %al, -0x5f9(%rbp)
jmp 0x14207
movb -0x5f9(%rbp), %al
testb $0x1, %al
jne 0x14216
jmp 0x142cf
movq -0x5a8(%rbp), %rax
movl 0x18(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x18(%rax)
jmp 0x142cf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x61(%rbp), %rdi
callq 0x32f0
jmp 0x149b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x149af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x149a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x270(%rbp), %rdi
callq 0x26870
jmp 0x149a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x14997
movq -0x5d8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
callq 0x32a0
jmp 0x14997
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x298(%rbp), %rdi
callq 0x15320
jmp 0x14997
jmp 0x142d1
movq -0x280(%rbp), %rax
movq %rax, -0x2d0(%rbp)
movq -0x2d0(%rbp), %rsi
leaq -0x170(%rbp), %rdi
callq 0xfc40
movq %rax, -0x618(%rbp)
jmp 0x142fb
movq -0x5a8(%rbp), %rdx
movq -0x618(%rbp), %rax
movq %rax, -0x2c8(%rbp)
addq $0x20, %rdx
leaq 0x15342(%rip), %rsi     # 0x2965d
leaq -0x430(%rbp), %rdi
callq 0x8d10
jmp 0x14329
leaq 0x15333(%rip), %rdx     # 0x29663
leaq -0x410(%rbp), %rdi
leaq -0x430(%rbp), %rsi
callq 0x8ae0
jmp 0x14345
movq -0x5c8(%rbp), %rdx
leaq -0x3f0(%rbp), %rdi
leaq -0x410(%rbp), %rsi
callq 0x8e20
jmp 0x14361
leaq 0x15302(%rip), %rdx     # 0x2966a
leaq -0x3d0(%rbp), %rdi
leaq -0x3f0(%rbp), %rsi
callq 0x8ae0
jmp 0x1437d
movq -0x278(%rbp), %rdi
callq 0x15100
movl %eax, -0x61c(%rbp)
jmp 0x14391
movl -0x61c(%rbp), %edx
leaq -0x450(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0xe380
jmp 0x143ac
leaq -0x3b0(%rbp), %rdi
leaq -0x3d0(%rbp), %rsi
leaq -0x450(%rbp), %rdx
callq 0x8a10
jmp 0x143c8
leaq 0x152a3(%rip), %rdx     # 0x29672
leaq -0x390(%rbp), %rdi
leaq -0x3b0(%rbp), %rsi
callq 0x8ae0
jmp 0x143e4
movl -0x2c8(%rbp), %esi
leaq -0x470(%rbp), %rdi
callq 0x8b80
jmp 0x143f8
leaq -0x370(%rbp), %rdi
leaq -0x390(%rbp), %rsi
leaq -0x470(%rbp), %rdx
callq 0x8a10
jmp 0x14414
leaq 0x151b0(%rip), %rdx     # 0x295cb
leaq -0x350(%rbp), %rdi
leaq -0x370(%rbp), %rsi
callq 0x8ae0
jmp 0x14430
movl -0x2c4(%rbp), %esi
leaq -0x490(%rbp), %rdi
callq 0x8b80
jmp 0x14444
leaq -0x330(%rbp), %rdi
leaq -0x350(%rbp), %rsi
leaq -0x490(%rbp), %rdx
callq 0x8a10
jmp 0x14460
leaq 0x15164(%rip), %rdx     # 0x295cb
leaq -0x310(%rbp), %rdi
leaq -0x330(%rbp), %rsi
callq 0x8ae0
jmp 0x1447c
movq -0x278(%rbp), %rdi
callq 0x8130
movl %eax, -0x620(%rbp)
jmp 0x14490
movl -0x620(%rbp), %eax
imull $0x5a, %eax, %esi
leaq -0x4b0(%rbp), %rdi
callq 0x8b80
jmp 0x144a7
leaq -0x2f0(%rbp), %rdi
leaq -0x310(%rbp), %rsi
leaq -0x4b0(%rbp), %rdx
callq 0x8a10
jmp 0x144c3
leaq -0x40(%rbp), %rdi
movq %rdi, -0x628(%rbp)
leaq -0x2f0(%rbp), %rsi
movq %rsi, -0x630(%rbp)
callq 0x3360
movq -0x630(%rbp), %rdi
callq 0x3210
leaq -0x4b0(%rbp), %rdi
callq 0x3210
leaq -0x310(%rbp), %rdi
callq 0x3210
leaq -0x330(%rbp), %rdi
callq 0x3210
leaq -0x490(%rbp), %rdi
callq 0x3210
leaq -0x350(%rbp), %rdi
callq 0x3210
leaq -0x370(%rbp), %rdi
callq 0x3210
leaq -0x470(%rbp), %rdi
callq 0x3210
leaq -0x390(%rbp), %rdi
callq 0x3210
leaq -0x3b0(%rbp), %rdi
callq 0x3210
leaq -0x450(%rbp), %rdi
callq 0x3210
leaq -0x3d0(%rbp), %rdi
callq 0x3210
leaq -0x3f0(%rbp), %rdi
callq 0x3210
leaq -0x410(%rbp), %rdi
callq 0x3210
leaq -0x430(%rbp), %rdi
callq 0x3210
movq -0x628(%rbp), %rsi
leaq -0x4d0(%rbp), %rdi
leaq -0x60(%rbp), %rdx
callq 0x153b0
jmp 0x145ae
movq -0x5b8(%rbp), %rdi
leaq 0x150d3(%rip), %rdx     # 0x2968f
leaq -0x4d0(%rbp), %rsi
callq 0x8ae0
jmp 0x145ca
leaq -0x4d0(%rbp), %rdi
callq 0x3210
movl $0x1, -0x4d4(%rbp)
jmp 0x1495d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1475e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x14752
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x14746
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1473a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1472e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x14722
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x14716
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1470a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x146fe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x146f2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x146e6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x146da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x146ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x4b0(%rbp), %rdi
callq 0x3210
leaq -0x310(%rbp), %rdi
callq 0x3210
leaq -0x330(%rbp), %rdi
callq 0x3210
leaq -0x490(%rbp), %rdi
callq 0x3210
leaq -0x350(%rbp), %rdi
callq 0x3210
leaq -0x370(%rbp), %rdi
callq 0x3210
leaq -0x470(%rbp), %rdi
callq 0x3210
leaq -0x390(%rbp), %rdi
callq 0x3210
leaq -0x3b0(%rbp), %rdi
callq 0x3210
leaq -0x450(%rbp), %rdi
callq 0x3210
leaq -0x3d0(%rbp), %rdi
callq 0x3210
leaq -0x3f0(%rbp), %rdi
callq 0x3210
leaq -0x410(%rbp), %rdi
callq 0x3210
leaq -0x430(%rbp), %rdi
callq 0x3210
jmp 0x14997
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x4d0(%rbp), %rdi
callq 0x3210
jmp 0x14997
movq -0x5a8(%rbp), %rdx
addq $0x20, %rdx
leaq 0x14ebf(%rip), %rsi     # 0x2965d
leaq -0x578(%rbp), %rdi
callq 0x8d10
jmp 0x147ac
leaq 0x14eb0(%rip), %rdx     # 0x29663
leaq -0x558(%rbp), %rdi
leaq -0x578(%rbp), %rsi
callq 0x8ae0
jmp 0x147c8
movq -0x5c8(%rbp), %rdx
leaq -0x538(%rbp), %rdi
leaq -0x558(%rbp), %rsi
callq 0x8e20
jmp 0x147e4
leaq 0x14e8c(%rip), %rdx     # 0x29677
leaq -0x518(%rbp), %rdi
leaq -0x538(%rbp), %rsi
callq 0x8ae0
jmp 0x14800
movq -0x5c0(%rbp), %rdi
callq 0x15100
movl %eax, -0x634(%rbp)
jmp 0x14814
movl -0x634(%rbp), %edx
leaq -0x598(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0xe380
jmp 0x1482f
leaq -0x4f8(%rbp), %rdi
leaq -0x518(%rbp), %rsi
leaq -0x598(%rbp), %rdx
callq 0x8a10
jmp 0x1484b
movq -0x5b8(%rbp), %rdi
leaq 0x14e25(%rip), %rdx     # 0x2967e
leaq -0x4f8(%rbp), %rsi
callq 0x8ae0
jmp 0x14867
leaq -0x4f8(%rbp), %rdi
callq 0x3210
leaq -0x598(%rbp), %rdi
callq 0x3210
leaq -0x518(%rbp), %rdi
callq 0x3210
leaq -0x538(%rbp), %rdi
callq 0x3210
leaq -0x558(%rbp), %rdi
callq 0x3210
leaq -0x578(%rbp), %rdi
callq 0x3210
movl $0x1, -0x4d4(%rbp)
jmp 0x1495d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1494f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x14943
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x14937
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1492b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x1491f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x4f8(%rbp), %rdi
callq 0x3210
leaq -0x598(%rbp), %rdi
callq 0x3210
leaq -0x518(%rbp), %rdi
callq 0x3210
leaq -0x538(%rbp), %rdi
callq 0x3210
leaq -0x558(%rbp), %rdi
callq 0x3210
leaq -0x578(%rbp), %rdi
callq 0x3210
jmp 0x14997
leaq -0x188(%rbp), %rdi
callq 0x15320
leaq -0x170(%rbp), %rdi
callq 0xe2f0
leaq -0x60(%rbp), %rdi
callq 0x3210
leaq -0x40(%rbp), %rdi
callq 0x3210
movq -0x5b0(%rbp), %rax
addq $0x640, %rsp            # imm = 0x640
popq %rbp
retq
leaq -0x188(%rbp), %rdi
callq 0x15320
leaq -0x170(%rbp), %rdi
callq 0xe2f0
leaq -0x60(%rbp), %rdi
callq 0x3210
leaq -0x40(%rbp), %rdi
callq 0x3210
movq -0x70(%rbp), %rdi
callq 0x34f0
nopw (%rax,%rax)