This commit is contained in:
Auric Vente 2024-07-22 09:43:54 -06:00
parent bb9606bb46
commit bc928dc8d6
2 changed files with 36 additions and 20 deletions

View File

@ -148,7 +148,7 @@ class Ants:
weights = [1] * len(Ants.ants) # If all ages are zero, use equal weights weights = [1] * len(Ants.ants) # If all ages are zero, use equal weights
else: else:
weights = [ weights = [
int(age / total_age * 1000) for age in ages int((age / total_age) * 1000) for age in ages
] # Scale and cast to int ] # Scale and cast to int
# Perform weighted random selection # Perform weighted random selection

View File

@ -36,9 +36,11 @@ class Method:
sentence_3 = 8 sentence_3 = 8
sentence_4 = 9 sentence_4 = 9
Opts = tuple[list[int], list[int]]
@staticmethod @staticmethod
def opts_all() -> list[int]: def opts_all() -> Opts:
return [ opts = [
Method.triumph, Method.triumph,
Method.hit, Method.hit,
Method.travel, Method.travel,
@ -50,27 +52,39 @@ class Method:
Method.sentence_4, Method.sentence_4,
] ]
@staticmethod weights = [2, 2, 2, 2, 2, 3, 3, 3, 3]
def opts_score() -> list[int]: return opts, weights
return [Method.triumph, Method.hit]
@staticmethod @staticmethod
def opts_travel() -> list[int]: def opts_score() -> Opts:
return [Method.travel] opts = [Method.triumph, Method.hit]
weights = [2, 2]
return opts, weights
@staticmethod @staticmethod
def opts_thought() -> list[int]: def opts_travel() -> Opts:
return [Method.thinking_1, Method.thinking_2] opts = [Method.travel]
weights = [2]
return opts, weights
@staticmethod @staticmethod
def opts_words() -> list[int]: def opts_thought() -> Opts:
return [ opts = [Method.thinking_1, Method.thinking_2]
weights = [2, 2]
return opts, weights
@staticmethod
def opts_words() -> Opts:
opts = [
Method.sentence_1, Method.sentence_1,
Method.sentence_2, Method.sentence_2,
Method.sentence_3, Method.sentence_3,
Method.sentence_4, Method.sentence_4,
] ]
weights = [2, 2, 2, 2]
return opts, weights
class Game: class Game:
timer: QTimer | None = None timer: QTimer | None = None
@ -237,27 +251,29 @@ class Game:
return return
mode = Settings.mode mode = Settings.mode
opts: list[int] nums: list[int]
weights: list[int]
if mode == "all": if mode == "all":
opts = Method.opts_all() nums, weights = Method.opts_all()
elif mode == "score": elif mode == "score":
opts = Method.opts_score() nums, weights = Method.opts_score()
elif mode == "travel": elif mode == "travel":
opts = Method.opts_travel() nums, weights = Method.opts_travel()
elif mode == "thought": elif mode == "thought":
opts = Method.opts_thought() nums, weights = Method.opts_thought()
elif mode == "words": elif mode == "words":
opts = Method.opts_words() nums, weights = Method.opts_words()
else: else:
return return
Game.merge_charge += 1 Game.merge_charge += 1
if Game.merge_charge >= Config.merge_goal: if Game.merge_charge >= Config.merge_goal:
opts.insert(0, Method.merge) nums.insert(0, Method.merge)
weights.insert(0, 1)
num = random.choice(opts) num = random.choices(nums, weights=weights, k=1)[0]
if num == Method.merge: if num == Method.merge:
if Ants.merge(): if Ants.merge():