Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add pre-commit #56

Merged
merged 3 commits into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 14 additions & 0 deletions .github/workflows/pre-commit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: pre-commit/[email protected]
12 changes: 12 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
repos:
- repo: https://github.com/crate-ci/typos
rev: v1.17.2
hooks:
- id: typos

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.14
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
30 changes: 15 additions & 15 deletions http_log_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import logging


logging.basicConfig(level = logging.INFO)
logging.basicConfig(level=logging.INFO)


if __name__ == '__main__':
log_path = 'logs.json'
if __name__ == "__main__":
log_path = "logs.json"
if len(sys.argv) > 1:
log_path = sys.argv[1]
log_str = open(log_path).read()
agents, match = read_log(log_str, use_16_omni = None)
agents, match = read_log(log_str, use_16_omni=None)
# for i in range(2):
# characters = match.player_tables[i].player_deck_information.characters # noqa: E501
# for c in characters:
Expand All @@ -22,18 +22,18 @@
try:
interact_match_with_agents(agents[0], agents[1], match)
except Exception:
print('!!!!! ERROR: play log failed, play to last success log. !!!!!')
print("!!!!! ERROR: play log failed, play to last success log. !!!!!")
server = HTTPServer(
decks = ['', ''],
match_config = MatchConfig(
check_deck_restriction = False,
card_number = None,
max_same_card_number = None,
character_number = None,
max_round_number = 999,
random_first_player = False,
history_level = 10,
)
decks=["", ""],
match_config=MatchConfig(
check_deck_restriction=False,
card_number=None,
max_same_card_number=None,
character_number=None,
max_round_number=999,
random_first_player=False,
history_level=10,
),
)
server.match = match

Expand Down
16 changes: 8 additions & 8 deletions http_room_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
from src.lpsim.network.http_room_server import HTTPRoomServer


if __name__ == '__main__':
if __name__ == "__main__":
room_server = HTTPRoomServer(
max_rooms = 3,
port = 7999,
room_port_range = [8001, 8010],
room_timeout = 300,
admin_password = 'foobar',
run_args = {}
max_rooms=3,
port=7999,
room_port_range=[8001, 8010],
room_timeout=300,
admin_password="foobar",
run_args={},
)
room_server.run()
print('server closed')
print("server closed")
36 changes: 18 additions & 18 deletions http_test_serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
import logging


logging.basicConfig(level = logging.INFO)
logging.basicConfig(level=logging.INFO)


if __name__ == '__main__':
deck_str_1 = '''
if __name__ == "__main__":
deck_str_1 = """
default_version:4.2
character:Baizhu
character:Nilou
character:Tighnari
All Things Are of the Earth*15
Lotus Flower Crisp*15
'''
deck_str_2 = '''
"""
deck_str_2 = """
character:[email protected]
character:Rhodeia of [email protected]
character:[email protected]
Expand All @@ -37,27 +37,27 @@
Send [email protected]
Lotus Flower [email protected]
Magic [email protected]*15
'''
"""
server = HTTPServer(
decks = [deck_str_1, deck_str_1],
match_config = MatchConfig(
check_deck_restriction = False,
card_number = None,
max_same_card_number = None,
character_number = None,
max_round_number = 999,
random_first_player = False,
decks=[deck_str_1, deck_str_1],
match_config=MatchConfig(
check_deck_restriction=False,
card_number=None,
max_same_card_number=None,
character_number=None,
max_round_number=999,
random_first_player=False,
# max_hand_size = 999,
# recreate_mode = True,
history_level = 10,
history_level=10,
# make_skill_prediction = True,
# random_object_information = {
# 'rhodeia': [
# 'squirrel', 'raptor', 'frog', 'squirrel', 'raptor',
# 'squirrel', 'raptor', 'frog', 'squirrel', 'raptor',
# 'frog', 'frog', 'squirrel', 'squirrel'
# ],
# }
)
),
)

# # modify hp
Expand All @@ -67,7 +67,7 @@
# character.max_hp = 40

# fix random seed
match = Match(random_state = get_random_state())
match = Match(random_state=get_random_state())
match.set_deck(server.decks)
match.config = server.match.config

Expand Down
25 changes: 12 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@


class Main(BaseModel):
"""
"""
""" """

version: str = '1.0.0'
name: Literal['GITCG'] = 'GITCG'
version: str = "1.0.0"
name: Literal["GITCG"] = "GITCG"
match: Match = Match()


if __name__ == '__main__':
logging.basicConfig(level = logging.WARNING)
agent_0 = RandomAgent(player_idx = 0)
agent_1 = RandomAgent(player_idx = 1)
if __name__ == "__main__":
logging.basicConfig(level=logging.WARNING)
agent_0 = RandomAgent(player_idx=0)
agent_1 = RandomAgent(player_idx=1)
main = Main()
deck = Deck.from_str(
'''
"""
default_version:4.1
character:Rhodeia of Loch
character:Kamisato Ayaka
Expand All @@ -33,7 +32,7 @@ class Main(BaseModel):
Abyssal Summons*5
Fatui Conspiracy*5
Timmie*5
'''
"""
)
main.match.set_deck([deck, deck])
main.match.config.max_same_card_number = 30
Expand All @@ -51,11 +50,11 @@ class Main(BaseModel):
elif main.match.need_respond(1):
current_agent = agent_1
else:
raise RuntimeError('no agent need to respond')
raise RuntimeError("no agent need to respond")
resp = current_agent.generate_response(main.match)
assert resp is not None
main.match.respond(resp)
main.match.step()

main.match.get_history_json(filename = 'logs.txt')
print('game end, save to logs.txt')
main.match.get_history_json(filename="logs.txt")
print("game end, save to logs.txt")
5 changes: 4 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,7 @@ local_scheme = "no-local-version"
files.extend-exclude = ["/src/lpsim/utils/deck_code_data.json"]

[tool.typos.default.extend-words]
Invokation = "Invokation"
Invokation = "Invokation"

[tool.ruff]
exclude = ["templates"]
9 changes: 6 additions & 3 deletions src/lpsim/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from .server.deck import Deck # noqa: F401
from .server.match import Match, MatchState # noqa: F401
from .utils import ( # noqa: F401
register_class, DescDictType, update_desc, deck_str_to_deck_code,
deck_code_to_deck_str
register_class,
DescDictType,
update_desc,
deck_str_to_deck_code,
deck_code_to_deck_str,
)


try:
from ._version import __version__, __version_tuple__ # type: ignore
except ModuleNotFoundError:
__version__ = 'unknown'
__version__ = "unknown"
__version_tuple__ = (0, 0, 0)
1 change: 1 addition & 0 deletions src/lpsim/agents/agent_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class AgentBase(BaseModel):
"""
Base class of all agents.
"""

player_idx: int

def generate_response(self, match: Match) -> Responses | None:
Expand Down
Loading
Loading