// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x448, %rsp            # imm = 0x448
movq %rcx, -0x30(%rbp)
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %r15
leaq -0x278(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x89ba(%rip), %rsi      # 0x126db
leaq -0x148(%rbp), %rdi
leaq -0x380(%rbp), %rdx
callq 0x30e0
leaq -0x380(%rbp), %rdi
callq 0x7668
leaq -0x468(%rbp), %rdi
movq %r13, %rsi
callq 0x60b0
leaq -0x110(%rbp), %rdi
leaq -0x468(%rbp), %rdx
movq %r12, %rsi
callq 0xb142
leaq -0x468(%rbp), %rdi
callq 0x10e3c
movq -0x108(%rbp), %rax
cmpq -0x110(%rbp), %rax
je 0xa09f
movl $0xe8, %edi
callq 0x3210
movq %rax, %rbx
movl 0x4(%r13), %esi
movq %rax, %rdi
callq 0xffb0
leaq -0x128(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0xa686
leaq -0x128(%rbp), %rdx
movq %r12, %rdi
movq %rbx, %rsi
callq 0xbd5e
movq %rax, %r13
leaq -0x128(%rbp), %rdi
callq 0xaca8
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0xc856
cmpl $0x0, 0x18(%r12)
jle 0x9e42
movq %rbx, -0x58(%rbp)
movq %r15, %r14
movq %r13, %rcx
shrq $0x20, %rcx
leaq -0x50(%rbp), %rdi
movq %r12, %rsi
movl %r13d, %edx
callq 0xa3aa
leaq -0x148(%rbp), %rbx
leaq -0x50(%rbp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3280
movq %r15, %rdi
callq 0x3120
leaq 0x88b1(%rip), %rsi      # 0x126db
movq %rbx, %rdi
callq 0x64ed
movq -0x58(%rbp), %rbx
movq %r14, %r15
testb %al, %al
je 0x9e42
decl 0x18(%r12)
leaq -0x380(%rbp), %rdi
movq %r13, %rsi
callq 0x81e2
movq %rax, %r13
addq $0x20, %r12
leaq 0x8882(%rip), %rsi      # 0x126e1
leaq -0x1e8(%rbp), %rdi
movq %r12, %rdx
callq 0x64fa
leaq 0x8872(%rip), %rdx      # 0x126e7
leaq -0x208(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x6415
leaq -0x228(%rbp), %rdi
leaq -0x208(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x6570
leaq 0x8848(%rip), %rdx      # 0x126ee
leaq -0x248(%rbp), %rdi
leaq -0x228(%rbp), %rsi
callq 0x6415
movl 0x4(%rbx), %edx
leaq -0x1c8(%rbp), %rdi
leaq -0x380(%rbp), %rsi
callq 0x7778
leaq -0x268(%rbp), %rdi
leaq -0x248(%rbp), %rsi
leaq -0x1c8(%rbp), %rdx
callq 0x63a4
leaq 0x8806(%rip), %rdx      # 0x126f6
leaq -0x78(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x6415
leaq -0x1a8(%rbp), %rdi
movl %r13d, %esi
callq 0x646c
leaq -0x98(%rbp), %rdi
leaq -0x78(%rbp), %rsi
leaq -0x1a8(%rbp), %rdx
callq 0x63a4
leaq 0x8722(%rip), %rdx      # 0x1264f
leaq -0xb8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x6415
shrq $0x20, %r13
leaq -0x188(%rbp), %rdi
movl %r13d, %esi
callq 0x646c
leaq -0xd8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
leaq -0x188(%rbp), %rdx
callq 0x63a4
leaq 0x86db(%rip), %rdx      # 0x1264f
leaq -0xf8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x6415
imull $0x5a, (%rbx), %esi
leaq -0x168(%rbp), %rdi
callq 0x646c
leaq -0x50(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
leaq -0x168(%rbp), %rdx
callq 0x63a4
leaq -0x288(%rbp), %r14
leaq -0x50(%rbp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3280
movq %rbx, %rdi
callq 0x3120
leaq -0x168(%rbp), %rdi
callq 0x3120
leaq -0xf8(%rbp), %rdi
callq 0x3120
leaq -0xd8(%rbp), %rdi
callq 0x3120
leaq -0x188(%rbp), %rdi
callq 0x3120
leaq -0xb8(%rbp), %rdi
callq 0x3120
leaq -0x98(%rbp), %rdi
callq 0x3120
leaq -0x1a8(%rbp), %rdi
callq 0x3120
leaq -0x78(%rbp), %rdi
callq 0x3120
leaq -0x268(%rbp), %rdi
callq 0x3120
leaq -0x1c8(%rbp), %rdi
callq 0x3120
leaq -0x248(%rbp), %rdi
callq 0x3120
leaq -0x228(%rbp), %rdi
callq 0x3120
leaq -0x208(%rbp), %rdi
callq 0x3120
leaq -0x1e8(%rbp), %rdi
callq 0x3120
leaq -0x50(%rbp), %rdi
leaq -0x148(%rbp), %rdx
movq %r14, %rsi
callq 0xa6d6
leaq 0x8689(%rip), %rdx      # 0x12713
leaq -0x50(%rbp), %rsi
movq %r15, %rdi
callq 0x6415
leaq -0x50(%rbp), %rdi
jmp 0xa17c
addq $0x20, %r12
leaq 0x8637(%rip), %rsi      # 0x126e1
leaq -0x98(%rbp), %rdi
movq %r12, %rdx
callq 0x64fa
leaq 0x8627(%rip), %rdx      # 0x126e7
leaq -0xb8(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x6415
leaq -0xd8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
movq -0x30(%rbp), %rdx
callq 0x6570
leaq 0x860a(%rip), %rdx      # 0x126fb
leaq -0xf8(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x6415
movl 0x4(%r13), %edx
leaq -0x78(%rbp), %rdi
leaq -0x380(%rbp), %rsi
callq 0x7778
leaq -0x50(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x63a4
leaq 0x85cf(%rip), %rdx      # 0x12702
leaq -0x50(%rbp), %rsi
movq %r15, %rdi
callq 0x6415
leaq -0x50(%rbp), %rdi
callq 0x3120
leaq -0x78(%rbp), %rdi
callq 0x3120
leaq -0xf8(%rbp), %rdi
callq 0x3120
leaq -0xd8(%rbp), %rdi
callq 0x3120
leaq -0xb8(%rbp), %rdi
callq 0x3120
leaq -0x98(%rbp), %rdi
callq 0x3120
leaq -0x110(%rbp), %rdi
callq 0xaca8
leaq -0x380(%rbp), %rdi
callq 0x7716
leaq -0x148(%rbp), %rdi
callq 0x3120
leaq -0x288(%rbp), %rdi
callq 0x3120
movq %r15, %rax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x3120
jmp 0xa1d7
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x3120
jmp 0xa1e5
movq %rax, %rbx
leaq -0xf8(%rbp), %rdi
callq 0x3120
jmp 0xa1f6
movq %rax, %rbx
leaq -0xd8(%rbp), %rdi
callq 0x3120
jmp 0xa207
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x3120
leaq -0x98(%rbp), %rdi
jmp 0xa2f6
movq %rax, %rbx
jmp 0xa213
jmp 0xa36e
jmp 0xa36e
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
jmp 0xa2f6
jmp 0xa36e
movq %rax, %rbx
leaq -0x168(%rbp), %rdi
callq 0x3120
jmp 0xa253
movq %rax, %rbx
leaq -0xf8(%rbp), %rdi
callq 0x3120
jmp 0xa264
movq %rax, %rbx
leaq -0xd8(%rbp), %rdi
callq 0x3120
jmp 0xa275
movq %rax, %rbx
leaq -0x188(%rbp), %rdi
callq 0x3120
jmp 0xa286
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x3120
leaq -0x98(%rbp), %rdi
callq 0x3120
leaq -0x1a8(%rbp), %rdi
callq 0x3120
leaq -0x78(%rbp), %rdi
callq 0x3120
leaq -0x268(%rbp), %rdi
callq 0x3120
leaq -0x1c8(%rbp), %rdi
callq 0x3120
leaq -0x248(%rbp), %rdi
callq 0x3120
leaq -0x228(%rbp), %rdi
callq 0x3120
leaq -0x208(%rbp), %rdi
callq 0x3120
leaq -0x1e8(%rbp), %rdi
callq 0x3120
jmp 0xa371
movq %rax, %rbx
jmp 0xa292
movq %rax, %rbx
jmp 0xa29e
movq %rax, %rbx
jmp 0xa2aa
movq %rax, %rbx
jmp 0xa2b3
movq %rax, %rbx
jmp 0xa2bf
movq %rax, %rbx
jmp 0xa2cb
movq %rax, %rbx
jmp 0xa2d7
movq %rax, %rbx
jmp 0xa2e3
movq %rax, %rbx
jmp 0xa2ef
jmp 0xa36e
jmp 0xa36e
movq %rax, %rbx
leaq -0x128(%rbp), %rdi
callq 0xaca8
jmp 0xa371
movq %rbx, %rdi
movq %rax, %rbx
callq 0x31f0
jmp 0xa371
jmp 0xa36e
movq %rax, %rbx
leaq -0x468(%rbp), %rdi
callq 0x10e3c
jmp 0xa37d
movq %rax, %rbx
jmp 0xa37d
movq %rax, %rbx
jmp 0xa389
movq %rax, %rbx
jmp 0xa395
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
callq 0xaca8
leaq -0x380(%rbp), %rdi
callq 0x7716
leaq -0x148(%rbp), %rdi
callq 0x3120
leaq -0x288(%rbp), %rdi
callq 0x3120
movq %rbx, %rdi
callq 0x33c0
nop