Skip to content

Commit

Permalink
Fix type circular dependency issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Liesegang committed Feb 27, 2024
1 parent 1833cb3 commit f30cb7f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 11 deletions.
12 changes: 8 additions & 4 deletions coc7e_combat_simulator/strategies/reaction.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
from enum import Enum

from typing import TYPE_CHECKING
if TYPE_CHECKING:
from ..character import Character

class ReactionType(Enum):
NOTHING = 0
DODGE = 1
FIGHT_BACK = 2

class ReactionStrategy:
def reply(self, character: "Character", attacker: "Character") -> ReactionType:
def reply(self, character: Character, attacker: Character) -> ReactionType:
raise NotImplementedError()

class NothingReactionStrategy(ReactionStrategy):
def reply(self, character: "Character", attacker: "Character") -> ReactionType:
def reply(self, character: Character, attacker: Character) -> ReactionType:
return ReactionType.NOTHING

class DodgeReactionStrategy(ReactionStrategy):
def reply(self, character: "Character", attacker: "Character") -> ReactionType:
def reply(self, character: Character, attacker: Character) -> ReactionType:
return ReactionType.DODGE

class FightBackReactionStrategy(ReactionStrategy):
def reply(self, character: "Character", attacker: "Character") -> ReactionType:
def reply(self, character: Character, attacker: Character) -> ReactionType:
return ReactionType.FIGHT_BACK
10 changes: 7 additions & 3 deletions coc7e_combat_simulator/strategies/skill_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
from ..skill import Skill
from ..dice_parser import DiceParser

from typing import TYPE_CHECKING
if TYPE_CHECKING:
from ..character import Character

class SkillSelectionStrategy:
def select_skill(self, character: "Character") -> Skill:
def select_skill(self, character: Character) -> Skill:
raise NotImplementedError()

class RandomSkillSelectionStrategy(SkillSelectionStrategy):
def select_skill(self, character: "Character") -> Skill:
def select_skill(self, character: Character) -> Skill:
return random.choice(character.skills)

class ExpectedDamageMaximizationSkillSelectionStrategy(SkillSelectionStrategy):
dice_parser = DiceParser()

def select_skill(self, character: "Character") -> Skill:
def select_skill(self, character: Character) -> Skill:
return max(character.skills, key=lambda skill: skill.success_rate / 100 * ExpectedDamageMaximizationSkillSelectionStrategy.dice_parser.expected(skill.damage))
12 changes: 8 additions & 4 deletions coc7e_combat_simulator/strategies/target_selection.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
import random
from typing import List

from typing import TYPE_CHECKING
if TYPE_CHECKING:
from ..character import Character

class TargetSelectionStrategy:
def select_target(self, character: "Character", characters: List["Character"]) -> "Character":
def select_target(self, character: Character, characters: List[Character]) -> Character:
raise NotImplementedError()

class RandomTargetSelectionStrategy(TargetSelectionStrategy):
def select_target(self, character: "Character", characters: List["Character"]) -> "Character":
def select_target(self, character: Character, characters: List[Character]) -> Character:
target_candidates = [target for target in characters if target.side != character.side and target.hp > 0]
return random.choice(target_candidates)

class MinimumHpTargetSelectionStrategy(TargetSelectionStrategy):
def select_target(self, character: "Character", characters: List["Character"]) -> "Character":
def select_target(self, character: Character, characters: List[Character]) -> Character:
target_candidates = [target for target in characters if target.side != character.side and target.hp > 0]
return min(target_candidates, key=lambda target: target.hp)

class MaximumHpTargetSelectionStrategy(TargetSelectionStrategy):
def select_target(self, character: "Character", characters: List["Character"]) -> "Character":
def select_target(self, character: Character, characters: List[Character]) -> Character:
target_candidates = [target for target in characters if target.side != character.side and target.hp > 0]
return max(target_candidates, key=lambda target: target.hp)

0 comments on commit f30cb7f

Please sign in to comment.