diff --git a/hwe/b_chiefcenter.php b/hwe/b_chiefcenter.php index 5ef4df50..b3878152 100644 --- a/hwe/b_chiefcenter.php +++ b/hwe/b_chiefcenter.php @@ -39,14 +39,14 @@ var maxChiefTurn = ;
.
+ >
>
>
- :  
+ >
 
 
; >
.
+ >
>
; >
.
+ >
>
>
- :  
+ >
 
 
; >
.
+ >
>
; 명마
@@ -299,15 +299,15 @@ var defaultSpecialDomestic = ; 무기
서적
@@ -328,8 +328,8 @@ var defaultSpecialDomestic = ; 도구
diff --git a/hwe/func_command.php b/hwe/func_command.php index 35aed69c..9c9ae38c 100644 --- a/hwe/func_command.php +++ b/hwe/func_command.php @@ -92,13 +92,7 @@ function repeatGeneralCommand(int $generalId, int $turnCnt){ $turnList = $db->query('SELECT turn_idx, `action`, arg, brief FROM general_turn WHERE general_id=%i AND turn_idx < %i', $generalId, $reqTurn); foreach($turnList as $turnItem){ $turnIdx = $turnItem['turn_idx']; - $nextTurnIdx = $turnIdx+$turnCnt; - $turnTarget = []; - while($nextTurnIdx < GameConst::$maxTurn){ - //NOTE: range(15, 24, 12) 가 PHP에선 에러다. 그러니 직접 짠다. - $turnTarget[] = $nextTurnIdx; - $nextTurnIdx += $turnCnt; - } + $turnTarget = iterator_to_array(Util::range($turnIdx+$turnCnt, GameConst::$maxTurn, $turnCnt)); $db->update('general_turn', [ 'action'=>$turnItem['action'], diff --git a/hwe/func_gamerule.php b/hwe/func_gamerule.php index 7fba9fcf..481ded77 100644 --- a/hwe/func_gamerule.php +++ b/hwe/func_gamerule.php @@ -931,8 +931,8 @@ function updateNationState() { ], 'nation=%i', $nation['nation']); $turnRows = []; - foreach(range(12, getNationChiefLevel($nation['level']), -1) as $chiefLevel){ - foreach(range(0, GameConst::$maxChiefTurn - 1) as $turnIdx){ + foreach(Util::range(getNationChiefLevel($nation['level']), 12) as $chiefLevel){ + foreach(Util::range(GameConst::$maxChiefTurn) as $turnIdx){ $turnRows[] = [ 'nation_id'=>$nation['nation'], 'level'=>$chiefLevel, diff --git a/hwe/func_history.php b/hwe/func_history.php index 4fb38e90..05777b5b 100644 --- a/hwe/func_history.php +++ b/hwe/func_history.php @@ -44,7 +44,7 @@ function getFormattedFileLogAll(string $path){ } function eraseTnmtFightLogAll(){ - foreach(range(0, 49) as $i){ + foreach(Util::range(50) as $i){ eraseTnmtFightLog($i); } } diff --git a/hwe/func_template.php b/hwe/func_template.php index 4befe43d..7254112c 100644 --- a/hwe/func_template.php +++ b/hwe/func_template.php @@ -15,7 +15,7 @@ function turnTable() { $turnList = []; $turnList[] = ""; - foreach(\range(1, GameConst::$maxTurn - 1) as $turnIdx){ + foreach(Util::range(1, GameConst::$maxTurn) as $turnIdx){ $turnText = $turnIdx + 1; $turnList[] = ""; } @@ -35,7 +35,7 @@ function turnTable() { function chiefTurnTable() { $turnList = []; $turnList[] = ""; -foreach(range(1, GameConst::$maxChiefTurn - 1) as $turnIdx){ +foreach(Util::range(1, GameConst::$maxChiefTurn) as $turnIdx){ $turnText = $turnIdx + 1; $turnList[] = ""; } diff --git a/hwe/j_simulate_battle.php b/hwe/j_simulate_battle.php index bacd2da9..08078f91 100644 --- a/hwe/j_simulate_battle.php +++ b/hwe/j_simulate_battle.php @@ -371,7 +371,7 @@ $avgWar = 0; $attackerActivatedSkills = []; $defendersActivatedSkills = []; -foreach(range(1, $repeatCnt) as $repeatIdx){ +foreach(Util::range($repeatCnt) as $repeatIdx){ [$attacker, $city, $battleResult, $conquerCity, $attackerRice, $defenderRice] = simulateBattle( $rawAttacker, $rawAttackerCity, $rawAttackerNation, $defenderList, $rawDefenderCity, $rawDefenderNation, diff --git a/hwe/join_post.php b/hwe/join_post.php index dc28a022..11646956 100644 --- a/hwe/join_post.php +++ b/hwe/join_post.php @@ -254,7 +254,7 @@ $db->insert('general', [ ]); $generalID = $db->insertId(); $turnRows = []; -foreach(range(0, GameConst::$maxTurn - 1) as $turnIdx){ +foreach(Util::range(GameConst::$maxTurn) as $turnIdx){ $turnRows[] = [ 'general_id'=>$generalID, 'turn_idx'=>$turnIdx, diff --git a/hwe/js/chiefCenter.js b/hwe/js/chiefCenter.js index 92931086..24c657fe 100644 --- a/hwe/js/chiefCenter.js +++ b/hwe/js/chiefCenter.js @@ -18,7 +18,7 @@ function genChiefTableObj(){ var $name = $plate.find('.chiefName'); var turn = []; for(var turnIdx=0;turnIdx$nationID, 'level'=>$chiefLevel, diff --git a/hwe/sammo/Command/Nation/che_불가침제의.php b/hwe/sammo/Command/Nation/che_불가침제의.php index b48bff11..5d5aaee6 100644 --- a/hwe/sammo/Command/Nation/che_불가침제의.php +++ b/hwe/sammo/Command/Nation/che_불가침제의.php @@ -275,12 +275,12 @@ class che_불가침제의 extends Command\NationCommand{ 에게 월 전까지 diff --git a/hwe/sammo/Command/Nation/che_원조.php b/hwe/sammo/Command/Nation/che_원조.php index bea6ffc3..ceca29c1 100644 --- a/hwe/sammo/Command/Nation/che_원조.php +++ b/hwe/sammo/Command/Nation/che_원조.php @@ -255,12 +255,12 @@ class che_원조 extends Command\NationCommand{ 국고 병량 diff --git a/hwe/sammo/General.php b/hwe/sammo/General.php index 3210c7b8..aa9fd1e3 100644 --- a/hwe/sammo/General.php +++ b/hwe/sammo/General.php @@ -326,7 +326,7 @@ class General implements iAction{ $rawCmds = $db->queryFirstRow('SELECT * FROM general_turn WHERE general_id = %i AND %i <= turn_idx AND turn_idx < %i ORDER BY turn_idx ASC', $generalID, $turnIdxFrom, $turnIdxTo); if(!$rawCmds){ - foreach(range($turnIdxFrom, $turnIdxTo-1) as $turnIdx){ + foreach(Util::range($turnIdxFrom, $turnIdxTo) as $turnIdx){ $result[$turnIdx] = buildGeneralCommandClass(null, $this, $env); } return $result; @@ -1025,7 +1025,7 @@ class General implements iAction{ $generalID = $general->getID(); $result[$generalID] = []; if(!key_exists($generalID, $orderedRawCmds)){ - foreach(range($turnIdxFrom, $turnIdxTo-1) as $turnIdx){ + foreach(Util::range($turnIdxFrom, $turnIdxTo) as $turnIdx){ $result[$generalID][$turnIdx] = buildGeneralCommandClass(null, $general, $env); } continue; diff --git a/hwe/sammo/GeneralAI.php b/hwe/sammo/GeneralAI.php index b01050a6..aa40c6bf 100644 --- a/hwe/sammo/GeneralAI.php +++ b/hwe/sammo/GeneralAI.php @@ -455,6 +455,10 @@ class GeneralAI } }); + if(!$generalCadidates){ + return null; + } + if(count($this->supplyCities) == 1){ return null; } @@ -566,7 +570,7 @@ class GeneralAI if (in_array($this->dipState, [self::d평화, self::d선포])) { return null; } - + //고립 도시 장수 발령 $args = []; foreach ($this->lostGenerals as $lostGeneral) { @@ -1887,7 +1891,7 @@ class GeneralAI $generalID = $general->getID(); $cmd = buildGeneralCommandClass('che_집합', $general, $this->env); - _setGeneralCommand($generalID, range(0, GameConst::$maxTurn - 1), $cmd->getRawClassName(), $cmd->getArg(), $cmd->getBrief()); + _setGeneralCommand($generalID, iterator_to_array(Util::range(GameConst::$maxTurn)), $cmd->getRawClassName(), $cmd->getArg(), $cmd->getBrief()); return $cmd; } @@ -3538,7 +3542,7 @@ class GeneralAI $iterCandChiefStrength = new \ArrayIterator($candChiefStrength); $iterCandChiefIntel = new \ArrayIterator($candChiefIntel); - foreach (range(10, $minChiefLevel, -1) as $chiefLevel) { + foreach (Util::range(10, $minChiefLevel-1, -1) as $chiefLevel) { if (key_exists($chiefLevel, $chiefCandidate)) { continue; } diff --git a/hwe/sammo/ResetHelper.php b/hwe/sammo/ResetHelper.php index bc842bc6..384a15d4 100644 --- a/hwe/sammo/ResetHelper.php +++ b/hwe/sammo/ResetHelper.php @@ -272,7 +272,7 @@ class ResetHelper{ ]); $generalID = $db->insertId(); $turnRows = []; - foreach(range(0, GameConst::$maxTurn - 1) as $turnIdx){ + foreach(Util::range(GameConst::$maxTurn) as $turnIdx){ $turnRows[] = [ 'general_id'=>$generalID, 'turn_idx'=>$turnIdx, diff --git a/hwe/sammo/Scenario/NPC.php b/hwe/sammo/Scenario/NPC.php index f9ce0d74..e57db89a 100644 --- a/hwe/sammo/Scenario/NPC.php +++ b/hwe/sammo/Scenario/NPC.php @@ -347,7 +347,7 @@ class NPC{ ]); $this->generalID = $db->insertId(); $turnRows = []; - foreach(range(0, GameConst::$maxTurn - 1) as $turnIdx){ + foreach(Util::range(GameConst::$maxTurn) as $turnIdx){ $turnRows[] = [ 'general_id'=>$this->generalID, 'turn_idx'=>$turnIdx, diff --git a/hwe/sammo/Scenario/Nation.php b/hwe/sammo/Scenario/Nation.php index 9e3ce105..66b34a3f 100644 --- a/hwe/sammo/Scenario/Nation.php +++ b/hwe/sammo/Scenario/Nation.php @@ -2,6 +2,7 @@ namespace sammo\Scenario; use \sammo\DB; use \sammo\GameConst; +use \sammo\Util; use function \sammo\getNationChiefLevel; class Nation{ @@ -150,8 +151,8 @@ class Nation{ } $turnRows = []; - foreach(range(getNationChiefLevel(0) - 1, getNationChiefLevel($this->nationLevel), -1) as $chiefLevel){ - foreach(range(0, GameConst::$maxChiefTurn - 1) as $turnIdx){ + foreach(Util::range(12, getNationChiefLevel($this->nationLevel)-1, -1) as $chiefLevel){ + foreach(Util::range(GameConst::$maxChiefTurn) as $turnIdx){ $turnRows[] = [ 'nation_id'=>$this->id, 'level'=>$chiefLevel, @@ -162,7 +163,7 @@ class Nation{ ]; } } - $db->insert('nation_turn', $turnRows); + $db->insertIgnore('nation_turn', $turnRows); } public function getBrief(){ diff --git a/src/sammo/Util.php b/src/sammo/Util.php index 2828b9a7..a5be3f1d 100644 --- a/src/sammo/Util.php +++ b/src/sammo/Util.php @@ -721,10 +721,45 @@ class Util extends \utilphp\util return 0; } - function isPowerOfTwo(int $number):bool{ + public static function isPowerOfTwo(int $number):bool{ if($number <= 0){ return false; } return ($number & ($number - 1)) == 0; } + + /** + * Python 3의 range와 동일 + * @param int $from + * @param null|int $to + * @param null|int $step + * @return \Traversable + * @throws InvalidArgumentException + */ + public static function range(int $from, ?int $to=null, ?int $step=null):\Traversable{ + if($to === null){ + $to = $from; + $from = 0; + } + if($step === null){ + $step = 1; + } + else if($step === 0){ + throw new \InvalidArgumentException('xrange() arg 3 must not be zero'); + } + + if($step > 0){ + while($from < $to){ + yield $from; + $from += 1; + } + } + else{ + while($from > $to){ + yield $from; + $from -= 1; + } + } + } + };