Auto-Carousel, Standings mit Spieler, Runden-Tracker, Item-Rail links, sinnvoller Item-Pool

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
team3
2026-07-23 06:18:07 +02:00
parent 885bf28fd4
commit 76acd026ec
9 changed files with 169 additions and 51 deletions

View File

@@ -20,7 +20,7 @@ def client(monkeypatch):
def test_full_game_via_api(client):
state = client.post("/api/game", params={"seed": 3}).json()
game_id = state["game_id"]
assert state["round"]["label"] == "1-1"
assert state["round"]["label"] == "1-2" # 1-1-Carousel läuft automatisch ab
assert state["player"]["hp"] == 100
assert len(state["opponents"]) == 7

View File

@@ -78,7 +78,7 @@ def test_invalid_actions_raise(art, cfg):
with pytest.raises(InvalidAction):
game.buy_xp()
with pytest.raises(InvalidAction):
game.sell("bench", 0)
game.sell("bench", 99)
def test_shop_lock_survives_step(art, cfg):
@@ -87,3 +87,19 @@ def test_shop_lock_survives_step(art, cfg):
before = list(game.shop)
game.step()
assert game.shop == before
def test_carousel_never_a_planning_round(art, cfg):
game = Game(art, cfg, seed=5)
seen = []
while not game.over:
seen.append(game.round["kind"])
game.step()
assert "carousel" not in seen
assert seen[0] == "pve" # Spiel startet bei 1-2
def test_carousel_grants_unit_and_loot(art, cfg):
game = Game(art, cfg, seed=5)
assert len(game.bench) == 1 # Unit vom 1-1-Carousel
assert len(game.items) == 1 # Item-Komponente vom Carousel

View File

@@ -74,3 +74,15 @@ def test_spearman():
assert spearman([1, 2, 3, 4], [10, 20, 30, 40]) == pytest.approx(1.0)
assert spearman([1, 2, 3, 4], [40, 30, 20, 10]) == pytest.approx(-1.0)
assert spearman([1, 2, 3, 4], [10, 10, 10, 10]) == 0.0
def test_craftable_item_pool():
from tft.model.artifact import craftable_items
items = {
"TFT_Item_InfinityEdge": {"composition": ["TFT_Item_BFSword", "TFT_Item_SparringGloves"]},
"TFT_Item_BFSword": {"composition": []},
"TFT_Item_Emblem": {"composition": ["TFT_Item_Spatula", "TFT_Item_BFSword"]},
"TFT17_Item_Weird": {"composition": ["TFT_Item_BFSword", "TFT_Item_BFSword"]},
"TFT_Item_Radiant": {"composition": None},
}
assert craftable_items(items) == ["TFT_Item_InfinityEdge"]

View File

@@ -143,6 +143,11 @@ def serialize(game: Game) -> dict:
return {
"round": {"label": game.round["label"], "stage": stage,
"kind": game.round["kind"]},
"stage_rounds": [
{"label": r["label"], "kind": r["kind"], "augment": r["augment"],
"done": i < game.idx, "current": i == game.idx}
for i, r in enumerate(game.rounds) if r["stage"] == stage
],
"player": {
"hp": game.hp, "gold": game.gold, "level": game.level, "xp": game.xp,
"xp_needed": game.cfg["xp"]["to_next"][game.level - 1]

View File

@@ -8,6 +8,23 @@ from tft.model import baseline
SCHEMA_VERSION = 1
# Spatula/Pfanne-Rezepte (Embleme) fallen aus dem normalen Loot raus.
SPATULA_COMPONENTS = {"TFT_Item_Spatula", "TFT_Item_FryingPan"}
def craftable_items(static_items: dict) -> list[str]:
"""Standard-kombinierbare Items — der Pool für Loot und Bot-Boards."""
pool = []
for api, item in static_items.items():
comp = item.get("composition") or []
if (
len(comp) == 2
and api.startswith("TFT_Item_")
and not set(comp) & SPATULA_COMPONENTS
):
pool.append(api)
return sorted(pool)
def build(static: dict, learned: dict | None = None, extra_meta: dict | None = None) -> dict:
roles = {
@@ -28,6 +45,7 @@ def build(static: dict, learned: dict | None = None, extra_meta: dict | None = N
"augments": static["augments"],
},
"roles": roles,
"item_pool": craftable_items(static["items"]),
"learned": learned or {},
}

View File

@@ -50,7 +50,7 @@ class Bot:
level = self.level(stage)
odds = cfg["shop"]["odds"][min(level, len(cfg["shop"]["odds"])) - 1]
p_2star = min(0.08 * stage, 0.55)
items = list(artifact["static"]["items"])
items = artifact.get("item_pool") or list(artifact["static"]["items"])
n_items = max(stage - 1, 0)
for _ in range(level):

View File

@@ -46,6 +46,10 @@ class Game:
self.bots = [
Bot(names[i], archetypes[i % len(archetypes)], self.hp) for i in range(7)
]
# 1-1-Carousel läuft automatisch ab: Unit + Loot, dann startet 1-2.
if self.round["kind"] == "carousel":
self._resolve(self.round)
self.idx += 1
self._refresh_bots()
self._reroll_shop()
self._maybe_offer_augment()
@@ -84,7 +88,7 @@ class Game:
self.augment_offer = self.rng.sample(augments, min(3, len(augments)))
def _grant_loot(self, components: int, gold: int) -> None:
items = list(self.artifact["static"]["items"])
items = self.artifact.get("item_pool") or list(self.artifact["static"]["items"])
for _ in range(components):
self.items.append(self.rng.choice(items))
self.gold += gold
@@ -207,13 +211,27 @@ class Game:
self.level, self.xp, self.cfg["xp"]["passive_per_round"], self.cfg
)
if self.idx + 1 >= len(self.rounds):
self._finish_by_hp()
return
prev_stage = rnd["stage"]
self.idx += 1
if self.round["stage"] != prev_stage:
self._refresh_bots()
self._advance()
def _advance(self) -> None:
"""Zur nächsten Planungsrunde; Carousels laufen dabei automatisch ab."""
while True:
if self.idx + 1 >= len(self.rounds):
self._finish_by_hp()
return
prev_stage = self.round["stage"]
self.idx += 1
if self.round["stage"] != prev_stage:
self._refresh_bots()
if self.round["kind"] != "carousel":
break
self._resolve(self.round)
self.gold += economy.round_income(
self.gold, self.streak, False, self.round["label"], self.cfg
)
self.level, self.xp = economy.apply_xp(
self.level, self.xp, self.cfg["xp"]["passive_per_round"], self.cfg
)
if not self.shop_locked:
self._reroll_shop()
self._maybe_offer_augment()