FastGameState를 기본 게임 상태로 전환
This commit is contained in:
@@ -7,6 +7,14 @@ from coolrl_lost_cities.games.classic.bots import (
|
||||
)
|
||||
from coolrl_lost_cities.games.classic.bots.heuristic import draw_from_discard_action
|
||||
from coolrl_lost_cities.games.classic.evaluation import play_game_for_evaluation
|
||||
from tests.games.classic.helpers import make_state
|
||||
|
||||
|
||||
def _expeditions(config: LostCitiesConfig) -> list[list[list[Card]]]:
|
||||
return [
|
||||
[[] for _ in range(config.n_colors)],
|
||||
[[] for _ in range(config.n_colors)],
|
||||
]
|
||||
|
||||
|
||||
def test_builtin_bots_implement_lost_cities_bot() -> None:
|
||||
@@ -31,15 +39,26 @@ def test_safe_heuristic_opponent_value_ignores_hidden_hand() -> None:
|
||||
bot = SafeHeuristicBot()
|
||||
discard_card = Card(color=0, rank=6)
|
||||
|
||||
state_a = GameState.empty(config)
|
||||
state_a.expeditions[1][0] = [Card(color=0, rank=0), Card(color=0, rank=4)]
|
||||
state_a.discards[0] = [discard_card]
|
||||
state_a.hands[1] = [Card(color=0, rank=5)]
|
||||
expeditions_a = _expeditions(config)
|
||||
expeditions_a[1][0] = [Card(color=0, rank=0), Card(color=0, rank=4)]
|
||||
state_a = make_state(
|
||||
config,
|
||||
hands=[[], [Card(color=0, rank=5)]],
|
||||
expeditions=expeditions_a,
|
||||
discards=[[discard_card], []],
|
||||
)
|
||||
|
||||
state_b = GameState.empty(config)
|
||||
state_b.expeditions[1][0] = [Card(color=0, rank=0), Card(color=0, rank=4)]
|
||||
state_b.discards[0] = [discard_card]
|
||||
state_b.hands[1] = [Card(color=0, rank=5), Card(color=0, rank=7), Card(color=0, rank=8)]
|
||||
expeditions_b = _expeditions(config)
|
||||
expeditions_b[1][0] = [Card(color=0, rank=0), Card(color=0, rank=4)]
|
||||
state_b = make_state(
|
||||
config,
|
||||
hands=[
|
||||
[],
|
||||
[Card(color=0, rank=5), Card(color=0, rank=7), Card(color=0, rank=8)],
|
||||
],
|
||||
expeditions=expeditions_b,
|
||||
discards=[[discard_card], []],
|
||||
)
|
||||
|
||||
value_a = bot._card_value_for_opponent(
|
||||
state=state_a,
|
||||
@@ -62,13 +81,21 @@ def test_safe_heuristic_started_expedition_value_ignores_invalid_lower_followup(
|
||||
bot = SafeHeuristicBot()
|
||||
high_card = Card(color=0, rank=8)
|
||||
|
||||
base_state = GameState.empty(config)
|
||||
base_state.expeditions[0][0] = [Card(color=0, rank=4)]
|
||||
base_state.hands[0] = [high_card]
|
||||
base_expeditions = _expeditions(config)
|
||||
base_expeditions[0][0] = [Card(color=0, rank=4)]
|
||||
base_state = make_state(
|
||||
config,
|
||||
hands=[[high_card], []],
|
||||
expeditions=base_expeditions,
|
||||
)
|
||||
|
||||
lower_followup_state = GameState.empty(config)
|
||||
lower_followup_state.expeditions[0][0] = [Card(color=0, rank=4)]
|
||||
lower_followup_state.hands[0] = [Card(color=0, rank=5), high_card]
|
||||
lower_expeditions = _expeditions(config)
|
||||
lower_expeditions[0][0] = [Card(color=0, rank=4)]
|
||||
lower_followup_state = make_state(
|
||||
config,
|
||||
hands=[[Card(color=0, rank=5), high_card], []],
|
||||
expeditions=lower_expeditions,
|
||||
)
|
||||
|
||||
base_value = bot._started_expedition_play_value(
|
||||
state=base_state,
|
||||
@@ -92,12 +119,15 @@ def test_safe_heuristic_draws_playable_discard_instead_of_deck() -> None:
|
||||
config = LostCitiesConfig(n_colors=2, n_ranks=8, hand_size=3)
|
||||
bot = SafeHeuristicBot()
|
||||
|
||||
state = GameState.empty(config)
|
||||
state.current_player = 0
|
||||
state.phase = "draw"
|
||||
state.expeditions[0][0] = [Card(color=0, rank=4)]
|
||||
state.discards[0] = [Card(color=0, rank=6)]
|
||||
state.deck = [Card(color=1, rank=8)]
|
||||
expeditions = _expeditions(config)
|
||||
expeditions[0][0] = [Card(color=0, rank=4)]
|
||||
state = make_state(
|
||||
config,
|
||||
deck=[Card(color=1, rank=8)],
|
||||
expeditions=expeditions,
|
||||
discards=[[Card(color=0, rank=6)], []],
|
||||
phase="draw",
|
||||
)
|
||||
|
||||
assert bot._act_draw(state) == draw_from_discard_action(0)
|
||||
|
||||
@@ -106,20 +136,23 @@ def test_safe_heuristic_can_draw_discard_to_deny_opponent_when_losing() -> None:
|
||||
config = LostCitiesConfig(n_colors=2, n_ranks=8, hand_size=4)
|
||||
bot = SafeHeuristicBot()
|
||||
|
||||
state = GameState.empty(config)
|
||||
state.current_player = 0
|
||||
state.phase = "draw"
|
||||
state.deck = [Card(color=1, rank=8), Card(color=1, rank=7)]
|
||||
state.hands[0] = [Card(color=0, rank=0), Card(color=0, rank=7)]
|
||||
state.expeditions[0][1] = [Card(color=1, rank=8)]
|
||||
state.expeditions[1][0] = [
|
||||
expeditions = _expeditions(config)
|
||||
expeditions[0][1] = [Card(color=1, rank=8)]
|
||||
expeditions[1][0] = [
|
||||
Card(color=0, rank=0),
|
||||
Card(color=0, rank=5),
|
||||
Card(color=0, rank=6),
|
||||
Card(color=0, rank=7),
|
||||
Card(color=0, rank=8),
|
||||
]
|
||||
state.discards[0] = [Card(color=0, rank=6)]
|
||||
state = make_state(
|
||||
config,
|
||||
deck=[Card(color=1, rank=8), Card(color=1, rank=7)],
|
||||
hands=[[Card(color=0, rank=0), Card(color=0, rank=7)], []],
|
||||
expeditions=expeditions,
|
||||
discards=[[Card(color=0, rank=6)], []],
|
||||
phase="draw",
|
||||
)
|
||||
|
||||
assert state.score_diff(0) < 0
|
||||
assert bot._act_draw(state) == draw_from_discard_action(0)
|
||||
@@ -152,16 +185,17 @@ def test_safe_heuristic_classic_self_play_opens_expeditions() -> None:
|
||||
def test_safe_heuristic_avoids_opening_weak_fifth_color() -> None:
|
||||
config = LostCitiesConfig(n_colors=5, n_ranks=8, hand_size=8)
|
||||
bot = SafeHeuristicBot()
|
||||
state = GameState.empty(config)
|
||||
state.current_player = 0
|
||||
state.phase = "card"
|
||||
|
||||
state.expeditions[0][0] = [Card(color=0, rank=4)]
|
||||
state.expeditions[0][1] = [Card(color=1, rank=4)]
|
||||
state.expeditions[0][2] = [Card(color=2, rank=5)]
|
||||
state.expeditions[0][3] = [Card(color=3, rank=6)]
|
||||
expeditions = _expeditions(config)
|
||||
expeditions[0][0] = [Card(color=0, rank=4)]
|
||||
expeditions[0][1] = [Card(color=1, rank=4)]
|
||||
expeditions[0][2] = [Card(color=2, rank=5)]
|
||||
expeditions[0][3] = [Card(color=3, rank=6)]
|
||||
weak_open = Card(color=4, rank=4)
|
||||
state.hands[0] = [weak_open, Card(color=4, rank=7), Card(color=0, rank=6)]
|
||||
state = make_state(
|
||||
config,
|
||||
hands=[[weak_open, Card(color=4, rank=7), Card(color=0, rank=6)], []],
|
||||
expeditions=expeditions,
|
||||
)
|
||||
state.sort_hand(0)
|
||||
|
||||
assert (
|
||||
@@ -180,11 +214,16 @@ def test_safe_heuristic_avoids_opening_weak_fifth_color() -> None:
|
||||
def test_safe_heuristic_prefers_followup_on_started_expedition() -> None:
|
||||
config = LostCitiesConfig(n_colors=3, n_ranks=8, hand_size=5)
|
||||
bot = SafeHeuristicBot()
|
||||
state = GameState.empty(config)
|
||||
state.current_player = 0
|
||||
state.phase = "card"
|
||||
state.expeditions[0][0] = [Card(color=0, rank=4)]
|
||||
state.hands[0] = [Card(color=0, rank=6), Card(color=1, rank=4), Card(color=1, rank=7)]
|
||||
expeditions = _expeditions(config)
|
||||
expeditions[0][0] = [Card(color=0, rank=4)]
|
||||
state = make_state(
|
||||
config,
|
||||
hands=[
|
||||
[Card(color=0, rank=6), Card(color=1, rank=4), Card(color=1, rank=7)],
|
||||
[],
|
||||
],
|
||||
expeditions=expeditions,
|
||||
)
|
||||
state.sort_hand(0)
|
||||
|
||||
action = bot._act_card(state)
|
||||
@@ -197,15 +236,20 @@ def test_safe_heuristic_prefers_followup_on_started_expedition() -> None:
|
||||
def test_safe_heuristic_avoids_unopened_discard_draw_after_four_opens() -> None:
|
||||
config = LostCitiesConfig(n_colors=5, n_ranks=8, hand_size=8)
|
||||
bot = SafeHeuristicBot()
|
||||
state = GameState.empty(config)
|
||||
state.current_player = 0
|
||||
state.phase = "draw"
|
||||
state.deck = [Card(color=0, rank=8), Card(color=1, rank=8)]
|
||||
state.expeditions[0][0] = [Card(color=0, rank=4)]
|
||||
state.expeditions[0][1] = [Card(color=1, rank=4)]
|
||||
state.expeditions[0][2] = [Card(color=2, rank=5)]
|
||||
state.expeditions[0][3] = [Card(color=3, rank=6)]
|
||||
state.hands[0] = [Card(color=4, rank=4), Card(color=4, rank=7)]
|
||||
state.discards[4] = [Card(color=4, rank=5)]
|
||||
expeditions = _expeditions(config)
|
||||
expeditions[0][0] = [Card(color=0, rank=4)]
|
||||
expeditions[0][1] = [Card(color=1, rank=4)]
|
||||
expeditions[0][2] = [Card(color=2, rank=5)]
|
||||
expeditions[0][3] = [Card(color=3, rank=6)]
|
||||
discards = [[] for _ in range(config.n_colors)]
|
||||
discards[4] = [Card(color=4, rank=5)]
|
||||
state = make_state(
|
||||
config,
|
||||
deck=[Card(color=0, rank=8), Card(color=1, rank=8)],
|
||||
hands=[[Card(color=4, rank=4), Card(color=4, rank=7)], []],
|
||||
expeditions=expeditions,
|
||||
discards=discards,
|
||||
phase="draw",
|
||||
)
|
||||
|
||||
assert bot._act_draw(state) == 0
|
||||
|
||||
Reference in New Issue
Block a user