mirror of
https://github.com/yairm210/Unciv.git
synced 2025-09-22 10:54:19 -04:00
Better state-based random - ensure repeatability while increasing diversity (less "bunching" of so-called "random" results)
This commit is contained in:
parent
bb5c98ab19
commit
c765287333
@ -20,7 +20,12 @@ object Conditionals {
|
||||
if (conditional.type?.targetTypes?.any { it.modifierType == UniqueTarget.ModifierType.Other } == true)
|
||||
return true // not a filtering condition, includes e.g. ModifierHiddenFromUsers
|
||||
|
||||
val stateBasedRandom by lazy { Random(state.hashCode() * 31 + (state.gameInfo?.turns?.hashCode() ?: 0)) }
|
||||
val stateBasedRandom by lazy {
|
||||
var seed = state.gameInfo?.turns?.hashCode() ?: 0
|
||||
seed = seed * 31 + (unique?.hashCode() ?: 0)
|
||||
seed = seed * 31 + state.hashCode()
|
||||
Random(seed)
|
||||
}
|
||||
|
||||
/** Helper to simplify conditional tests requiring gameInfo */
|
||||
fun checkOnGameInfo(predicate: (GameInfo.() -> Boolean)): Boolean {
|
||||
|
@ -106,10 +106,10 @@ data class StateForConditionals(
|
||||
fun CombatAction?.hash() = this?.name?.hashCode() ?: 0
|
||||
fun Region?.hash() = this?.rect?.hashCode() ?: 0
|
||||
|
||||
var result = civInfo.hash()
|
||||
result = 31 * result + city.hash()
|
||||
result = 31 * result + unit.hash()
|
||||
result = 31 * result + tile.hash()
|
||||
var result = relevantCiv.hash()
|
||||
result = 31 * result + relevantCity.hash()
|
||||
result = 31 * result + relevantUnit.hash()
|
||||
result = 31 * result + relevantTile.hash()
|
||||
result = 31 * result + ourCombatant.hash()
|
||||
result = 31 * result + theirCombatant.hash()
|
||||
result = 31 * result + attackedTile.hash()
|
||||
|
Loading…
x
Reference in New Issue
Block a user