Refresh web UI and make ML imports optional
All checks were successful
ci / tests (push) Successful in 21s

This commit is contained in:
dan
2025-12-25 09:15:10 +03:00
parent f542747d5e
commit 2499deb071
49 changed files with 4367 additions and 500 deletions

View File

@@ -7,10 +7,26 @@ from catan.ml.agents import RandomAgent
from tests.utils import find_initial_spot
def _resolve_robber(controller: CLIController) -> None:
game = controller.game
board = game.board
for hex_id, tile in board.hexes.items():
if hex_id == board.robber_hex:
continue
victims = {
board.corners[corner].owner
for corner in tile.corners
if board.corners[corner].owner and board.corners[corner].owner != game.current_player.name
}
victim = next(iter(victims)) if victims else None
game.move_robber(hex_id, victim)
return
def test_human_vs_random_bot_session() -> None:
controller = CLIController(
Game(GameConfig(player_names=["Human", "Bot"], seed=9)),
bots={"Bot": RandomAgent(seed=3)},
Game(GameConfig(player_names=["Human", "Bot", "Companion"], seed=9)),
bots={"Bot": RandomAgent(seed=3), "Companion": RandomAgent(seed=5)},
)
# Complete setup: human manually places, bot uses random agent.
@@ -22,13 +38,16 @@ def test_human_vs_random_bot_session() -> None:
else:
controller._run_bot_turn(current) # noqa: SLF001 - exercising CLI internals
# Play a few turns: human rolls and ends, bot plays automatically.
for _ in range(3):
# Play a few rounds: human rolls and ends, bots play automatically.
for _ in range(2):
assert controller.game.current_player.name == "Human"
controller.handle_command("roll")
if controller.game.robber_move_required:
_resolve_robber(controller)
controller.handle_command("end")
assert controller.game.current_player.name == "Bot"
controller._run_bot_turn("Bot") # noqa: SLF001
for name in ("Bot", "Companion"):
assert controller.game.current_player.name == name
controller._run_bot_turn(name) # noqa: SLF001
# Ensure bot activity is recorded in history.
assert any(log.player == "Bot" for log in controller.game.history)
assert any(log.player in {"Bot", "Companion"} for log in controller.game.history)