NPC 새로짜던 사령턴 파기
This commit is contained in:
@@ -959,209 +959,6 @@ class GeneralAI{
|
|||||||
return Util::choiceRandomUsingWeightPair($commandList);
|
return Util::choiceRandomUsingWeightPair($commandList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function chooseNeoNationTurn($command, $arg):array{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
//TODO: 이 버전으로 새로 개발
|
|
||||||
$generalObj = $this->getGeneralObj();
|
|
||||||
//NOTE: 수뇌 턴에서는 general과 city이름의 충돌 가능성이 있음
|
|
||||||
$env = $this->env;
|
|
||||||
|
|
||||||
$chiefID = $generalObj->getID();
|
|
||||||
$cityID = $generalObj->getCityID();
|
|
||||||
$nationID = $generalObj->getNationID();
|
|
||||||
|
|
||||||
$tech = $this->nation['tech'];
|
|
||||||
|
|
||||||
$db = DB::db();
|
|
||||||
|
|
||||||
if($generalObj->getVar('npc') == 5){
|
|
||||||
return [$command, $arg];
|
|
||||||
}
|
|
||||||
|
|
||||||
if($command && $command != '휴식'){
|
|
||||||
return [$command, $arg];
|
|
||||||
}
|
|
||||||
|
|
||||||
if($generalObj->getVar('level') == 12 && $this->dipState == self::d평화 && !$this->attackable){
|
|
||||||
$targetNationID = $this->findWarTarget();
|
|
||||||
if($targetNationID !== null){
|
|
||||||
return ['che_선전포고', ['destNationID'=>$targetNationID]];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$cityList = [];
|
|
||||||
$frontCity = [];
|
|
||||||
foreach($db->query('SELECT * FROM city WHERE nation = %i',$nationID) as $city){
|
|
||||||
//귀찮으니 object 변환
|
|
||||||
$city = (object)$city;
|
|
||||||
$city->id = $city->city;
|
|
||||||
$city->generals = [];
|
|
||||||
$city->devel_intel = ($city->agri + $city->comm) / ($city->agri2 + $city->comm2);
|
|
||||||
$city->devel_power = ($city->secu + $city->def + $city->wall) / ($city->secu2 + $city->def2 + $city->wall2);
|
|
||||||
$city->devel_leadership = (($city->trust) + ($city->pop / $city->pop2)) / 2;
|
|
||||||
$cityList[$city->id] = $city;
|
|
||||||
if($city->front > 0){
|
|
||||||
$frontCity[$city->id] = $city->front;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!key_exists($cityID, $cityList)){
|
|
||||||
//수뇌가 아국에 없음
|
|
||||||
return ['휴식', null];
|
|
||||||
}
|
|
||||||
|
|
||||||
$generalList = [];
|
|
||||||
foreach($db->query('SELECT no, npc, leader, power, intel, city, nation, level, gold, rice, troop, experience, dedication, killturn, injury, crew, crewtype, train, atmos, gold, rice FROM general WHERE nation = %i AND no != %i', $nationID, $generalObj->getID()) as $general){
|
|
||||||
//귀찮으니 object 변환
|
|
||||||
$general = (object)$general;
|
|
||||||
$general->id = $general->no;
|
|
||||||
$generalList[$general->id] = $general;
|
|
||||||
}
|
|
||||||
|
|
||||||
$troopList = [];
|
|
||||||
foreach($db->queryAllLists('SELECT troop, no FROM troop WHERE nation = %i', $nationID) as [$troopID, $troopLeaderID]){
|
|
||||||
$troop = (object)['id'=>$troopID, 'troop'=>$troopID, 'leader'=>$generalList[$troopLeaderID], 'members'=>[]];
|
|
||||||
$troopList[$troopID] = $troop;//troopID 가 아니라 troopLeaderID 임!
|
|
||||||
}
|
|
||||||
|
|
||||||
$candidateCommand = [];
|
|
||||||
|
|
||||||
$outerGenerals = [];
|
|
||||||
$troopLeaders = [];
|
|
||||||
|
|
||||||
$userGenerals = [];
|
|
||||||
$npcWarGenerals = [];
|
|
||||||
$npcCivilGenerals = [];
|
|
||||||
|
|
||||||
$remainResource = [
|
|
||||||
'gold'=>$this->nation['gold'] - GameConst::$minNationalGold,
|
|
||||||
'rice'=>$this->nation['rice'] - GameConst::$minNationalRice,
|
|
||||||
];
|
|
||||||
|
|
||||||
$generalResource = [
|
|
||||||
'gold'=>0,
|
|
||||||
'rice'=>0,
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
foreach($generalList as $general){
|
|
||||||
$generalResource['gold'] += $general->gold;
|
|
||||||
$generalResource['rice'] += $general->rice;
|
|
||||||
|
|
||||||
if(!key_exists($general->city, $cityList)){
|
|
||||||
$score = $general->npc < 2? 5 : 1;
|
|
||||||
$score *= sqrt(($general->leader + $general->power + $general->intel)/GameConst::$chiefStatMin);
|
|
||||||
//sqrt(1~5) 일 것.
|
|
||||||
$outerGenerals[$general->id] = $score;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$cityList[$general->city]->generals[$general->id] = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($general->troop){
|
|
||||||
if($troopList[$general->troop]->leader == $general){
|
|
||||||
$troopLeaders[] = $general;
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$troopList[$general->troop]->members[] = $general;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if($chiefID != $general->id){
|
|
||||||
//명단에 추가할 수 없다.
|
|
||||||
}
|
|
||||||
else if($general->npc < 2 && $general->killturn >= 5){
|
|
||||||
$userGenerals[] = $general;
|
|
||||||
}
|
|
||||||
else if($general->leader >= 40 && $general->killturn >= 5){
|
|
||||||
$npcWarGenerals[] = $general;
|
|
||||||
}
|
|
||||||
else if($general->npc != 5){
|
|
||||||
$npcCivilGenerals[] = $general;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if($outerGenerals){
|
|
||||||
$candidateCommand[] =
|
|
||||||
[
|
|
||||||
['che_발령', [
|
|
||||||
'destGeneralID' => Util::choiceRandomUsingWeight($outerGenerals),
|
|
||||||
'destCityID' => Util::choiceRandom(array_keys($frontCity))
|
|
||||||
]],
|
|
||||||
Util::arraySum($outerGenerals, 1) / sqrt(count($outerGenerals))
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
$baseDevelCost = $env['develcost'] * 12;
|
|
||||||
|
|
||||||
foreach(['gold', 'rice'] as $resName){
|
|
||||||
usort($this->userGenerals, function($lhs, $rhs){
|
|
||||||
return $lhs->$resName <=> $rhs->$resName;
|
|
||||||
});
|
|
||||||
|
|
||||||
usort($this->npcWarGenerals, function($lhs, $rhs){
|
|
||||||
return $lhs->$resName <=> $rhs->$resName;
|
|
||||||
});
|
|
||||||
|
|
||||||
usort($this->npcCivilGenerals, function($lhs, $rhs){
|
|
||||||
return $lhs->$resName <=> $rhs->$resName;
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
if(
|
|
||||||
$remainResource[$resName] < 3000 ||
|
|
||||||
$remainResource[$resName] < $generalResource[$resName] / sqrt(count($generalList))
|
|
||||||
){
|
|
||||||
if ($npcWarGenerals) {
|
|
||||||
$targetNpcWarGeneral = Util::array_first($npcWarGenerals);
|
|
||||||
$crewtype = GameUnitConst::byID($targetNpcWarGeneral->crewtype);
|
|
||||||
//징병 2바퀴?
|
|
||||||
$reqMoney = $crewtype->costWithTech($tech, $targetNpcWarGeneral->leadership) * 2.2;
|
|
||||||
$enoughMoney = $reqMoney * 2;
|
|
||||||
$tooMuchMoney = $enoughMoney * 1.5;
|
|
||||||
|
|
||||||
if($targetNpcWarGeneral->$resName >= $reqMoney){
|
|
||||||
$candidateCommand[] = [
|
|
||||||
['che_몰수', [
|
|
||||||
'destGeneralID' => $targetNpcWarGeneral->id,
|
|
||||||
'isGold'=>$resName=='gold',
|
|
||||||
'amount'=>($targetNpcWarGeneral->$resName - $reqMoney) / 2
|
|
||||||
]],
|
|
||||||
$reqMoney / $tooMuchMoney * 3,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($userGenerals) {
|
|
||||||
$targetUserGeneral = Util::array_last($userGenerals);
|
|
||||||
$crewtype = GameUnitConst::byID($targetUserGeneral->crewtype);
|
|
||||||
//모병 4바퀴?
|
|
||||||
$reqMoney = max(21000, $crewtype->costWithTech($tech, $targetNpcWarGeneral->leadership) * 2*4*1.1);
|
|
||||||
$enoughMoney = $reqMoney * 1.5;
|
|
||||||
$tooMuchMoney = $enoughMoney * 1.5;
|
|
||||||
|
|
||||||
if($targetNpcWarGeneral->$resName >= $reqMoney){
|
|
||||||
$candidateCommand[] = [
|
|
||||||
['che_몰수', [
|
|
||||||
'destGeneralID' => $targetNpcWarGeneral->id,
|
|
||||||
'isGold'=>$resName=='gold',
|
|
||||||
'amount'=>($userGenerals->$resName - $reqMoney) / 2
|
|
||||||
]],
|
|
||||||
$reqMoney / $tooMuchMoney * 2,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}//end if $remainResource[$resName] < 3000
|
|
||||||
}
|
|
||||||
|
|
||||||
if(in_array($this->dipState, [self::d직전, self::d전쟁])){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return Util::choiceRandomUsingWeightPair($candidateCommand);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function chooseNeutralTurn():array{
|
public function chooseNeutralTurn():array{
|
||||||
|
|
||||||
$general = $this->getGeneralObj();
|
$general = $this->getGeneralObj();
|
||||||
|
|||||||
Reference in New Issue
Block a user