feat,refac: 게임 로직 내 '랜덤'을 RandUtil을 활용하여 재설정

- 기존의 랜덤 코드는 deprecated 처리
- 서버 시작 시 랜덤하게 정해진 hiddenSeed를 활용
- 랜덤 생성 단위
  - 월 실행
  - 사령턴 실행 결과
  - 커맨드 실행 결과
  - 작위 보상
  - 부대장 생성
  - 유니크 획득 시도
  - 설문 조사
  - 장수 생성
  - NPC국 생성, NPC 생성, NPC의 토너먼트 베팅
  - 전투
  - 도시 점령
  - 자율 행동 선택
  - 랜덤 턴 변경
- 거래장, 토너먼트 등 구 랜덤 코드를 이용하는 잔여 코드 있음
This commit is contained in:
2022-05-17 03:46:59 +09:00
parent 2cb697f3dc
commit c5ceff6fb5
136 changed files with 1000 additions and 784 deletions
+50
View File
@@ -0,0 +1,50 @@
<?php
namespace sammo;
const MAX_RNG_SUPPORT_BIT = 53;
/**
* 내부에 랜덤 값을 호출하지 않을 것이 확실할 때 RNG 대용으로 사용
* 어떤 함수를 호출하든 에러 발생
*/
class NoRNG implements RNG
{
const MAX_INT = (1 << MAX_RNG_SUPPORT_BIT) - 1;
public function __construct()
{
}
static function getMaxInt(): int
{
return self::MAX_INT;
}
public function nextBytes(int $bytes): string
{
throw new MustNotBeReachedException();
}
public function nextBits(int $bits): string
{
throw new MustNotBeReachedException();
}
public function nextInt(?int $max = null): int
{
throw new MustNotBeReachedException();
}
public function nextFloat1(): float
{
throw new MustNotBeReachedException();
}
private static RandUtil|null $instance = null;
static function rngInstance(): RandUtil
{
if (self::$instance === null) {
self::$instance = new RandUtil(new NoRNG());
}
return self::$instance;
}
}
+1 -1
View File
@@ -4,7 +4,7 @@ namespace sammo;
class RandUtil
{
public function __construct(protected RNG $rng)
public function __construct(public readonly RNG $rng)
{
}
+7
View File
@@ -430,6 +430,7 @@ class Util extends \utilphp\util
/**
* [0.0, 1.0] 사이의 선형 랜덤 float
* @deprecated
* @return float
*/
public static function randF()
@@ -439,6 +440,7 @@ class Util extends \utilphp\util
/**
* [min, max] 사이의 선형 랜덤 float
* @deprecated
* @return float
*/
public static function randRange(float $min, float $max)
@@ -449,6 +451,7 @@ class Util extends \utilphp\util
/**
* [min, max] 사이의 선형 랜덤 int
* 현재는 rand(min, max)와 동일
* @deprecated
* @return int
*/
public static function randRangeInt(int $min, int $max){
@@ -457,6 +460,7 @@ class Util extends \utilphp\util
/**
* $prob의 확률로 true를 반환
* @deprecated
* @return boolean
*/
public static function randBool($prob = 0.5)
@@ -501,6 +505,7 @@ class Util extends \utilphp\util
* @param array $items 각 수치의 비중
*
* @return int|string 선택된 랜덤 값의 key값. 단순 배열인 경우에는 index
* @deprecated
*/
public static function choiceRandomUsingWeight(array $items)
{
@@ -533,6 +538,7 @@ class Util extends \utilphp\util
*
* @param array<{0:array|object,1:float|int}> $items 각 수치와 비중. [값, weight] 으로 보관
* @return array|object 선택된 랜덤 값의 첫번째 값
* @deprecated
*/
public static function choiceRandomUsingWeightPair(array $items)
{
@@ -629,6 +635,7 @@ class Util extends \utilphp\util
* @param array $items 선택하고자 하는 배열
*
* @return int|float|string|array|object 선택된 value값.
* @deprecated
*/
public static function choiceRandom(array $items)
{