mirror of
https://github.com/RichieCahill/dotfiles.git
synced 2026-04-17 04:58:19 -04:00
added more options for simulat.py
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
"""Splendor game."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
|||||||
@@ -1,26 +1,45 @@
|
|||||||
|
"""Simulator for Splendor game."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from .base import GameConfig, create_random_nobles, create_random_cards, new_game, run_game
|
from collections import defaultdict
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from .base import GameConfig, load_cards, load_nobles, new_game, run_game
|
||||||
from .bot import RandomBot
|
from .bot import RandomBot
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
"""Main entry point."""
|
"""Main entry point."""
|
||||||
turn_limit = 10000
|
turn_limit = 1000
|
||||||
for _ in range(1000):
|
good_games = 0
|
||||||
|
games = 10000
|
||||||
|
winners: dict[str, int] = defaultdict(int)
|
||||||
|
game_data = Path(__file__).parent / "game_data"
|
||||||
|
|
||||||
|
cards = load_cards(game_data / "cards/default.json")
|
||||||
|
nobles = load_nobles(game_data / "nobles/default.json")
|
||||||
|
|
||||||
|
for _ in range(games):
|
||||||
bot_a = RandomBot("bot_a")
|
bot_a = RandomBot("bot_a")
|
||||||
bot_b = RandomBot("bot_b")
|
bot_b = RandomBot("bot_b")
|
||||||
bot_c = RandomBot("bot_c")
|
bot_c = RandomBot("bot_c")
|
||||||
bot_d = RandomBot("bot_d")
|
bot_d = RandomBot("bot_d")
|
||||||
config = GameConfig(
|
config = GameConfig(
|
||||||
cards=create_random_cards(),
|
cards=cards,
|
||||||
nobles=create_random_nobles(),
|
nobles=nobles,
|
||||||
turn_limit=turn_limit,
|
turn_limit=turn_limit,
|
||||||
)
|
)
|
||||||
players = (bot_a, bot_b, bot_c, bot_d)
|
players = (bot_a, bot_b, bot_c, bot_d)
|
||||||
game_state = new_game(players, config)
|
game_state = new_game(players, config)
|
||||||
winner, turns = run_game(game_state)
|
winner, turns = run_game(game_state)
|
||||||
print(f"Winner is {winner.strategy.name} with {winner.score} points after {turns} turns.")
|
if turns < turn_limit:
|
||||||
|
good_games += 1
|
||||||
|
winners[winner.strategy.name] += 1
|
||||||
|
|
||||||
|
print(f"out of {games} {turn_limit} turn games with 4 random bots there where {good_games} games where a bot won")
|
||||||
|
for k, v in winners.items():
|
||||||
|
print(f"{k} won {v}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user