Util::range 추가
This commit is contained in:
@@ -39,14 +39,14 @@ var maxChiefTurn = <?=GameConst::$maxChiefTurn?>;
|
||||
<div class="chiefSubTable" style='height:<?=22*(GameConst::$maxChiefTurn+1)?>px;'
|
||||
><div class='chiefTurnIdxPanel'
|
||||
><div class='bg1 chiefTurnIdx'>.</div
|
||||
<?php foreach(range(1, 12) as $idx):?>
|
||||
<?php foreach(Util::range(GameConst::$maxChiefTurn) as $idx):?>
|
||||
><div class='bg0 chiefTurnIdx'><?=$idx?></div
|
||||
<?php endforeach; ?>
|
||||
></div
|
||||
<?php foreach([12, 10, 8, 6] as $chiefIdx): ?>
|
||||
><div class='bg2 chiefPlate' style='flex-grow:1;' id='chief_<?=$chiefIdx?>'
|
||||
><div class='bg1 chiefNamePlate'><span class='chiefLevelText'>-</span> : <span class='chiefName'> </span></div
|
||||
<?php foreach(range(1, GameConst::$maxChiefTurn) as $turnIdx): ?>
|
||||
<?php foreach(Util::range(GameConst::$maxChiefTurn) as $turnIdx): ?>
|
||||
><div class='chiefTurnBox turn<?=$turnIdx?>'
|
||||
><div class='chiefTurnTime'> </div
|
||||
><div class='chiefTurnPad'><span class='chiefTurnText'> </span></div
|
||||
@@ -56,7 +56,7 @@ var maxChiefTurn = <?=GameConst::$maxChiefTurn?>;
|
||||
<?php endforeach; ?>
|
||||
><div class='chiefTurnIdxPanel tail'
|
||||
><div class='bg1 chiefTurnIdx'>.</div
|
||||
<?php foreach(range(1, GameConst::$maxChiefTurn) as $idx):?>
|
||||
<?php foreach(Util::range(GameConst::$maxChiefTurn) as $idx):?>
|
||||
><div class='bg0 chiefTurnIdx'><?=$idx?></div
|
||||
<?php endforeach; ?>
|
||||
></div
|
||||
@@ -79,14 +79,14 @@ var maxChiefTurn = <?=GameConst::$maxChiefTurn?>;
|
||||
><div class="chiefSubTable" style='height:<?=22*(GameConst::$maxChiefTurn+1)?>px;'
|
||||
><div class='chiefTurnIdxPanel'
|
||||
><div class='bg1 chiefTurnIdx'>.</div
|
||||
<?php foreach(range(1, GameConst::$maxChiefTurn) as $idx):?>
|
||||
<?php foreach(Util::range(GameConst::$maxChiefTurn) as $idx):?>
|
||||
><div class='bg0 chiefTurnIdx'><?=$idx?></div
|
||||
<?php endforeach; ?>
|
||||
></div
|
||||
<?php foreach([11, 9, 7, 5] as $chiefIdx): ?>
|
||||
><div class='bg2 chiefPlate' style='flex-grow:1;' id='chief_<?=$chiefIdx?>'
|
||||
><div class='bg1 chiefNamePlate'><span class='chiefLevelText'>-</span> : <span class='chiefName'> </span></div
|
||||
<?php foreach(range(1, GameConst::$maxChiefTurn) as $turnIdx): ?>
|
||||
<?php foreach(Util::range(GameConst::$maxChiefTurn) as $turnIdx): ?>
|
||||
><div class='chiefTurnBox turn<?=$turnIdx?>'
|
||||
><div class='chiefTurnTime'> </div
|
||||
><div class='chiefTurnPad'><span class='chiefTurnText'> </span></div
|
||||
@@ -96,7 +96,7 @@ var maxChiefTurn = <?=GameConst::$maxChiefTurn?>;
|
||||
<?php endforeach; ?>
|
||||
><div class='chiefTurnIdxPanel tail'
|
||||
><div class='bg1 chiefTurnIdx'>.</div
|
||||
<?php foreach(range(1, 12) as $idx):?>
|
||||
<?php foreach(Util::range(GameConst::$maxChiefTurn) as $idx):?>
|
||||
><div class='bg0 chiefTurnIdx'><?=$idx?></div
|
||||
<?php endforeach; ?>
|
||||
></div
|
||||
|
||||
@@ -291,7 +291,7 @@ var defaultSpecialDomestic = <?=GameConst::$defaultSpecialDomestic?>;
|
||||
<span class="input-group-text">명마</span>
|
||||
</div>
|
||||
<select class="custom-select form_general_horse">
|
||||
<?php foreach(range(0, 26) as $horseID): ?>
|
||||
<?php foreach(GameConst::$allItems['horse'] as $horseID=>$cnt): ?>
|
||||
<option value="<?=$horseID?>"><?=getItemName($horseID)?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
@@ -299,15 +299,15 @@ var defaultSpecialDomestic = <?=GameConst::$defaultSpecialDomestic?>;
|
||||
<span class="input-group-text">무기</span>
|
||||
</div>
|
||||
<select class="custom-select form_general_weap">
|
||||
<?php foreach(range(0, 26) as $weapID): ?>
|
||||
<option value="<?=$weapID?>"><?=getItemName($weapID)?></option>
|
||||
<?php foreach(GameConst::$allItems['weapon'] as $weaponID=>$cnt): ?>
|
||||
<option value="<?=$weaponID?>"><?=getItemName($weaponID)?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<div class="input-group-prepend">
|
||||
<span class="input-group-text">서적</span>
|
||||
</div>
|
||||
<select class="custom-select form_general_book">
|
||||
<?php foreach(range(0, 26) as $bookID): ?>
|
||||
<?php foreach(GameConst::$allItems['book'] as $bookID=>$cnt): ?>
|
||||
<option value="<?=$bookID?>"><?=getItemName($bookID)?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
@@ -328,8 +328,8 @@ var defaultSpecialDomestic = <?=GameConst::$defaultSpecialDomestic?>;
|
||||
<span class="input-group-text">도구</span>
|
||||
</div>
|
||||
<select class="custom-select form_general_item">
|
||||
<?php foreach(range(0, 26) as $bookID): ?>
|
||||
<option value="<?=$bookID?>"><?=getItemName($bookID)?></option>
|
||||
<?php foreach(GameConst::$allItems['item'] as $itemID=>$cnt): ?>
|
||||
<option value="<?=$itemID?>"><?=getItemName($itemID)?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
</div>
|
||||
|
||||
@@ -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'],
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -44,7 +44,7 @@ function getFormattedFileLogAll(string $path){
|
||||
}
|
||||
|
||||
function eraseTnmtFightLogAll(){
|
||||
foreach(range(0, 49) as $i){
|
||||
foreach(Util::range(50) as $i){
|
||||
eraseTnmtFightLog($i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ function turnTable() {
|
||||
|
||||
$turnList = [];
|
||||
$turnList[] = "<option selected value='0'>1턴</option>";
|
||||
foreach(\range(1, GameConst::$maxTurn - 1) as $turnIdx){
|
||||
foreach(Util::range(1, GameConst::$maxTurn) as $turnIdx){
|
||||
$turnText = $turnIdx + 1;
|
||||
$turnList[] = "<option value='{$turnIdx}'>{$turnText}턴</option>";
|
||||
}
|
||||
@@ -35,7 +35,7 @@ function turnTable() {
|
||||
function chiefTurnTable() {
|
||||
$turnList = [];
|
||||
$turnList[] = "<option selected value='0'>1턴</option>";
|
||||
foreach(range(1, GameConst::$maxChiefTurn - 1) as $turnIdx){
|
||||
foreach(Util::range(1, GameConst::$maxChiefTurn) as $turnIdx){
|
||||
$turnText = $turnIdx + 1;
|
||||
$turnList[] = "<option value='{$turnIdx}'>{$turnText}턴</option>";
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
+1
-1
@@ -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,
|
||||
|
||||
@@ -18,7 +18,7 @@ function genChiefTableObj(){
|
||||
var $name = $plate.find('.chiefName');
|
||||
var turn = [];
|
||||
for(var turnIdx=0;turnIdx<maxChiefTurn;turnIdx++){
|
||||
var $turn = $plate.find('.turn{0}'.format(turnIdx+1));
|
||||
var $turn = $plate.find('.turn{0}'.format(turnIdx));
|
||||
var $turnTime = $turn.find('.chiefTurnTime');
|
||||
var $turnPad = $turn.find('.chiefTurnPad');
|
||||
var $turnText = $turn.find('.chiefTurnText');
|
||||
|
||||
@@ -132,7 +132,7 @@ class che_거병 extends Command\GeneralCommand{
|
||||
|
||||
$turnRows = [];
|
||||
foreach([12, 11] as $chiefLevel){
|
||||
foreach(range(0, GameConst::$maxChiefTurn - 1) as $turnIdx){
|
||||
foreach(Util::range(GameConst::$maxChiefTurn) as $turnIdx){
|
||||
$turnRows[] = [
|
||||
'nation_id'=>$nationID,
|
||||
'level'=>$chiefLevel,
|
||||
|
||||
@@ -275,12 +275,12 @@ class che_불가침제의 extends Command\NationCommand{
|
||||
<?php endforeach; ?>
|
||||
</select>에게
|
||||
<select class='formInput' name="year" id="year" size='1' style='color:white;background-color:black;'>
|
||||
<?php foreach(range($currYear+1, $currYear+20) as $formYear): ?>
|
||||
<?php foreach(Util::range($currYear+1, $currYear+20+1) as $formYear): ?>
|
||||
<option value='<?=$formYear?>'><?=$formYear?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>년
|
||||
<select class='formInput' name="month" id="month" size='1' style='color:white;background-color:black;'>
|
||||
<?php foreach(range(1, 12) as $formMonth): ?>
|
||||
<?php foreach(Util::range(1, 12+1) as $formMonth): ?>
|
||||
<option value='<?=$formMonth?>'><?=$formMonth?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>월 전까지
|
||||
|
||||
@@ -255,12 +255,12 @@ class che_원조 extends Command\NationCommand{
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
국고 <select class='formInput' name="amountList[]" class="amountList" size='1' style='color:white;background-color:black;'>
|
||||
<?php foreach(range(0, $currentNationLevel) as $nationLevel): ?>
|
||||
<?php foreach(Util::range($currentNationLevel+1) as $nationLevel): ?>
|
||||
<option value='<?=$nationLevel*GameConst::$coefAidAmount?>'><?=$nationLevel*GameConst::$coefAidAmount?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
병량 <select class='formInput' name="amountList[]" class="amountList" size='1' style='color:white;background-color:black;'>
|
||||
<?php foreach(range(0, $currentNationLevel) as $nationLevel): ?>
|
||||
<?php foreach(Util::range($currentNationLevel+1) as $nationLevel): ?>
|
||||
<option value='<?=$nationLevel*GameConst::$coefAidAmount?>'><?=$nationLevel*GameConst::$coefAidAmount?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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(){
|
||||
|
||||
+36
-1
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user