#include "StrategyManager.h"

using namespace MyBot;


void StrategyManager::updateBuildTask()
{
	if (BWAPI::Broodwar->getFrameCount() % 6 != 0) {
		return;
	}


	if (BWAPI::Broodwar->self()->getRace() == BWAPI::Races::Zerg) {

		// 일꾼을 미리 건설 위치에 보내서 더 빨리 건설
		moveWorkerToConstructionPlace();
		
		// 적군 전략에 따른 대응 빌드 타스크
		// 적군이 성큰 / 벙커 / 캐논 러시 전략이면, 방어 성큰 건설 및 드론 동원해서 대응
		/*
		switch (enemyCurrentBuildStrategy) {

		case Terran_Combat_Mechanic_Vulture_FrontRush:
		insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 6));
		break;
		case Terran_Combat_Bionic_Marine_FrontRush:
		insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 8));
		break;
		case Protoss_Combat_Hardcore_Zealot_Rush:
		insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 24));
		insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Hydralisk, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 12));
		break;
		case Zerg_Combat_Front_Ground_Rush:
		insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 24));
		insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Hydralisk, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 12));
		insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Lurker, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 8));
		break;
		case Zerg_Combat_4Drone_Zergling_Rush:
		insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 6));
		insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Sunken_Colony, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1));
		break;
		}
		*/

		// TODO : 적이 빠른 저글링 공격 (4드론, 5드론, 8드론) 일 경우
		if (enemyCurrentBuildStrategy == Zerg_Build_4Drone_Spawing_Pool) {

			// 현재 크립 콜로니가 없으면, 2개 건설
			if (selfPlayer->allUnitCount(BWAPI::UnitTypes::Zerg_Creep_Colony) < 2) {
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Creep_Colony, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 2, true));
			}

			/*
			// 현재 스포닝풀을 건설하고 있지 않으면 모든 빌드큐 삭제하고, 스포닝풀 부터 건설
			if (selfPlayer->allUnitCount(BWAPI::UnitTypes::Zerg_Spawning_Pool) == 0) {
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Spawning_Pool, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));				
			}
			else {

				// 현재 스포닝풀이 건설되어있는데 저글링이 적으면 저글링 건설
				if (selfPlayer->allUnitCount(BWAPI::UnitTypes::Zerg_Zergling) < 12) {
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 12, true));

					// 현재 추가 해처리 건설 중이면 취소
					for (auto & unit : selfPlayer->getUnits()) {
						if (unit == nullptr || unit->exists() == false) continue;
						if (unit->getType() == BWAPI::UnitTypes::Zerg_Hatchery && unit->isCompleted() == false && unit->isConstructing()) {
							unit->cancelConstruction();
						}
					}
				}

			}
			*/
		}

		// 아군 빌드 전략에 따른 빌드 타스크
		// 아군이 뮤탈 전략이면 뮤탈 생산 타스크 추가
		switch (myCurrentBuildStrategy) {

		// 4드론 기본 타스크
		case Zerg_Build_4Drone_Spawing_Pool:
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 12));
			break;

		// 저그전 기본 타스크
		case Zerg_Build_9Drone_SpawningPool_1Hatchery:
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 12));
			break;

		// 프로토스전 기본 타스크
		case Zerg_Build_9Drone_Hatchery:
			break;

		// 테란전 기본 타스크
		case Zerg_Build_12Drone_SpawningPool_2Hatchery:
			break;


		case Zerg_Build_Zergling_Only:
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 36));
			break;

		case Zerg_Build_Zergling_Hydralisk:
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 24));
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Hydralisk, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 24));
			break;
		case Zerg_Build_Zergling_Hydralisk_Defiler:
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 24));
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Hydralisk, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 36));
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Defiler, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 3));
			break;

		case Zerg_Build_Zergling_Hydralisk_Lurker:
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 24));
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Hydralisk, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 24));
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Lurker, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 8));
			break;
		case Zerg_Build_Zergling_Hydralisk_Lurker_Defiler:
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 24));
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Hydralisk, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 36));
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Lurker, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 12));
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Defiler, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 3));
			break;

		case Zerg_Build_Zergling_Lurker_Defiler:
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 48));
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Hydralisk, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 8));
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Lurker, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 24));
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Defiler, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 3));
			break;

		case Zerg_Build_Zergling_Lurker_Mutalisk:
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 24));
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Hydralisk, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 8));
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Lurker, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 8));
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Mutalisk, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 24));
			break;

		case Zerg_Build_Air_Focused:
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 24));
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Mutalisk, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 60));
			insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Scourge, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 24));
			break;
		}

		// 빌드오더가 텅 빈 경우, 저글링 6마리는 최소한 만든다.
		// 정찰을 위해서
		if (BuildManager::Instance().buildQueue.isEmpty()){
			if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Zergling) < 6) {
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 6));
			}
		}

		// 적군 종족 및 유닛에 따른 대응 유닛 빌드 타스크
		if (InformationManager::Instance().enemyRace == BWAPI::Races::Protoss) {
			
			// 적 Protoss 가 다수의 질럿 으로 러시를 하려고하면, Sunken을 더 만든다
			if (true) {
				if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Zealot, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Dragoon, InformationManager::Instance().enemyPlayer) >= 20)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Creep_Colony, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr,
						BWAPI::Positions::None, 6));
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr,
						BWAPI::Positions::None, 40));
				}
				else if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Zealot, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Dragoon, InformationManager::Instance().enemyPlayer) >= 15
					|| InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Gateway, InformationManager::Instance().enemyPlayer) >= 5)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Creep_Colony, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr,
						BWAPI::Positions::None, 5));
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr,
						BWAPI::Positions::None, 30));
				}
				else if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Zealot, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Dragoon, InformationManager::Instance().enemyPlayer) >= 10
					|| InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Gateway, InformationManager::Instance().enemyPlayer) >= 4)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Creep_Colony, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr,
						BWAPI::Positions::None, 4));
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr,
						BWAPI::Positions::None, 20));
				}
				else if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Zealot, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Dragoon, InformationManager::Instance().enemyPlayer) >= 8
					|| InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Gateway, InformationManager::Instance().enemyPlayer) >= 3)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Creep_Colony, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr,
						BWAPI::Positions::None, 3));
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr,
						BWAPI::Positions::None, 16));
				}
				else if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Zealot, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Dragoon, InformationManager::Instance().enemyPlayer) >= 4
					|| InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Gateway, InformationManager::Instance().enemyPlayer) >= 2)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Creep_Colony, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr,
						BWAPI::Positions::None, 2));
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr,
						BWAPI::Positions::None, 8));
				}
			}

			// 적 Protoss 가 HighTemplar 를 만들면, Queen 으로 견제한다
			if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Templar_Archives, InformationManager::Instance().enemyPlayer) > 0
				|| InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_High_Templar, InformationManager::Instance().enemyPlayer) > 0)
			{
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Queens_Nest, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Queen, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 6));
			}

			// 적 Protoss 가 Corsair,  를 만들면, 히드라로 오버로드를 보호하고, 스커지로 요격한다
			if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Corsair, InformationManager::Instance().enemyPlayer) >= 1
				|| InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Carrier, InformationManager::Instance().enemyPlayer) >= 1
				|| InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Fleet_Beacon, InformationManager::Instance().enemyPlayer) >= 1
				|| InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Stargate, InformationManager::Instance().enemyPlayer) >= 1)
			{
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Hydralisk_Den, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Hydralisk, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 6));

				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Spire, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Scourge, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 6));
			}

			// 적 Protoss 가 Protoss_Shuttle 나 Protoss_Observer 를 만들면, 스커지로 요격한다
			if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Shuttle, InformationManager::Instance().enemyPlayer) > 0
				|| InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Protoss_Observer, InformationManager::Instance().enemyPlayer) > 0)
			{
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Spire, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1));
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Scourge, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 6));
			}

		}
		else if (InformationManager::Instance().enemyRace == BWAPI::Races::Terran) {

			// 적 Terran 이 다수의 마린 메딕 혹은 벌처를 만들면, 성큰을 더 만들어 방어한다
			if (true) {

				if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Marine, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Medic, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Firebat, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Siege_Tank_Tank_Mode, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Vulture, InformationManager::Instance().enemyPlayer) >= 20)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Creep_Colony, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr,
						BWAPI::Positions::None, 5));
				}
				else if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Marine, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Medic, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Firebat, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Siege_Tank_Tank_Mode, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Vulture, InformationManager::Instance().enemyPlayer) >= 12)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Creep_Colony, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr,
						BWAPI::Positions::None, 4));
				}
				else if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Marine, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Medic, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Firebat, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Siege_Tank_Tank_Mode, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Vulture, InformationManager::Instance().enemyPlayer) >= 6)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Creep_Colony, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr,
						BWAPI::Positions::None, 3));
				}
				else if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Marine, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Medic, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Firebat, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Siege_Tank_Tank_Mode, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Vulture, InformationManager::Instance().enemyPlayer) >= 3)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Creep_Colony, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr,
						BWAPI::Positions::None, 2));
				}
			}

			// 적 Terran 이 SiegeTank 를 만들면, Queen 으로 견제한다
			if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Siege_Tank_Siege_Mode, InformationManager::Instance().enemyPlayer) > 0
				|| InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Siege_Tank_Tank_Mode, InformationManager::Instance().enemyPlayer) > 0)
			{
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Queens_Nest, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Queen, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 6));
			}

			// 적 Terran 이 Dropship 이나 Science_Vessel을 만들면, Scourge 로 견제한다
			if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Dropship, InformationManager::Instance().enemyPlayer) > 0
				|| InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Science_Vessel, InformationManager::Instance().enemyPlayer) > 0)
			{
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Spire, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Scourge, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 6));
			}

			// 적 Terran 이 Wraith 를 만들면, Hydralisk 로 오버로드를 보호한다
			if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Wraith, InformationManager::Instance().enemyPlayer) >= 1
				|| InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Terran_Starport, InformationManager::Instance().enemyPlayer) >= 1)
			{
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Hydralisk_Den, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Hydralisk, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 6));
			}
		}
		else if (InformationManager::Instance().enemyRace == BWAPI::Races::Zerg) {

			// 적 Zerg 가 다수의 저글링 혹은 히드라를 만들면, 성큰을 더 만들어 방어한다
			if (true) {
				if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Zerg_Zergling, InformationManager::Instance().enemyPlayer) / 2
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Zerg_Hydralisk, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Zerg_Ultralisk, InformationManager::Instance().enemyPlayer) * 5 >= 30)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Creep_Colony, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr,
						BWAPI::Positions::None, 5));

				}
				else if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Zerg_Zergling, InformationManager::Instance().enemyPlayer) / 2
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Zerg_Hydralisk, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Zerg_Ultralisk, InformationManager::Instance().enemyPlayer) * 5 >= 20)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Creep_Colony, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr,
						BWAPI::Positions::None, 4));

				}
				else if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Zerg_Zergling, InformationManager::Instance().enemyPlayer) / 2
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Zerg_Hydralisk, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Zerg_Ultralisk, InformationManager::Instance().enemyPlayer) * 5 >= 10)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Creep_Colony, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr,
						BWAPI::Positions::None, 3));

				}
				else if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Zerg_Zergling, InformationManager::Instance().enemyPlayer) / 2
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Zerg_Hydralisk, InformationManager::Instance().enemyPlayer)
					+ InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Zerg_Ultralisk, InformationManager::Instance().enemyPlayer) * 5 >= 6)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Creep_Colony, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr,
						BWAPI::Positions::None, 2));

				}
			}

			// 적 Zerg 가 Mutalisk 나 Scourge 를 만들면, 히드라로 오버로드를 보호한다
			if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Zerg_Scourge, InformationManager::Instance().enemyPlayer) >= 1)
			{
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Hydralisk_Den, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Hydralisk, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 6));
			}

			// 적 Zerg 가 Lurker 를 다수 만들면, 퀸으로 견제한다
			if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Zerg_Lurker, InformationManager::Instance().enemyPlayer) >= 4)
			{
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Queens_Nest, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Queen, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 4));
			}

			// 적 Zerg 가 Defiler 를 만들면, 퀸으로 견제한다
			if (InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Zerg_Defiler, InformationManager::Instance().enemyPlayer) > 0
				|| InformationManager::Instance().getNumUnits(BWAPI::UnitTypes::Zerg_Defiler_Mound, InformationManager::Instance().enemyPlayer) > 0)
			{
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Queens_Nest, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
				insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Queen, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 4));
			}
		}

		// 아군 상황에 따른 유닛 빌드 타스크

		if (true) {
			
			bool isDefenseOK = isDefenseEnough();

			if (isDefenseOK == false) {

				// 점령한 지역의 해처리/레어/하이브 주위에 아직 Sunken 가 건설되지 않은 것이 있으면, 최소한 1개는 무조건 건설한다
				if (BuildManager::Instance().buildQueue.getItemCount(BWAPI::UnitTypes::Zerg_Creep_Colony) == 0
					&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UnitTypes::Zerg_Sunken_Colony) == 0
					&& ConstructionManager::Instance().getConstructionQueueItemCount(BWAPI::UnitTypes::Zerg_Creep_Colony) == 0)
				{
					for (BWTA::BaseLocation * baseLocation : InformationManager::Instance().getOccupiedBaseLocations(InformationManager::Instance().selfPlayer)) {

						// 게임 초기에는 아군 mainBase 는 제외. 앞마당에만 건설
						// TODO : 나중에는 
						if (baseLocation == myMainBaseLocation && BWAPI::Broodwar->getFrameCount() < 24 * 60 * 10) continue;

						// ResourceDepot 이 존재하면
						bool isResourceDepotCompleted = false;
						for (auto & unit : BWAPI::Broodwar->self()->getUnits())
						{
							if (unit == nullptr || unit->exists() == false) continue;
							if (unit->getType().isResourceDepot() && unit->isCompleted() && unit->getDistance(baseLocation->getPosition()) < 10 * TILE_SIZE)
							{
								isResourceDepotCompleted = true;
							}
						}

						if (isResourceDepotCompleted) {

							int sunkenCountInThisRegion = 0;

							for (auto & unit : BWAPI::Broodwar->self()->getUnits()) {
								if (unit == nullptr || unit->exists() == false) continue;
								if (unit->getType() == BWAPI::UnitTypes::Zerg_Creep_Colony || unit->getType() == BWAPI::UnitTypes::Zerg_Sunken_Colony) {
									if (BWTA::getRegion(unit->getTilePosition()) == BWTA::getRegion(baseLocation->getTilePosition())) {
										sunkenCountInThisRegion++;
									}
								}
							}

							if (sunkenCountInThisRegion == 0) {
								insertTask(StrategicTask(TaskGoalType::Build_Unit_Another, BWAPI::UnitTypes::Zerg_Creep_Colony, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, baseLocation->getPosition(), 1, true));
							}
						}
					}
				}

				// 저글링이 부족하면, 적 유닛 숫자만큼 만든다
				int myZerglingCount = BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Zergling);
				myZerglingCount += BuildManager::Instance().buildQueue.getItemCount(BWAPI::UnitTypes::Zerg_Zergling) * 2;

				if (InformationManager::Instance().getUnitData(enemyPlayer).getNumUnits(BWAPI::UnitTypes::Protoss_Zealot) > myZerglingCount) {
					insertTask(StrategicTask(TaskGoalType::Build_Unit_Another, BWAPI::UnitTypes::Zerg_Zergling, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
				}
			}
			// 방어가 충분히 갖춰져있으면
			else {

				// 미네랄 일꾼이 충분히 많이 있으면 가스 건설 검토
				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Drone) >= 9)
				{
					// 점령한 지역의 해처리/레어/하이브 주위에 아직 Extractor 가 건설되지 않은 Geyser 가 있으면 
					bool isToBuildAnotherRefinery = false;

					int currentExtractorCount = BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Extractor)
						+ BuildManager::Instance().buildQueue.getItemCount(BWAPI::UnitTypes::Zerg_Extractor)
						+ ConstructionManager::Instance().getConstructionQueueItemCount(BWAPI::UnitTypes::Zerg_Extractor);

					int currentPossibleExtractorCount = 0;
					for (BWTA::BaseLocation * baseLocation : InformationManager::Instance().getOccupiedBaseLocations(InformationManager::Instance().selfPlayer)) {
						for (auto & geyser : baseLocation->getGeysers()) {
							currentPossibleExtractorCount++;
						}
					}

					if (currentPossibleExtractorCount > currentExtractorCount
						&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UnitTypes::Zerg_Extractor) == 0
						&& ConstructionManager::Instance().getConstructionQueueItemCount(BWAPI::UnitTypes::Zerg_Extractor) == 0)
					{
						// 가스 건물이 하나도 없는 상황 : 프로토스 하드코어 질럿 러시 / 저그 저글링 러시인 상황
						// 적이 가스를 최초 건설하거나 고급유닛을 생산하기 시작하면 아군도 이에 맞춰서 건설
						// 적이 계속 하드코어 질럿 러시 / 저글링 러시만 하려고하는데, 아군 방어가 잘 갖춰져있고 일꾼과 미네랄이 충분한 상황에서는 가스 건설
						if (currentExtractorCount == 0) {

							int enemyRefineryCount = InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(InformationManager::Instance().getRefineryBuildingType(enemyRace));
							int enemyAdvancedUnitCount =
								InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Protoss_Cybernetics_Core)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Protoss_Dragoon)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Protoss_Corsair)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Protoss_High_Templar)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Protoss_Dark_Templar)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Academy)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Factory)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Medic)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Firebat)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Vulture)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Siege_Tank_Tank_Mode)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Siege_Tank_Siege_Mode)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Wraith)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Starport)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Lair)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Hydralisk_Den)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Spire)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Mutalisk)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Scourge)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Hydralisk);

							if (enemyRefineryCount > 0 || enemyAdvancedUnitCount > 0 || BWAPI::Broodwar->self()->minerals() > 400 ) {
								isToBuildAnotherRefinery = true;
							}
						}
						// 가스 건물이 1개 이상 이미 있는데,  앞마당이나 다른 멀티 지역에 가스가 건설 안되어있는 경우
						else {

							// 스파이어 건설 시작 or 러커 업그레이드 완료 후에는 가스 무조건 건설
							if (BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Spire) >= 1
								|| BWAPI::Broodwar->self()->hasResearched(BWAPI::TechTypes::Lurker_Aspect) == true) 
							{
								isToBuildAnotherRefinery = true;
							}
						}
					}

					if (isToBuildAnotherRefinery) 
					{
						// TODO : Extractor 위치를 딱 찝어서 해야함. 해처리와 다른데 Extractor 건설하려고함
						BWAPI::TilePosition closestGeyser = BWAPI::TilePositions::None;
						double minGeyserDistanceFromHome = std::numeric_limits<double>::max();

						for (BWTA::BaseLocation * baseLocation : InformationManager::Instance().getOccupiedBaseLocations(InformationManager::Instance().selfPlayer)) {
							for (auto & geyser : baseLocation->getGeysers()) {

								BWAPI::Position geyserPos = geyser->getInitialPosition();
								BWAPI::TilePosition geyserTilePos = geyser->getInitialTilePosition();

								// geyser 근처에 ResourceDepot 이 존재하면
								bool isResourceDepotCompleted = false;
								for (auto & unit : BWAPI::Broodwar->self()->getUnits())
								{
									if (unit == nullptr || unit->exists() == false) continue;
									if (unit->getType().isResourceDepot() && unit->isCompleted() && unit->getDistance(geyserPos) < 300)
									{
										isResourceDepotCompleted = true;
									}
								}

								if (isResourceDepotCompleted)
								{
									// geyser 위치에 Refinery 가 건설되어있지 않으면
									bool isAlreadyRefineryBuilt = false;
									for (auto & uot : BWAPI::Broodwar->getUnitsOnTile(geyserTilePos)) {
										if (uot->getType().isRefinery()) {
											isAlreadyRefineryBuilt = true;
											break;
										}
									}

									if (isAlreadyRefineryBuilt == false) {
										insertTask(StrategicTask(TaskGoalType::Build_Unit_Another, BWAPI::UnitTypes::Zerg_Extractor, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Position(geyserTilePos), 1, true));
									}
								}
							}
						}
					}
				}
			}

			// 돈이 조금만 여유 있으면 크립 콜로니는 성큰 콜로니로 바꾼다
			if (BWAPI::Broodwar->self()->minerals() > (BWAPI::UnitTypes::Zerg_Sunken_Colony).mineralPrice())  {

				for (auto & unit : BWAPI::Broodwar->self()->getUnits()) {
					if (unit == nullptr || unit->exists() == false) continue;
					if (unit->getType() == BWAPI::UnitTypes::Zerg_Creep_Colony && unit->isMorphing() == false) {
						unit->morph(BWAPI::UnitTypes::Zerg_Sunken_Colony);
					}
				}
			}

			// 어느 단계에서든지, 돈이 넘쳐나는데, larva가 절대적으로 부족하거나, 가스가 부족하면, 최우선적으로, 즉각적으로 해처리 추가 증설. 저글링 등 빨리 만들어서 적 공격해서 멀티 확장 해야함
			if (BWAPI::Broodwar->self()->minerals() > 500)  {

				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Larva) == 0 || BWAPI::Broodwar->self()->gas() < 100) {

					if (BuildManager::Instance().buildQueue.getItemCount(BWAPI::UnitTypes::Zerg_Hatchery) == 0
						&& ConstructionManager::Instance().getConstructionQueueItemCount(BWAPI::UnitTypes::Zerg_Hatchery) == 0)
					{
						insertTask(StrategicTask(TaskGoalType::Build_Unit_Another, BWAPI::UnitTypes::Zerg_Hatchery, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
					}

				}
			}


			// 미네랄만 넘쳐나고 가스는 부족할 때 자동 유닛 생산 : 저글링
			if (BWAPI::Broodwar->self()->supplyUsed() < 390
				&& BWAPI::Broodwar->self()->minerals() > 500
				&& BWAPI::Broodwar->self()->gas() < 25)
			{
				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Spawning_Pool) == 1)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_Another, BWAPI::UnitTypes::Zerg_Zergling));
				}
			}

			// 미네랄과 가스가 넘쳐날때 자동 유닛 생산
			if (BWAPI::Broodwar->self()->supplyUsed() < 390
				&& BWAPI::Broodwar->self()->minerals() > 300
				&& BWAPI::Broodwar->self()->gas() > 300)  
			{

				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Spawning_Pool) == 1
					&& BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Zergling) <= 24)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_Another, BWAPI::UnitTypes::Zerg_Zergling));
				}

				// 히드라는 주력 공격 유닛
				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk_Den) >= 1
					&& BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk) <= 80)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_Another, BWAPI::UnitTypes::Zerg_Hydralisk));
				}

				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk_Den) >= 1
					&& BWAPI::Broodwar->self()->hasResearched(BWAPI::TechTypes::Lurker_Aspect) == true
					&& BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk) > 0
					&& BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Lurker) <= 12) {
					insertTask(StrategicTask(TaskGoalType::Build_Unit_Another, BWAPI::UnitTypes::Zerg_Lurker));
				}

				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Spire) >= 1
					&& BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Mutalisk) <= 12)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_Another, BWAPI::UnitTypes::Zerg_Mutalisk));
				}

				if (isToMakeQueen) {
					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Queens_Nest) >= 1
						&& BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Queen) <= 6)
					{
						insertTask(StrategicTask(TaskGoalType::Build_Unit_Another, BWAPI::UnitTypes::Zerg_Queen));
					}
				}

				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Defiler_Mound) >= 1
					&& BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Defiler) <= 4)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_Another, BWAPI::UnitTypes::Zerg_Defiler));
				}
				
				if (isToMakeDevourer) {
					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Greater_Spire) >= 1
						&& BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Mutalisk) >= 36
						&& BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Devourer) <= 4)
					{
						insertTask(StrategicTask(TaskGoalType::Build_Unit_Another, BWAPI::UnitTypes::Zerg_Devourer));
					}
				}

				if (isToMakeGuardian) {
					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Greater_Spire) >= 1
						&& BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Mutalisk) >= 16
						&& BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Guardian) <= 12) {
						insertTask(StrategicTask(TaskGoalType::Build_Unit_Another, BWAPI::UnitTypes::Zerg_Guardian));
					}
				}

				if (isToMakeUltralisk) {
					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Ultralisk_Cavern) == 1
						&& BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Ultralisk) <= 4) {
						insertTask(StrategicTask(TaskGoalType::Build_Unit_Another, BWAPI::UnitTypes::Zerg_Ultralisk));
					}
				}
			}

			// 건물 건설 및 테크트리 업

			// 스포닝풀은 기본
			if (BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Spawning_Pool) == 0
				&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UnitTypes::Zerg_Spawning_Pool) == 0
				&& ConstructionManager::Instance().getConstructionQueueItemCount(BWAPI::UnitTypes::Zerg_Spawning_Pool) == 0)
			{
				// 해처리/레어/하이브가 있으면
				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hatchery) >= 1
					|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Lair) >= 1
					|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hive) >= 1)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Spawning_Pool, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
				}
			}

			// 히드라리스크 덴을 언제 만들것인가
			if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Spawning_Pool) >= 1) {

				if (BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk_Den) == 0
					&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UnitTypes::Zerg_Hydralisk_Den) == 0
					&& ConstructionManager::Instance().getConstructionQueueItemCount(BWAPI::UnitTypes::Zerg_Hydralisk_Den) == 0)
				{
					// 해처리/레어/하이브가 있으면
					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hatchery) >= 1
						|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Lair) >= 1
						|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hive) >= 1)
					{
						// 적군의 종족에 따라, 적군 전략에 따라, 아군 전략에 따라, 스파이어를 먼저 갈지, 히드라를 먼저 갈지 결정						
						// InitialBuildOrder 에서 뮤탈로 가지않는 이상, 기본적으로 히드라 체제로 간다

						// 프로토스 : 하드코어 질럿 러시일 때는 먼저 히드라 / 러커
						//           질럿 드라군 러시일 때는 히드라 러커로 방어 갖춘 후 뮤탈
						//           드라군 리버 러시일 때는 히드라 러커로 방어 갖추고 퀸 뽑은 후 뮤탈
						//           포톤 캐리어 러시일 때는 땡 히드라
						// 테란 : 바이오닉일 때는 러커 만들어야 함. 먼저 레어 그다음에 히드라. 
						//        메카닉일 때는 히드라로 먼저 벌처 방어. 후 러커로 방어
						//        레이쓰 체제일 때도 히드라로 방어
						// 저그 : 적이 저글링 러시만 할 때는 천천히 방어 갖춘 후
						//        적이 바로 뮤탈 갈때는 먼저 뮤탈
						//        적이 바로 히드라 갈때는 같이 히드라/러커로 방어 후 뮤탈.

						bool isToMakeHydraliskDen = false;

						if (enemyRace == BWAPI::Races::Protoss) {
							isToMakeHydraliskDen = true;
						}
						else if (enemyRace == BWAPI::Races::Terran) {
							isToMakeHydraliskDen = true;
						}
						else if (enemyRace == BWAPI::Races::Zerg) {
							int enemyHydraliskCount = InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Hydralisk)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Lurker)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Lurker_Egg)
								+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Hydralisk_Den);

							if (enemyHydraliskCount > 0) {
								isToMakeHydraliskDen = true;
							}
						}

						// 뮤탈이 충분히 생산되었으면, 뮤탈 체계로 가더라도 히드라는 생산 할 수 있도록 준비
						if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Mutalisk) >= 12) {
							isToMakeHydraliskDen = true;
						}

						if (isToMakeHydraliskDen) {

							// 히드라는 안만들고 러커 만 만들 계획이라면, 먼저 레어 업그레이드를 한 후, 레어 건설이 50% 정도 되었을 때 히드라리스크덴을 건설한다
							// 프로토스 : 하드코어 질럿 러시
							// 테란 : 바이오닉
							bool isToMakeLurkerOnly = false;
							if (myCurrentBuildStrategy == BuildStrategy::Zerg_Build_Zergling_Lurker_Defiler
								|| myCurrentBuildStrategy == BuildStrategy::Zerg_Build_Zergling_Lurker_Mutalisk
							) {
								isToMakeLurkerOnly = true;
							}

							if (isToMakeLurkerOnly) {
								if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Lair) == 0
									&& BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hive) == 0) 
								{
									if (BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Lair) > 0) {
										for (auto & hatchery : BWAPI::Broodwar->self()->getUnits()) {
											if (hatchery != nullptr 
												&& hatchery->exists() 
												&& hatchery->getType() == BWAPI::UnitTypes::Zerg_Lair 
												&& hatchery->isMorphing()) 
											{
												if (hatchery->getRemainingBuildTime() > BWAPI::UnitTypes::Zerg_Lair.buildTime() * 0.5) {
													insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Hydralisk_Den, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
												}
											}
										}

									}
								}
							}
							else {
								insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Hydralisk_Den, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
							}
						}

					}
				}

			}

			// 해처리 단계에서 레어 테크트리 업 
			if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hatchery) >= 1
				&& BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Spawning_Pool) >= 1) {

				if (BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Lair) == 0
					&& BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Hive) == 0
					&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UnitTypes::Zerg_Lair) == 0) {

					int targetUnitCount = BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Lair)
						+ BuildManager::Instance().buildQueue.getItemCount(BWAPI::UnitTypes::Zerg_Lair);

					BWAPI::UnitType targetUnitType = BWAPI::UnitTypes::Zerg_Lair;
					for (auto & unit : BWAPI::Broodwar->self()->getUnits()) {
						if (unit == nullptr || unit->exists() == false) continue;
						if (unit->getType() == targetUnitType && unit->isMorphing() == true) {
							targetUnitCount++;
						}
					}

					//std::cout << BWAPI::Broodwar->getFrameCount() << " Zerg_Lair Count " << targetUnitCount << std::endl;

					if (targetUnitCount == 0) {

						// 방어가 충분히 갖춰져있으면 레어 테크트리 업
						if (isDefenseOK)
						{
							insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Lair, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
							//std::cout << BWAPI::Broodwar->getFrameCount() << " insertTask Zerg_Lair" << targetUnitCount << std::endl;
						}

					}
				}
			}

			// 레어/하이브가 있을 때
			if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Lair) >= 1
				|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hive) >= 1)
			{
				if (BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Spire) == 0
					&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UnitTypes::Zerg_Spire) == 0
					&& ConstructionManager::Instance().getConstructionQueueItemCount(BWAPI::UnitTypes::Zerg_Spire) == 0)
				{
					if (isDefenseOK) {
						// 무조건 빨리 스파이어 건설 ? 
						// 프로토스 하드코어 질럿 러시 / 저그 저글링 러시일 때 뮤탈 체계로 가다가 병력 공백으로 인해 밀려버릴 수 있다. 기본적으로 히드라 러커로 방어 갖춘 후 뮤탈 체계로 가야함
						// 적 프로토스가 커세어 / 리버 를 만들면  같이 스파이어를 만들어야 함
						// 적 테란이 레이쓰 / 드랍쉽 을 만들면  같이 스파이어를 만들어야 함
						// 적 저그가 스파이어를 만들기 시작하면 같이 스파이어를 만들어야 함

						int enemyFlyerCount = InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Protoss_Corsair)
							+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Protoss_Shuttle)
							+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Protoss_Arbiter)
							+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Protoss_Carrier)
							+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Wraith)
							+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Dropship)
							+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Science_Vessel)
							+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Mutalisk)
							+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Scourge)
							+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Guardian);
						int enemyFlyerBuildingCount = InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Protoss_Stargate)
							+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Protoss_Robotics_Facility)
							+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Protoss_Robotics_Support_Bay)
							+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Protoss_Fleet_Beacon)
							+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Starport)
							+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Science_Facility)
							+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Spire)
							+ InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Greater_Spire);

						if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk) >= 12
							|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Lurker) >= 4
							|| enemyFlyerCount > 0
							|| enemyFlyerBuildingCount > 0)
						{
							insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Lair, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
							insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Spire, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
						}
					}
				}
			}

			// 레어 단계에서 
			if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Lair) >= 1)
			{
				// 뮤탈 혹은 히드라가 충분히 뽑혔으면 하이브로 진입하기 위한 준비로서 퀸스네스트 건설
				// 적 프로토스 하이템플러 를 브루들링으로 죽이기 위해 건설
				// 적 테란 시즈탱크, 고스트 를 브루들링으로 죽이기 위해 건설
				// 적 저그 디파일러 를 브루들링으로 죽이기 위해 건설
				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Mutalisk) >= 24
					|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk) >= 24
					|| InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Protoss_Templar_Archives) > 0
					|| InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Protoss_High_Templar) > 0
					|| InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Machine_Shop) > 0
					|| InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Siege_Tank_Siege_Mode) > 0
					|| InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Siege_Tank_Tank_Mode) > 0
					|| InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Nuclear_Silo) > 0
					|| InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Covert_Ops) > 0
					|| InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Terran_Ghost) > 0
					|| InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Defiler) > 0
					|| InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Defiler_Mound) > 0)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Queens_Nest, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
				}
			}

			// 레어 단계에서 하이브 테크트리 업 시기 결정 : 
			if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Lair) >= 1
				&& BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Queens_Nest) >= 1) {
				if (BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Hive) == 0
					&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UnitTypes::Zerg_Hive) == 0)
				{
					int targetUnitCount = 0;
					BWAPI::UnitType targetUnitType = BWAPI::UnitTypes::Zerg_Hive;
					for (auto & unit : BWAPI::Broodwar->self()->getUnits()) {
						if (unit == nullptr || unit->exists() == false) continue;
						if (unit->getType() == targetUnitType && unit->isMorphing() == true) {
							targetUnitCount++;
						}
					}

					if (targetUnitCount == 0) {

						// 방어가 충분히 갖춰져있는 것은 기본 
						if (isDefenseOK) {
							
							// 하이브 테크트리 업 
							// 공격유닛이 충분히 생산되었거나, 
							// 적 프로토스에게 드라군, 커세어, 캐리어 다수 있어서 디파일러가 필요할 경우
							// 적 테란에게 시즈탱크, 마린메딕, 사이언스베슬 다수 있어서 디파일러가 필요할 경우
							// 적 저그에게 뮤탈리스크가 다수 있어서 디바우어러가 필요할 경우
							if (BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk) >= 12
								|| BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Lurker) >= 6
								|| BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Mutalisk) >= 12
								|| InformationManager::Instance().getUnitData(enemyPlayer).getNumUnits(BWAPI::UnitTypes::Protoss_Dragoon) > 10
								|| InformationManager::Instance().getUnitData(enemyPlayer).getNumUnits(BWAPI::UnitTypes::Protoss_Corsair) > 6
								|| InformationManager::Instance().getUnitData(enemyPlayer).getNumUnits(BWAPI::UnitTypes::Protoss_Carrier) > 4
								|| InformationManager::Instance().getUnitData(enemyPlayer).getNumUnits(BWAPI::UnitTypes::Terran_Marine) > 20
								|| InformationManager::Instance().getUnitData(enemyPlayer).getNumUnits(BWAPI::UnitTypes::Terran_Science_Vessel) > 4
								|| InformationManager::Instance().getUnitData(enemyPlayer).getNumUnits(BWAPI::UnitTypes::Terran_Battlecruiser) > 4
								|| InformationManager::Instance().getUnitData(enemyPlayer).getNumUnits(BWAPI::UnitTypes::Zerg_Mutalisk) > 12
								|| InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Defiler) > 0
								|| InformationManager::Instance().getUnitData(enemyPlayer).getNumCreatedUnits(BWAPI::UnitTypes::Zerg_Defiler_Mound) > 0
							){
								insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Hive, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
							}
						}
					}
				}
			}

			// 하이브에서 건물 건설
			if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hive) >= 1) {

				// 디파일러 마운드는 필수
				if (BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Defiler_Mound) == 0
					&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UnitTypes::Zerg_Defiler_Mound) == 0
					&& ConstructionManager::Instance().getConstructionQueueItemCount(BWAPI::UnitTypes::Zerg_Defiler_Mound) == 0)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Defiler_Mound, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
				}

				// 그레이터 스파이어 : 뮤탈이 충분히 많이 생산되어있거나, 가디언을 생산해야할때
				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Mutalisk) >= 12
					|| isToMakeGuardian == true) {

					if (BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Greater_Spire) == 0
						&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UnitTypes::Zerg_Greater_Spire) == 0) 
					{
						int targetUnitCount = 0;
						BWAPI::UnitType targetUnitType = BWAPI::UnitTypes::Zerg_Greater_Spire;
						for (auto & unit : BWAPI::Broodwar->self()->getUnits()) {
							if (unit == nullptr || unit->exists() == false) continue;
							if (unit->getType() == targetUnitType && unit->isMorphing() == true) {
								targetUnitCount++;
							}
						}

						if (targetUnitCount == 0) {
							insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Greater_Spire, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
						}
					}
				}

				// 울트라 리스크 캐번 : 확장기지가 충분히 많이 있거나, 울트라리스크를 생산해야할때
				if (InformationManager::Instance().getOccupiedRegions(selfPlayer).size() >= 3
					|| isToMakeUltralisk == true)
				{
					if (BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Ultralisk_Cavern) == 0
						&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UnitTypes::Zerg_Ultralisk_Cavern) == 0
						&& ConstructionManager::Instance().getConstructionQueueItemCount(BWAPI::UnitTypes::Zerg_Ultralisk_Cavern) == 0)
					{
						if (isDefenseOK) {
							insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Ultralisk_Cavern, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
						}
					}
				}
			}

			// 업그레이드 관련 타스크 : 전략적 필요성이 아니더라도 최소한 일정 수준에 도달하면 무조건 업그레이드

			/*
			// 버로우 -> 저글링 정찰. 생존성 향상
			if (BWAPI::Broodwar->self()->hasResearched(BWAPI::TechTypes::Burrowing) == false
				&& BWAPI::Broodwar->self()->isResearching(BWAPI::TechTypes::Burrowing) == false) {

				// 최소한 레어는 만들고 나서. 버로우보다 레어 업그레이드가 더 급하다
				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Lair) >= 1
					&& BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hatchery) >= 1) {

					// 다수 유닛 생산 후 / 러커 4마리 완성 후 / 뮤탈 8마리 완성 후 
					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Drone) >= 24
						|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Zergling) >= 24
						|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk) >= 12
						|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Lurker) >= 4
						|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Mutalisk) >= 8)
					{
						insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Hatchery, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
						insertTask(StrategicTask(TaskGoalType::Build_Tech, BWAPI::UnitTypes::None, BWAPI::TechTypes::Burrowing, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
					}
				}
			}
			*/

			// 저글링 업그레이드
			if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Spawning_Pool) >= 1) {

				// 저글링 이동속도 업
				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Zergling) >= 24) {
					if (BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Metabolic_Boost) == 0
						&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Metabolic_Boost) == false)
					{
						if (enemyCurrentBuildStrategy == BuildStrategy::Zerg_Build_4Drone_Spawing_Pool
							|| enemyCurrentBuildStrategy == BuildStrategy::Zerg_Build_Zergling_Only
							|| enemyCurrentBuildStrategy == BuildStrategy::Protoss_Build_Hardcore_Zealot) 
						{
							insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Metabolic_Boost, nullptr, BWAPI::Positions::None, 1, true));
						}
						else {
							if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Lair) >= 1) {
								insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Metabolic_Boost, nullptr, BWAPI::Positions::None, 1, true));
							}
						}
					}
				}

				// 저글링 공격 속도 업 : 하이브 단계에서 필수
				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hive) >= 1
					&& BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Adrenal_Glands) == 0
					&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Adrenal_Glands) == false)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Adrenal_Glands, nullptr, BWAPI::Positions::None, 1));
				}
			}

			// 히드라 업그레이드
			if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk_Den) >= 1) {

				if (BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Grooved_Spines) == 0
					&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Grooved_Spines) == false)
				{
					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk) >= 6) {
						// 히드라 공격 사정거리 업
						insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Grooved_Spines, nullptr, BWAPI::Positions::None, 1, true));
					}
				}

				if (BWAPI::Broodwar->self()->hasResearched(BWAPI::TechTypes::Lurker_Aspect) == false
					&& BWAPI::Broodwar->self()->isResearching(BWAPI::TechTypes::Lurker_Aspect) == false)
				{
					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Lair) > 0) {
						// 럴커
						insertTask(StrategicTask(TaskGoalType::Build_Tech, BWAPI::UnitTypes::None, BWAPI::TechTypes::Lurker_Aspect, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
					}
				}

				if (BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Muscular_Augments) == 0
					&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Muscular_Augments) == false)
				{

					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk) >= 10) {
						// 히드라 이동속도 업
						insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Muscular_Augments, nullptr, BWAPI::Positions::None, 1, true));
					}
				}
			}

			// 오버로드 업그레이드
			if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Lair) >= 1
				|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hive) >= 1) {

				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Overlord) >= 8) {

					// 오버로드 속도 증가
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Lair, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
					insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Pneumatized_Carapace, nullptr, BWAPI::Positions::None, 1));

					/*
					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Overlord) >= 15) {

						// 오버로드 시야 증가
						insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Antennae, nullptr, BWAPI::Positions::None, 1));

						if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Overlord) >= 20) {

							// 오버로드 운반가능
							insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Ventral_Sacs, nullptr, BWAPI::Positions::None, 1));
						}
					}
					*/
				}

			}

			/*
			// 뮤탈리스크 업그레이드
			if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Mutalisk) >= 8) {

				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Spire) > 0) {

					// 스파이어 -> 공중유닛 업그레이드 : 공격력부터
					if (BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Flyer_Attacks) == 0
						&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Zerg_Flyer_Attacks) == false
						&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UpgradeTypes::Zerg_Flyer_Attacks) == 0)
					{
						insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Zerg_Flyer_Attacks, nullptr, BWAPI::Positions::None, 1));
					}

					// 스파이어 -> 공중유닛 업그레이드 : 방어력은 그다음
					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Mutalisk) >= 12
						&& BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Flyer_Carapace) == 0
						&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Zerg_Flyer_Carapace) == false
						&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UpgradeTypes::Zerg_Flyer_Carapace) == 0)
					{
						insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Zerg_Flyer_Carapace, nullptr, BWAPI::Positions::None, 1));
					}

					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Mutalisk) >= 16
						&& BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Flyer_Attacks) == 1
						&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Zerg_Flyer_Attacks) == false
						&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UpgradeTypes::Zerg_Flyer_Attacks) == 0)
					{
						insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Zerg_Flyer_Attacks, nullptr, BWAPI::Positions::None, 2));
					}

					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Mutalisk) >= 20
						&& BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Flyer_Carapace) == 1
						&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Zerg_Flyer_Carapace) == false
						&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UpgradeTypes::Zerg_Flyer_Carapace) == 0)
					{
						insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Zerg_Flyer_Carapace, nullptr, BWAPI::Positions::None, 2));
					}

					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Mutalisk) >= 24
						&& BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hive) >= 1
						&& BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Flyer_Attacks) == 2
						&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Zerg_Flyer_Attacks) == false
						&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UpgradeTypes::Zerg_Flyer_Attacks) == 0)
					{
						insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Zerg_Flyer_Attacks, nullptr, BWAPI::Positions::None, 3));
					}

					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Mutalisk) >= 24
						&& BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hive) >= 1
						&& BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Flyer_Carapace) == 2
						&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Zerg_Flyer_Carapace) == false
						&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UpgradeTypes::Zerg_Flyer_Carapace) == 0)
					{
						insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Zerg_Flyer_Carapace, nullptr, BWAPI::Positions::None, 3));
					}
				}
				// BWAPI 4.1.2 의 버그 때문에 그레이터 스파이어가 있더라도 스파이어 건설 필요
				else {

					if (BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Spire) == 0
						&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UnitTypes::Zerg_Spire) == 0
						&& ConstructionManager::Instance().getConstructionQueueItemCount(BWAPI::UnitTypes::Zerg_Spire) == 0) 
					{
						insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Spire, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
					}
				}
			}
			*/

			// 퀸
			if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Queens_Nest) >= 1) {

				// 브루들링은 필수
				if (BWAPI::Broodwar->self()->hasResearched(BWAPI::TechTypes::Spawn_Broodlings) == false
					&& BWAPI::Broodwar->self()->isResearching(BWAPI::TechTypes::Spawn_Broodlings) == false) {

					insertTask(StrategicTask(TaskGoalType::Build_Tech, BWAPI::UnitTypes::None, BWAPI::TechTypes::Spawn_Broodlings, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
				}

				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Queen) >= 4) {
					// 에너지 업그레이드
					insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Gamete_Meiosis, nullptr, BWAPI::Positions::None, 1));

					// 인스네어
					/*
					if (BWAPI::Broodwar->self()->hasResearched(BWAPI::TechTypes::Spawn_Broodlings) == true
						&& BWAPI::Broodwar->self()->hasResearched(BWAPI::TechTypes::Ensnare) == false
						&& BWAPI::Broodwar->self()->isResearching(BWAPI::TechTypes::Ensnare) == false) {

						insertTask(StrategicTask(TaskGoalType::Build_Tech, BWAPI::UnitTypes::None, BWAPI::TechTypes::Ensnare, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
					}
					*/
				}

			}

			// 디파일러
			if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Defiler_Mound) >= 1) {

				// 컨슘은 필수 : 대 테란전 항상. 대 프로토스 : 드라군 대응. 대 저그 : 뮤탈 대응
				if (BWAPI::Broodwar->self()->hasResearched(BWAPI::TechTypes::Consume) == false
					&& BWAPI::Broodwar->self()->isResearching(BWAPI::TechTypes::Consume) == false) {

					insertTask(StrategicTask(TaskGoalType::Build_Tech, BWAPI::UnitTypes::None, BWAPI::TechTypes::Consume, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1, true));
				}

				// 컨슘 다음에 플래이그
				/*
				if (BWAPI::Broodwar->self()->hasResearched(BWAPI::TechTypes::Consume) == true
					&& BWAPI::Broodwar->self()->hasResearched(BWAPI::TechTypes::Plague) == false
					&& BWAPI::Broodwar->self()->isResearching(BWAPI::TechTypes::Plague) == false) {

					insertTask(StrategicTask(TaskGoalType::Build_Tech, BWAPI::UnitTypes::None, BWAPI::TechTypes::Plague, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1));
				}

				// 플래이그 다음에 에너지 업그레이드
				if (BWAPI::Broodwar->self()->hasResearched(BWAPI::TechTypes::Plague) == true
					&& BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Metasynaptic_Node) <= 0
					&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Metasynaptic_Node) == false) {
		
					insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Metasynaptic_Node, nullptr, BWAPI::Positions::None, 1));
				}
				*/
			}


			/*
			// 울트라리스크
			if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Ultralisk_Cavern) >= 1) {
				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Ultralisk) >= 2) {
					// 울트라리스크 이동속도 업
					insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Anabolic_Synthesis, nullptr, BWAPI::Positions::None, 1));
				}

				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Ultralisk) >= 4) {
					// 울트라리스크 방어력 업
					insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Chitinous_Plating, nullptr, BWAPI::Positions::None, 1));
				}
			}
			*/

			// 에볼루션 챔버
			if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Zergling) >= 24
				|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk) >= 8
				|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Ultralisk) >= 4) 
			{
				if (BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Evolution_Chamber) == 0
					&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UnitTypes::Zerg_Evolution_Chamber) == 0
					&& ConstructionManager::Instance().getConstructionQueueItemCount(BWAPI::UnitTypes::Zerg_Evolution_Chamber) == 0)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Evolution_Chamber, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 1));
				}
			}

			if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Zergling) >= 36
				|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk) >= 16
				|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Ultralisk) >= 8)
			{
				if (BWAPI::Broodwar->self()->allUnitCount(BWAPI::UnitTypes::Zerg_Evolution_Chamber) < 2
					&& BuildManager::Instance().buildQueue.getItemCount(BWAPI::UnitTypes::Zerg_Evolution_Chamber) == 0
					&& ConstructionManager::Instance().getConstructionQueueItemCount(BWAPI::UnitTypes::Zerg_Evolution_Chamber) == 0)
				{
					insertTask(StrategicTask(TaskGoalType::Build_Unit_By_Limit, BWAPI::UnitTypes::Zerg_Evolution_Chamber, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::None, nullptr, BWAPI::Positions::None, 2));
				}
			}

			if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Evolution_Chamber) >= 1) {

				// 방어력 업그레이드
				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Zergling) >= 16
					|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk) >= 8
					|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Ultralisk) >= 4)
				{
					if (BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Carapace) == 0
						&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Zerg_Melee_Attacks) == false)
					{
						insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Zerg_Carapace, nullptr, BWAPI::Positions::None, 1));
					}

					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Lair) >= 1
						|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hive) >= 1) {

						if (BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Carapace) == 1
							&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Zerg_Carapace) == false)
						{
							insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Zerg_Carapace, nullptr, BWAPI::Positions::None, 2));
						}
					}

					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hive) >= 1) {

						if (BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Carapace) == 2
							&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Zerg_Carapace) == false)
						{
							insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Zerg_Carapace, nullptr, BWAPI::Positions::None, 3));
						}
					}
				}

				/*
				// Melee 공격력 업그레이드
				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Zergling) >= 16
					|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Ultralisk) >= 4)
				{
					if (BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Carapace) >= 1
						&& BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Melee_Attacks) == 0
						&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Zerg_Melee_Attacks) == false)
					{
						insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Zerg_Melee_Attacks, nullptr, BWAPI::Positions::None, 1));
					}

					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Lair) >= 1
						|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hive) >= 1) {

						if (BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Carapace) >= 2
							&& BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Melee_Attacks) == 1
							&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Zerg_Melee_Attacks) == false)
						{
							insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Zerg_Melee_Attacks, nullptr, BWAPI::Positions::None, 2));
						}
					}

					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hive) >= 1) {

						if (BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Carapace) >= 3
							&& BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Melee_Attacks) == 2
							&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Zerg_Melee_Attacks) == false)
						{
							insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Zerg_Melee_Attacks, nullptr, BWAPI::Positions::None, 3));
						}
					}
				}
				*/

				// Missile 공격력 업그레이드
				if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hydralisk) >= 8)
				{
					if (BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Carapace) >= 1
						&& BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Missile_Attacks) == 0
						&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Zerg_Missile_Attacks) == false)
					{
						insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Zerg_Missile_Attacks, nullptr, BWAPI::Positions::None, 1));
					}

					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Lair) >= 1
						|| BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hive) >= 1) {

						if (BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Carapace) >= 2
							&& BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Missile_Attacks) == 1
							&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Zerg_Missile_Attacks) == false)
						{
							insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Zerg_Missile_Attacks, nullptr, BWAPI::Positions::None, 2));
						}
					}

					if (BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hive) >= 1) {

						if (BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Carapace) >= 3
							&& BWAPI::Broodwar->self()->getUpgradeLevel(BWAPI::UpgradeTypes::Zerg_Missile_Attacks) == 2
							&& BWAPI::Broodwar->self()->isUpgrading(BWAPI::UpgradeTypes::Zerg_Missile_Attacks) == false)
						{
							insertTask(StrategicTask(TaskGoalType::Build_Upgrade, BWAPI::UnitTypes::None, BWAPI::TechTypes::None, BWAPI::UpgradeTypes::Zerg_Missile_Attacks, nullptr, BWAPI::Positions::None, 3));
						}
					}
				}
			}
		}
	}
}


void StrategyManager::moveWorkerToConstructionPlace()
{

	// 앞마당 해처리 조금 더 빨리 건설하기
	if (isAlreadySentFirstExpansionHatcheryDrone == false) {

		if (BuildManager::Instance().buildQueue.isEmpty() == false) {
			BuildOrderItem currentItem = BuildManager::Instance().buildQueue.getHighestPriorityItem();
			if (currentItem.metaType.isBuilding()) {

				if (currentItem.metaType.getUnitType() == BWAPI::UnitTypes::Zerg_Hatchery
					&& currentItem.seedLocationStrategy == BuildOrderItem::SeedPositionStrategy::FirstExpansionLocation
					&& BWAPI::Broodwar->self()->completedUnitCount(BWAPI::UnitTypes::Zerg_Hatchery) == 1)
				{
					// TODO : 변경
					if (BWAPI::Broodwar->self()->minerals() >= 220)
					{
						BWAPI::Unit worker = WorkerManager::Instance().getClosestMineralWorkerTo(StrategyManager::Instance().myFirstExpansionBaseLocation->getPosition());

						if (worker) {
							//std::cout << "Zerg_Hatchery getClosestMineralWorkerTo " << worker->getID() << std::endl;
							WorkerManager::Instance().setMoveWorker(worker, 0, 0, myFirstExpansionBaseLocation->getPosition());
							isAlreadySentFirstExpansionHatcheryDrone = true;
						}
					}
				}
			}
		}
	}

	// 앞마당 크립 조금 더 빨리 건설하기
	if (isAlreadySentFirstExpansionCreepColonyDrone == false) {

		if (BuildManager::Instance().buildQueue.isEmpty() == false) {
			BuildOrderItem currentItem = BuildManager::Instance().buildQueue.getHighestPriorityItem();
			if (currentItem.metaType.isBuilding()) {

				if (currentItem.metaType.getUnitType() == BWAPI::UnitTypes::Zerg_Creep_Colony
					&& currentItem.seedLocationStrategy == BuildOrderItem::SeedPositionStrategy::FirstExpansionLocation)
				{
					BWAPI::Unit mySecondHatchery = nullptr;
					for (auto & unit : BWAPI::Broodwar->self()->getUnits()) {
						if (unit == nullptr || unit->exists() == false) continue;
						if (unit->getType() == BWAPI::UnitTypes::Zerg_Hatchery) {
							if (unit->getDistance(myFirstExpansionBaseLocation->getPosition()) < 8 * TILE_SIZE) {
								mySecondHatchery = unit;
								break;
							}
						}
					}

					if (mySecondHatchery) {
						if (mySecondHatchery->getHitPoints() > 1100) {
							BWAPI::Unit worker = WorkerManager::Instance().getClosestMineralWorkerTo(StrategyManager::Instance().myFirstExpansionBaseLocation->getPosition());

							if (worker) {

								//std::cout << "Zerg_Creep_Colony getClosestMineralWorkerTo " << worker->getID() << std::endl;

								WorkerManager::Instance().setMoveWorker(worker, 0, 0, myFirstExpansionBaseLocation->getPosition());
								isAlreadySentFirstExpansionCreepColonyDrone = true;
							}
						}
					}

				}
			}
		}
	}

}