Skip to content

Commit

Permalink
🏞️ Solvers: Support Duet game type
Browse files Browse the repository at this point in the history
  • Loading branch information
asaf-kali committed Nov 19, 2024
1 parent d1c85a7 commit 13de55f
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ check-mypy:
mypy .

check-pylint:
pylint solvers/ --fail-under=9.68
pylint solvers/ --fail-under=10

lint: format
pre-commit run --all-files
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ all = ["openai"]
# Core
python = "^3.12,<3.13"
the-spymaster-util = { version = "~3.2", extras = ["logging"] }
codenames = ">=5.0.4,<5.1"
codenames = ">=5.1.2"
pydantic = ">=2.4"
# Numbers
numpy = "^1.21"
Expand Down Expand Up @@ -122,8 +122,8 @@ disable = [
]
extension-pkg-allow-list = ["pydantic"]
ignore = [
"sna_hinter.py",
"solvers/sna",
"solvers/olympic",
"algebra.py",
"olympic_hinter.py",
"board_heuristics.py",
]
2 changes: 1 addition & 1 deletion solvers/gpt/gpt_spymaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from codenames.generic.move import Clue, GivenClue
from codenames.generic.player import Spymaster, Team
from codenames.generic.state import SpymasterState
from codenames.resources.english import ENGLISH_WORDS
from codenames.utils.vocabulary.english import ENGLISH_WORDS

from solvers.gpt.gpt_player import (
HINTER_TURN_COMMAND,
Expand Down
13 changes: 11 additions & 2 deletions solvers/naive/naive_spymaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import numpy as np
from codenames.classic.color import ClassicColor
from codenames.classic.state import ClassicState
from codenames.classic.state import ClassicPlayerState
from codenames.duet.card import DuetColor
from codenames.duet.state import DuetPlayerState
from codenames.generic.board import Board
from codenames.generic.move import Clue
from codenames.generic.player import Spymaster, Team
Expand Down Expand Up @@ -116,11 +118,18 @@ def give_clue(


def _get_proposal_colors(state: PlayerState) -> ProposalColors:
if isinstance(state, ClassicState):
if isinstance(state, ClassicPlayerState):
return ProposalColors(
team=state.current_team.as_card_color,
opponent=state.current_team.opponent.as_card_color,
neutral=ClassicColor.NEUTRAL,
assassin=ClassicColor.ASSASSIN,
)
if isinstance(state, DuetPlayerState):
return ProposalColors(
team=state.current_team.as_card_color,
opponent=None,
neutral=DuetColor.NEUTRAL,
assassin=DuetColor.ASSASSIN,
)
raise NotImplementedError(f"Unsupported state type: {type(state)}")
Empty file added tests/resources/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions tests/resources/resource_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os

RESOURCE_DIR = os.path.join(os.path.dirname(__file__))


def get_resource_path(resource_name: str) -> str:
return os.path.join(RESOURCE_DIR, resource_name)
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions tests/test_naive_flow_classical.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

from solvers.naive.naive_operative import NaiveOperative
from solvers.naive.naive_spymaster import NaiveSpymaster
from tests.words import ALL_WORDS
from tests.resources.resource_manager import get_resource_path
from tests.resources.words import ALL_WORDS

VECTORS_FILE_NAME = "tests/small_model.csv"
VECTORS_FILE_NAME = get_resource_path("small_model.csv")


def mock_load_word2vec_format(*args, **kwargs):
Expand Down
26 changes: 13 additions & 13 deletions utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
def configure_logging(
formatter: Optional[str] = None, level: Optional[str] = None, mute_solvers: bool = False, mute_online: bool = True
):
handlers = {
"file": {
"class": "logging.FileHandler",
"filename": "run.log",
"formatter": "debug",
},
}
# handlers = {
# "file": {
# "class": "logging.FileHandler",
# "filename": "run.log",
# "formatter": "debug",
# },
# }
loggers = {
"selenium": {"level": "INFO"},
"urllib3": {"level": "INFO"},
Expand All @@ -24,14 +24,14 @@ def configure_logging(
dict_config = get_dict_config(
std_formatter=formatter,
root_log_level=level,
extra_handlers=handlers,
# extra_handlers=handlers,
extra_loggers=loggers,
)
dict_config["root"]["handlers"].append("file")
# dict_config["root"]["handlers"].append("file")

if mute_solvers:
dict_config["loggers"]["solvers"] = {"handlers": ["file"], "propagate": False} # type: ignore
if mute_online:
dict_config["loggers"]["codenames.online"] = {"handlers": ["file"], "propagate": False} # type: ignore
# if mute_solvers:
# dict_config["loggers"]["solvers"] = {"handlers": ["file"], "propagate": False} # type: ignore
# if mute_online:
# dict_config["loggers"]["codenames.online"] = {"handlers": ["file"], "propagate": False} # type: ignore
dictConfig(dict_config)
print("Logging configured.")

0 comments on commit 13de55f

Please sign in to comment.