-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
201 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from enum import Enum | ||
|
||
class ReactionType(Enum): | ||
NOTHING = 0 | ||
DODGE = 1 | ||
FIGHT_BACK = 2 | ||
|
||
class ReactionStrategy: | ||
def reply(self, character: "Character", attacker: "Character") -> ReactionType: | ||
raise NotImplementedError() | ||
|
||
class NothingReactionStrategy(ReactionStrategy): | ||
def reply(self, character: "Character", attacker: "Character") -> ReactionType: | ||
return ReactionType.NOTHING | ||
|
||
class DodgeReactionStrategy(ReactionStrategy): | ||
def reply(self, character: "Character", attacker: "Character") -> ReactionType: | ||
return ReactionType.DODGE | ||
|
||
class FightBackReactionStrategy(ReactionStrategy): | ||
def reply(self, character: "Character", attacker: "Character") -> ReactionType: | ||
return ReactionType.FIGHT_BACK |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import random | ||
|
||
from ..skill import Skill | ||
from ..dice_parser import DiceParser | ||
|
||
class SkillSelectionStrategy: | ||
def select_skill(self, character: "Character") -> Skill: | ||
raise NotImplementedError() | ||
|
||
class RandomSkillSelectionStrategy(SkillSelectionStrategy): | ||
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: | ||
return max(character.skills, key=lambda skill: skill.success_rate / 100 * ExpectedDamageMaximizationSkillSelectionStrategy.dice_parser.expected(skill.damage)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import random | ||
from typing import List | ||
|
||
class TargetSelectionStrategy: | ||
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": | ||
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": | ||
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": | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ply==3.11 | ||
tqdm==4.64.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import unittest | ||
from coc7e_combat_simulator.strategies.skill_selection import ExpectedDamageMaximizationSkillSelectionStrategy | ||
from coc7e_combat_simulator.character import Character | ||
from coc7e_combat_simulator.skill import Skill | ||
|
||
class TestSkillSelection(unittest.TestCase): | ||
def setUp(self): | ||
self.strategy = ExpectedDamageMaximizationSkillSelectionStrategy() | ||
|
||
def test_select_skill_damage(self): | ||
skill1 = Skill("Skill1", 50, "2d6+3", False) | ||
skill2 = Skill("Skill2", 50, "1d8+2", True) | ||
skill3 = Skill("Skill3", 50, "3d4+1", False) | ||
character = Character.of_random("Test", skills=[skill1, skill2, skill3]) | ||
|
||
selected_skill = self.strategy.select_skill(character) | ||
self.assertEqual(selected_skill, skill1) | ||
|
||
def test_select_skill_chance(self): | ||
skill1 = Skill("Skill1", 10, "3D6", False) | ||
skill2 = Skill("Skill2", 20, "3D6", True) | ||
skill3 = Skill("Skill3", 30, "3D6", False) | ||
character = Character.of_random("Test", skills=[skill1, skill2, skill3]) | ||
|
||
selected_skill = self.strategy.select_skill(character) | ||
self.assertEqual(selected_skill, skill3) | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.