Files
dockipelago/worlds/PokemonStadium/randomizer/randomizePokemonBaseValues.py
Jonathan Tinney 7971961166
Some checks failed
Analyze modified files / flake8 (push) Failing after 2m28s
Build / build-win (push) Has been cancelled
Build / build-ubuntu2204 (push) Has been cancelled
ctest / Test C++ ubuntu-latest (push) Has been cancelled
ctest / Test C++ windows-latest (push) Has been cancelled
Analyze modified files / mypy (push) Has been cancelled
Build and Publish Docker Images / Push Docker image to Docker Hub (push) Successful in 5m4s
Native Code Static Analysis / scan-build (push) Failing after 5m2s
type check / pyright (push) Successful in 1m7s
unittests / Test Python 3.11.2 ubuntu-latest (push) Failing after 16m23s
unittests / Test Python 3.12 ubuntu-latest (push) Failing after 28m19s
unittests / Test Python 3.13 ubuntu-latest (push) Failing after 14m49s
unittests / Test hosting with 3.13 on ubuntu-latest (push) Successful in 5m0s
unittests / Test Python 3.13 macos-latest (push) Has been cancelled
unittests / Test Python 3.11 windows-latest (push) Has been cancelled
unittests / Test Python 3.13 windows-latest (push) Has been cancelled
add schedule I, sonic 1/frontiers/heroes, spirit island
2026-04-02 23:46:36 -07:00

58 lines
1.9 KiB
Python

import random
from . import constants
class BaseValuesRandomizer:
@classmethod
def randomize_stats(cls, vanilla_stats, random_factor):
min_val = 20
max_val = 235
bst_list = []
for stat in vanilla_stats:
bst_list.append(stat)
bst = sum(bst_list)
new_stats_bytes = bytearray()
# Start with an array of 5 numbers, all at the minimum value
new_stats = [min_val] * 5
current_sum = sum(new_stats)
# Increment numbers until we reach BST
while current_sum < bst:
# Randomly select an index to increase
idx = cls.select_index(random_factor)
# Only increase if it won't exceed max_val
if new_stats[idx] < max_val:
new_stats[idx] += 1
current_sum += 1
else:
# Check if all numbers are maxed out (should never happen with correct BST input)
if all(n == max_val for n in new_stats):
raise RuntimeError("All stats reached max_val but BST is not yet met. Something went wrong!")
random.shuffle(new_stats)
for stat in new_stats:
try:
new_stats_bytes.extend(stat.to_bytes(1, "big"))
except OverflowError:
print("ERROR: BST is too high.")
print("BST_STR: " + str(vanilla_stats))
print("BST: " + str(bst))
print("STATS: " + str(new_stats))
exit(1)
return new_stats_bytes
@classmethod
def select_index(cls, random_factor):
random_factor = random_factor - 1
weight_map = {
1: constants.bst_weights[0] if random.random() < 0.5 else constants.bst_weights[1],
2: constants.bst_weights[2],
3: constants.bst_weights[3]
}
return random.choices([0, 1, 2, 3, 4], weights=weight_map.get(random_factor, constants.bst_weights[0]))[0]