// File: FakePsyho[P]halite2/MyBot.cpp
// Function: execOrder(Order&)
Move execOrder(Order &o) {
	const Ship& ship = m.get_ship(player_id, o.ship);
	
	if (o.type == OrderType::Colonize) {
		Planet& planet = m.planets[o.planet];
		if (ship.can_dock(planet)) {
			Move mv = Move::dock(ship.entity_id, planet.entity_id);
			mv.evasion = Evasion::None;
			return mv;
		} else {
			Move mv = move_to(ship, planet.location);
			mv.evasion = Evasion::None;
			return mv;
		}
		
	} else if (o.type == OrderType::AttackShip) {
		Ship eship = *enemyShips[o.target];
		double dist = ship.location.get_distance_to(eship.location);
		Location loc;
		loc = ship.location + (eship.location - ship.location).normalize() * max(MAX_SPEED, eship.location.dist(ship.location));
		if (!m.in_ex_bounds(loc, 4)) loc = ship.location + (eship.location - ship.location).normalize() * 1000;
		if (shipTarget[eship.entity_id] != eship.location)
			loc = shipTarget[eship.entity_id];
		double aces = 1e9;
		for (auto &e : findCloseEntities(ship.location, 10.0, MASK_ALLIES, ship.entity_id)) aces = min(aces, closestEnemyShip[e.entity_id]);
		double ces = closestEnemyShip[ship.entity_id];
		double maxSpeed = MAX_SPEED;
		if (maxFollowers[eship.entity_id] > 2 && ces < 20.0 && aces < 25.0 && ces < aces) maxSpeed = max(3.0, min(MAX_SPEED, 7.0 - (aces - ces) / 3));
		Move mv = move_to(ship, loc, maxSpeed);
		// Move mv = move_to(ship, eship.location, MAX_SPEED);
		mv.evasion = Evasion::Small;
		return mv;
		
	} else if (o.type == OrderType::AttackMiner) {
		Ship eship = *enemyShips[o.target];
		double dist = ship.location.get_distance_to(eship.location);
		
		double aces = 1e9;
		for (auto &e : findCloseEntities(ship.location, 10.0, MASK_ALLIES, ship.entity_id)) aces = min(aces, closestEnemyShip[e.entity_id]);
		double ces = closestEnemyShip[ship.entity_id];
		double maxSpeed = MAX_SPEED;
		if (maxFollowers[eship.entity_id] > 2 && ces < 20.0 && aces < 25.0 && ces < aces) maxSpeed = max(3.0, min(MAX_SPEED, 7.0 - (aces - ces) / 3));
		
		Move mv = move_to(ship, eship.location, maxSpeed, 5.05);
		mv.evasion = Evasion::Medium;
		return mv;
		
	} else if (o.type == OrderType::HitAndRun) {
		Ship eship = *enemyShips[o.target];
		double dist = ship.location.get_distance_to(eship.location);
		Move mv = move_to(ship, eship.location, MAX_SPEED, 5.05, true);
		mv.evasion = Evasion::None;
		return mv;
		
	// } else if (o.type == OrderType::DefendMiner) {
		// Ship aship = m.get_ship(player_id, aggressiveShips[o.target]);
		// double dist = ship.location.get_distance_to(aship.location);
		// Move mv = Move::stop(ship.entity_id);
		// REP(tries, 10) {
			// auto nav = move_to(ship, aship.location + Location(rng.nextDouble(-2, 2), rng.nextDouble(-2, 2)), max(0.0, min(dist + 1.25, MAX_SPEED)));
			// if (nav.Y) {
				// mv = nav.X;
				// break;
			// }
		// }
		// mv.evasion = Evasion::None;
		// return mv;		
		
	} else if (o.type == OrderType::Hide) {
		Location loc = Location(o.cornerx == 0 ? 1 : m.map_width - 1, o.cornery == 0 ? 1 : m.map_height - 1);
		double dist = ship.location.get_distance_to(loc);
		Move mv = move_to(ship, loc, min(dist, MAX_SPEED), 0.0, true);
		mv.evasion = Evasion::None;
		return mv;
		
	} else if (o.type == OrderType::Undock) {
		Move mv = Move::undock(ship.entity_id);
		return mv;
		
	} else {
		assert(false);
	}
}

// Assembly:
subq $0x418, %rsp            # imm = 0x418
movq %rdi, 0x68(%rsp)
movq %rdi, 0x70(%rsp)
movq %rsi, 0x410(%rsp)
movl 0x4ab3d(%rip), %esi     # 0x51d1c
movq 0x410(%rsp), %rax
movl 0x60(%rax), %edx
leaq 0x4ab37(%rip), %rdi     # 0x51d28
callq 0x13160
movq %rax, 0x408(%rsp)
movq 0x410(%rsp), %rax
cmpl $0x2, (%rax)
jne 0x72d3
movq 0x410(%rsp), %rax
movl 0x64(%rax), %eax
movl %eax, %esi
leaq 0x4ab05(%rip), %rdi     # 0x51d28
addq $0x80, %rdi
callq 0x13e40
movq %rax, 0x400(%rsp)
movq 0x408(%rsp), %rdi
movq 0x400(%rsp), %rsi
callq 0x13b40
testb $0x1, %al
jne 0x7252
jmp 0x7281
movq 0x68(%rsp), %rdi
movq 0x408(%rsp), %rax
movl (%rax), %esi
movq 0x400(%rsp), %rax
movl (%rax), %edx
callq 0x13f50
movq 0x68(%rsp), %rax
movl $0x0, 0x30(%rax)
jmp 0x7dfa
movq 0x68(%rsp), %rdi
movq 0x408(%rsp), %rsi
movq 0x400(%rsp), %rdx
addq $0x8, %rdx
movsd 0x33e3e(%rip), %xmm0    # 0x3b0e0
xorps %xmm1, %xmm1
xorl %r9d, %r9d
movl %r9d, %ecx
movl %r9d, %r8d
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
movl $0x0, 0x8(%rsp)
callq 0x50a0
movq 0x68(%rsp), %rax
movl $0x0, 0x30(%rax)
jmp 0x7dfa
movq 0x410(%rsp), %rax
cmpl $0x3, (%rax)
jne 0x78b1
movq 0x410(%rsp), %rax
movl 0x68(%rax), %eax
movl %eax, 0x374(%rsp)
leaq 0x4ae63(%rip), %rdi     # 0x52160
leaq 0x374(%rsp), %rsi
callq 0x13e60
movq (%rax), %rsi
leaq 0x378(%rsp), %rdi
movl $0x88, %edx
callq 0x3220
movq 0x408(%rsp), %rdi
addq $0x8, %rdi
leaq 0x378(%rsp), %rsi
addq $0x8, %rsi
callq 0x13dd0
movsd %xmm0, 0x368(%rsp)
leaq 0x358(%rsp), %rdi
callq 0x13430
movq 0x408(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x60(%rsp)
leaq 0x378(%rsp), %rdi
addq $0x8, %rdi
movq 0x408(%rsp), %rax
movq 0x8(%rax), %rcx
movq %rcx, 0x308(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x310(%rsp)
movsd 0x308(%rsp), %xmm0
movsd 0x310(%rsp), %xmm1
callq 0x13f90
movsd %xmm0, 0x318(%rsp)
movsd %xmm1, 0x320(%rsp)
leaq 0x318(%rsp), %rdi
callq 0x13fe0
movsd %xmm0, 0x328(%rsp)
movsd %xmm1, 0x330(%rsp)
leaq 0x378(%rsp), %rdi
addq $0x8, %rdi
movq 0x408(%rsp), %rsi
addq $0x8, %rsi
callq 0x12ac0
movsd %xmm0, 0x300(%rsp)
leaq 0x33e1c(%rip), %rdi     # 0x3b220
leaq 0x300(%rsp), %rsi
callq 0x13860
movsd (%rax), %xmm0
leaq 0x328(%rsp), %rdi
callq 0x14070
movq 0x60(%rsp), %rdi
movsd %xmm0, 0x338(%rsp)
movsd %xmm1, 0x340(%rsp)
movsd 0x338(%rsp), %xmm0
movsd 0x340(%rsp), %xmm1
callq 0x12fa0
movsd %xmm0, 0x348(%rsp)
movsd %xmm1, 0x350(%rsp)
movq 0x348(%rsp), %rax
movq %rax, 0x358(%rsp)
movq 0x350(%rsp), %rax
movq %rax, 0x360(%rsp)
leaq 0x4a89f(%rip), %rdi     # 0x51d28
leaq 0x358(%rsp), %rsi
movsd 0x33bdf(%rip), %xmm0    # 0x3b078
callq 0x136b0
testb $0x1, %al
jne 0x75a0
movq 0x408(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x58(%rsp)
leaq 0x378(%rsp), %rdi
addq $0x8, %rdi
movq 0x408(%rsp), %rax
movq 0x8(%rax), %rcx
movq %rcx, 0x2b0(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x2b8(%rsp)
movsd 0x2b0(%rsp), %xmm0
movsd 0x2b8(%rsp), %xmm1
callq 0x13f90
movsd %xmm0, 0x2c0(%rsp)
movsd %xmm1, 0x2c8(%rsp)
leaq 0x2c0(%rsp), %rdi
callq 0x13fe0
movsd %xmm0, 0x2d0(%rsp)
movsd %xmm1, 0x2d8(%rsp)
leaq 0x2d0(%rsp), %rdi
movsd 0x33b75(%rip), %xmm0    # 0x3b0b0
callq 0x14070
movq 0x58(%rsp), %rdi
movsd %xmm0, 0x2e0(%rsp)
movsd %xmm1, 0x2e8(%rsp)
movsd 0x2e0(%rsp), %xmm0
movsd 0x2e8(%rsp), %xmm1
callq 0x12fa0
movsd %xmm0, 0x2f0(%rsp)
movsd %xmm1, 0x2f8(%rsp)
movq 0x2f0(%rsp), %rax
movq %rax, 0x358(%rsp)
movq 0x2f8(%rsp), %rax
movq %rax, 0x360(%rsp)
leaq 0x378(%rsp), %rsi
leaq 0x4a849(%rip), %rdi     # 0x51df8
callq 0x140c0
movq %rax, %rdi
leaq 0x378(%rsp), %rsi
addq $0x8, %rsi
callq 0x141b0
testb $0x1, %al
jne 0x75ce
jmp 0x75f9
leaq 0x378(%rsp), %rsi
leaq 0x4a81b(%rip), %rdi     # 0x51df8
callq 0x140c0
movq (%rax), %rcx
movq %rcx, 0x358(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x360(%rsp)
movsd 0x33a7f(%rip), %xmm0    # 0x3b080
movsd %xmm0, 0x2a8(%rsp)
movq 0x408(%rsp), %rax
movq 0x8(%rax), %rcx
movq %rcx, 0x278(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x280(%rsp)
movq 0x408(%rsp), %rax
movl (%rax), %edx
movsd 0x278(%rsp), %xmm0
movsd 0x280(%rsp), %xmm1
leaq 0x288(%rsp), %rdi
movsd 0x339ba(%rip), %xmm2    # 0x3b010
movl $0x2, %esi
callq 0x3f40
leaq 0x288(%rsp), %rax
movq %rax, 0x2a0(%rsp)
movq 0x2a0(%rsp), %rdi
callq 0x12ed0
movq %rax, 0x270(%rsp)
movq 0x2a0(%rsp), %rdi
callq 0x12f00
movq %rax, 0x268(%rsp)
leaq 0x270(%rsp), %rdi
leaq 0x268(%rsp), %rsi
callq 0x12f30
testb $0x1, %al
jne 0x76c5
leaq 0x288(%rsp), %rdi
callq 0x12de0
jmp 0x7758
leaq 0x270(%rsp), %rdi
callq 0x12f70
movq %rax, 0x260(%rsp)
movq 0x260(%rsp), %rsi
leaq 0x4a7ff(%rip), %rdi     # 0x51ee8
callq 0x13b90
movq %rax, 0x50(%rsp)
jmp 0x76f5
movq 0x50(%rsp), %rsi
leaq 0x2a8(%rsp), %rdi
callq 0x13750
movq %rax, 0x48(%rsp)
jmp 0x770e
movq 0x48(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x2a8(%rsp)
leaq 0x270(%rsp), %rdi
callq 0x12f80
jmp 0x769a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0x288(%rsp), %rdi
callq 0x12de0
jmp 0x7e07
movq 0x408(%rsp), %rsi
leaq 0x4a781(%rip), %rdi     # 0x51ee8
callq 0x13b90
movsd (%rax), %xmm0
movsd %xmm0, 0x248(%rsp)
movsd 0x3395f(%rip), %xmm0    # 0x3b0e0
movsd %xmm0, 0x240(%rsp)
leaq 0x378(%rsp), %rsi
leaq 0x4a7af(%rip), %rdi     # 0x51f48
callq 0x13a50
cmpl $0x2, (%rax)
jle 0x7862
movsd 0x33981(%rip), %xmm0    # 0x3b130
ucomisd 0x248(%rsp), %xmm0
jbe 0x7862
movsd 0x3387a(%rip), %xmm0    # 0x3b040
ucomisd 0x2a8(%rsp), %xmm0
jbe 0x7862
movsd 0x248(%rsp), %xmm1
movsd 0x2a8(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x7862
movsd 0x33943(%rip), %xmm0    # 0x3b138
movsd %xmm0, 0x238(%rsp)
movsd 0x2a8(%rsp), %xmm1
subsd 0x248(%rsp), %xmm1
movsd 0x33920(%rip), %xmm0    # 0x3b138
divsd %xmm0, %xmm1
movsd 0x338bc(%rip), %xmm0    # 0x3b0e0
subsd %xmm1, %xmm0
movsd %xmm0, 0x230(%rsp)
leaq 0x339e8(%rip), %rdi     # 0x3b220
leaq 0x230(%rsp), %rsi
callq 0x13750
movq %rax, %rsi
leaq 0x238(%rsp), %rdi
callq 0x13860
movsd (%rax), %xmm0
movsd %xmm0, 0x240(%rsp)
movq 0x68(%rsp), %rdi
movq 0x408(%rsp), %rsi
movsd 0x240(%rsp), %xmm0
leaq 0x358(%rsp), %rdx
xorps %xmm1, %xmm1
xorl %r9d, %r9d
movl %r9d, %ecx
movl %r9d, %r8d
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
movl $0x0, 0x8(%rsp)
callq 0x50a0
movq 0x68(%rsp), %rax
movl $0x1, 0x30(%rax)
jmp 0x7dfa
movq 0x410(%rsp), %rax
cmpl $0x4, (%rax)
jne 0x7be4
movq 0x410(%rsp), %rax
movl 0x68(%rax), %eax
movl %eax, 0x1a4(%rsp)
leaq 0x4a885(%rip), %rdi     # 0x52160
leaq 0x1a4(%rsp), %rsi
callq 0x13e60
movq (%rax), %rsi
leaq 0x1a8(%rsp), %rdi
movl $0x88, %edx
callq 0x3220
movq 0x408(%rsp), %rdi
addq $0x8, %rdi
leaq 0x1a8(%rsp), %rsi
addq $0x8, %rsi
callq 0x13dd0
movsd %xmm0, 0x198(%rsp)
movsd 0x33755(%rip), %xmm0    # 0x3b080
movsd %xmm0, 0x190(%rsp)
movq 0x408(%rsp), %rax
movq 0x8(%rax), %rcx
movq %rcx, 0x160(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x168(%rsp)
movq 0x408(%rsp), %rax
movl (%rax), %edx
movsd 0x160(%rsp), %xmm0
movsd 0x168(%rsp), %xmm1
leaq 0x170(%rsp), %rdi
movsd 0x33690(%rip), %xmm2    # 0x3b010
movl $0x2, %esi
callq 0x3f40
leaq 0x170(%rsp), %rax
movq %rax, 0x188(%rsp)
movq 0x188(%rsp), %rdi
callq 0x12ed0
movq %rax, 0x158(%rsp)
movq 0x188(%rsp), %rdi
callq 0x12f00
movq %rax, 0x150(%rsp)
leaq 0x158(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x12f30
testb $0x1, %al
jne 0x79ef
leaq 0x170(%rsp), %rdi
callq 0x12de0
jmp 0x7a82
leaq 0x158(%rsp), %rdi
callq 0x12f70
movq %rax, 0x148(%rsp)
movq 0x148(%rsp), %rsi
leaq 0x4a4d5(%rip), %rdi     # 0x51ee8
callq 0x13b90
movq %rax, 0x40(%rsp)
jmp 0x7a1f
movq 0x40(%rsp), %rsi
leaq 0x190(%rsp), %rdi
callq 0x13750
movq %rax, 0x38(%rsp)
jmp 0x7a38
movq 0x38(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x190(%rsp)
leaq 0x158(%rsp), %rdi
callq 0x12f80
jmp 0x79c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x258(%rsp)
movl %eax, 0x254(%rsp)
leaq 0x170(%rsp), %rdi
callq 0x12de0
jmp 0x7e07
movq 0x408(%rsp), %rsi
leaq 0x4a457(%rip), %rdi     # 0x51ee8
callq 0x13b90
movsd (%rax), %xmm0
movsd %xmm0, 0x140(%rsp)
movsd 0x33635(%rip), %xmm0    # 0x3b0e0
movsd %xmm0, 0x138(%rsp)
leaq 0x1a8(%rsp), %rsi
leaq 0x4a485(%rip), %rdi     # 0x51f48
callq 0x13a50
cmpl $0x2, (%rax)
jle 0x7b8c
movsd 0x33657(%rip), %xmm0    # 0x3b130
ucomisd 0x140(%rsp), %xmm0
jbe 0x7b8c
movsd 0x33550(%rip), %xmm0    # 0x3b040
ucomisd 0x190(%rsp), %xmm0
jbe 0x7b8c
movsd 0x140(%rsp), %xmm1
movsd 0x190(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x7b8c
movsd 0x33619(%rip), %xmm0    # 0x3b138
movsd %xmm0, 0x130(%rsp)
movsd 0x190(%rsp), %xmm1
subsd 0x140(%rsp), %xmm1
movsd 0x335f6(%rip), %xmm0    # 0x3b138
divsd %xmm0, %xmm1
movsd 0x33592(%rip), %xmm0    # 0x3b0e0
subsd %xmm1, %xmm0
movsd %xmm0, 0x128(%rsp)
leaq 0x336be(%rip), %rdi     # 0x3b220
leaq 0x128(%rsp), %rsi
callq 0x13750
movq %rax, %rsi
leaq 0x130(%rsp), %rdi
callq 0x13860
movsd (%rax), %xmm0
movsd %xmm0, 0x138(%rsp)
movq 0x68(%rsp), %rdi
movq 0x408(%rsp), %rsi
leaq 0x1a8(%rsp), %rdx
addq $0x8, %rdx
movsd 0x138(%rsp), %xmm0
movsd 0x33572(%rip), %xmm1    # 0x3b128
xorl %r9d, %r9d
movl %r9d, %ecx
movl %r9d, %r8d
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
movl $0x0, 0x8(%rsp)
callq 0x50a0
movq 0x68(%rsp), %rax
movl $0x2, 0x30(%rax)
jmp 0x7dfa
movq 0x410(%rsp), %rax
cmpl $0x6, (%rax)
jne 0x7caf
movq 0x410(%rsp), %rax
movl 0x68(%rax), %eax
movl %eax, 0x9c(%rsp)
leaq 0x4a552(%rip), %rdi     # 0x52160
leaq 0x9c(%rsp), %rsi
callq 0x13e60
movq (%rax), %rsi
leaq 0xa0(%rsp), %rdi
movl $0x88, %edx
callq 0x3220
movq 0x408(%rsp), %rdi
addq $0x8, %rdi
leaq 0xa0(%rsp), %rsi
addq $0x8, %rsi
callq 0x13dd0
movq 0x68(%rsp), %rdi
movsd %xmm0, 0x90(%rsp)
movq 0x408(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
addq $0x8, %rdx
movsd 0x33469(%rip), %xmm0    # 0x3b0e0
movsd 0x334a9(%rip), %xmm1    # 0x3b128
movl $0x1, %ecx
xorl %r9d, %r9d
movl %r9d, %r8d
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
movl $0x0, 0x8(%rsp)
callq 0x50a0
movq 0x68(%rsp), %rax
movl $0x0, 0x30(%rax)
jmp 0x7dfa
movq 0x410(%rsp), %rax
cmpl $0x7, (%rax)
jne 0x7db8
movq 0x410(%rsp), %rax
cmpl $0x0, 0x6c(%rax)
jne 0x7cd9
movl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x7ce6
movl 0x4a049(%rip), %eax     # 0x51d28
subl $0x1, %eax
movl %eax, 0x34(%rsp)
movl 0x34(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0x410(%rsp), %rax
cmpl $0x0, 0x70(%rax)
jne 0x7d0d
movl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x7d1a
movl 0x4a019(%rip), %eax     # 0x51d2c
subl $0x1, %eax
movl %eax, 0x24(%rsp)
movsd 0x28(%rsp), %xmm0
movl 0x24(%rsp), %eax
cvtsi2sd %eax, %xmm1
leaq 0x80(%rsp), %rdi
callq 0x13380
movq 0x408(%rsp), %rdi
addq $0x8, %rdi
leaq 0x80(%rsp), %rsi
callq 0x13dd0
movsd %xmm0, 0x78(%rsp)
movq 0x408(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x334b3(%rip), %rsi     # 0x3b220
callq 0x13750
movq 0x18(%rsp), %rsi
movq 0x68(%rsp), %rdi
movsd (%rax), %xmm0
leaq 0x80(%rsp), %rdx
xorps %xmm1, %xmm1
movl $0x1, %ecx
xorl %r9d, %r9d
movl %r9d, %r8d
movl $0xffffffff, (%rsp)     # imm = 0xFFFFFFFF
movl $0x0, 0x8(%rsp)
callq 0x50a0
movq 0x68(%rsp), %rax
movl $0x0, 0x30(%rax)
jmp 0x7dfa
movq 0x410(%rsp), %rax
cmpl $0x8, (%rax)
jne 0x7ddb
movq 0x68(%rsp), %rdi
movq 0x408(%rsp), %rax
movl (%rax), %esi
callq 0x14210
jmp 0x7dfa
leaq 0x3345e(%rip), %rdi     # 0x3b240
leaq 0x3345d(%rip), %rsi     # 0x3b246
movl $0x2de, %edx            # imm = 0x2DE
leaq 0x33475(%rip), %rcx     # 0x3b26a
callq 0x31a0
movq 0x70(%rsp), %rax
addq $0x418, %rsp            # imm = 0x418
retq
movq 0x258(%rsp), %rdi
callq 0x3440
nopw %cs:(%rax,%rax)