Skip to content

Commit

Permalink
implement fight decision maker
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmiglio committed Sep 15, 2024
1 parent 35d7459 commit cb539ff
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 12 deletions.
47 changes: 46 additions & 1 deletion poetry.lock

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

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ repository = "https://github.com/pyclashbot/clash-net-lib"

[tool.poetry.dependencies]
python = "^3.12"
numpy = "^1"


[tool.poetry.group.dev]
Expand Down
2 changes: 2 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Entry point for the package."""

from . import implements
from .decision_maker import Decision, DecisionInput, DecisionInputValue, DecisionMaker, DecisionName, DecisionValue

__all__ = [
Expand All @@ -9,4 +10,5 @@
"DecisionInputValue",
"DecisionValue",
"DecisionMaker",
"implements",
]
24 changes: 13 additions & 11 deletions src/decision_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
This module provides high-level classes for handling a decision-making process.
"""

from __future__ import annotations

from typing import TypeVar

DecisionName = str
Expand Down Expand Up @@ -40,7 +42,7 @@ def __str__(self) -> str:
str: The name and value of the decision input.
"""
return self.name + " : " + str(self.value)
return f"{self.name} : {self.value!s}"

def __repr__(self) -> str:
"""Return the official string representation of the DecisionInput.
Expand Down Expand Up @@ -83,7 +85,7 @@ def __str__(self) -> str:
str: The name and value of the decision.
"""
return self.name + " : " + str(self.value)
return f"{self.name} : {self.value!s}"

def __repr__(self) -> str:
"""Return the official string representation of the Decision.
Expand All @@ -96,32 +98,32 @@ def __repr__(self) -> str:
return self.__str__()


class DecisionMaker[DecisionInputValue, DecisionValue]:
class DecisionMaker[DecisionInput, Decision]:
"""Manages decision inputs and generates decisions.
Attributes
----------
inputs (list[DecisionInput[DecisionInputValue]]): The list of inputs to the decision-making process.
decisions (list[Decision[DecisionValue]]): The list of decisions made.
inputs (list[DecisionInput]): The list of inputs to the decision-making process.
decisions (list[Decision]): The list of decisions made.
"""

def __init__(self) -> None:
"""Initialize a DecisionMaker instance."""
self.inputs: list[DecisionInput[DecisionInputValue]] = []
self.decisions: list[Decision[DecisionValue]] = []
self.inputs: list[DecisionInput] = []
self.decisions: list[Decision] = []

def add_input(self, decision_input: DecisionInput[DecisionInputValue]) -> None:
def add_input(self, decision_input: DecisionInput) -> None:
"""Add an input to the decision-making process.
Args:
----
decision_input (DecisionInput[DecisionInputValue]): The decision input to be added.
decision_input (DecisionInput): The decision input to be added.
"""
self.inputs.append(decision_input)

def make_decision(self) -> Decision[DecisionValue]:
def make_decision(self) -> Decision | None:
"""Generate a decision based on the inputs.
Raises
Expand All @@ -130,7 +132,7 @@ def make_decision(self) -> Decision[DecisionValue]:
Returns
-------
Decision[DecisionValue]: The decision based on the inputs (when implemented).
Decision | None: The decision based on the inputs (when implemented).
"""
msg = "make_decision method is not implemented"
Expand Down
5 changes: 5 additions & 0 deletions src/implements/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""Implementations of the decision makers."""

import fight_decision_maker

__all__ = ["fight_decision_maker"]
56 changes: 56 additions & 0 deletions src/implements/fight_decision_maker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""An implementation of the DecisionMaker class for making decisions during a fight."""

from __future__ import annotations

from typing import TypedDict

import numpy as np

from src.decision_maker import Decision, DecisionInput, DecisionMaker

FightDecisionInputValue = np.ndarray

name = "Fight Decision"


class FightDecisionValue(TypedDict):
"""Represents the value of a fight decision."""

cardIndex: int | None
location: tuple[int, int] | None


class FightDecisionInput(DecisionInput[FightDecisionInputValue]):
"""Represents an input to a fight decision-making process."""

def __init__(self, value: FightDecisionInputValue) -> None:
"""Initialize a FightDecisionInput instance.
Args:
----
value (FightDecisionInputValue): The value of the fight decision input.
"""
super().__init__(name, value)


class FightDecision(Decision[FightDecisionValue]):
"""Represents a decision made during a fight."""

def __init__(self, value: FightDecisionValue) -> None:
"""Initialize a FightDecision instance.
Args:
----
value (FightDecisionValue): The value of the fight decision.
"""
super().__init__(name, value)


class FightDecisionMaker(DecisionMaker[FightDecisionInputValue, FightDecisionValue]):
"""An implementation of the DecisionMaker class for making decisions during a fight."""

def __init__(self) -> None:
"""Initialize a FightDecisionMaker instance."""
super().__init__()

0 comments on commit cb539ff

Please sign in to comment.