-
Notifications
You must be signed in to change notification settings - Fork 41
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
21 changed files
with
145 additions
and
55 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,31 @@ | ||
from .action import Action | ||
from .archers_action import ArchersAction | ||
from .arrows_action import ArrowsAction | ||
from .bats_action import BatsAction | ||
from .cannon_action import CannonAction | ||
from .fireball_action import FireballAction | ||
from .giant_action import GiantAction | ||
from .goblin_barrel_action import GoblinBarrelAction | ||
from .hungry_dragon_action import HungryDragonAction | ||
from .knight_action import KnightAction | ||
from .minions_action import MinionsAction | ||
from .minipekka_action import MinipekkaAction | ||
from .musketeer_action import MusketeerAction | ||
from .witch_action import WitchAction | ||
from .zap_action import ZapAction | ||
|
||
__all__ = ["Action"] | ||
__all__ = [ | ||
"ArchersAction", | ||
"ArrowsAction", | ||
"BatsAction", | ||
"CannonAction", | ||
"FireballAction", | ||
"GiantAction", | ||
"GoblinBarrelAction", | ||
"HungryDragonAction", | ||
"KnightAction", | ||
"MinionsAction", | ||
"MinipekkaAction", | ||
"MusketeerAction", | ||
"WitchAction", | ||
"ZapAction", | ||
] |
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
Empty file.
File renamed without changes.
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,25 @@ | ||
from clashroyalebuildabot.actions.generic.action import Action | ||
|
||
|
||
class BridgeAction(Action): | ||
""" | ||
If you have 10 elixir, | ||
play this card at the bridge on the side of the weakest tower | ||
""" | ||
|
||
def calculate_score(self, state): | ||
if (self.tile_x, self.tile_y) not in {(3, 15), (14, 15)}: | ||
return [0] | ||
|
||
if state.numbers.elixir.number != 10: | ||
return [0] | ||
|
||
left_hp = state.numbers.left_enemy_princess_hp.number | ||
right_hp = state.numbers.right_enemy_princess_hp.number | ||
if self.tile_x == 3: | ||
score = [1, left_hp > 0, left_hp <= right_hp] | ||
else: | ||
# self.tile_x == 14 | ||
score = [1, right_hp > 0, right_hp <= left_hp] | ||
|
||
return score |
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,31 @@ | ||
from clashroyalebuildabot.actions.generic.action import Action | ||
|
||
|
||
class DefenseAction(Action): | ||
""" | ||
If there are enemies on our side, | ||
play the card in a defensive position | ||
""" | ||
|
||
def calculate_score(self, state): | ||
if (self.tile_x, self.tile_y) not in {(8, 9), (9, 9)}: | ||
return [0] | ||
|
||
lhs = 0 | ||
rhs = 0 | ||
for det in state.enemies: | ||
if det.position.tile_y > 16: | ||
continue | ||
|
||
if det.position.tile_x >= 9: | ||
rhs += 1 | ||
else: | ||
lhs += 1 | ||
|
||
if lhs == rhs == 0: | ||
return [0] | ||
|
||
if lhs >= rhs and self.tile_x == 9: | ||
return [0] | ||
|
||
return [1] |
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,23 @@ | ||
import math | ||
|
||
from clashroyalebuildabot.actions.generic.action import Action | ||
|
||
|
||
class KingAction(Action): | ||
""" | ||
Play the card behind the king, on the side of the closest enemy | ||
""" | ||
|
||
def calculate_score(self, state): | ||
if (self.tile_x, self.tile_y) not in {(8, 0), (9, 0)}: | ||
return [0] | ||
|
||
min_distance = float("inf") | ||
for det in state.enemies: | ||
distance = math.hypot( | ||
det.position.tile_x - self.tile_x, | ||
det.position.tile_y - self.tile_y, | ||
) | ||
min_distance = min(min_distance, distance) | ||
|
||
return [0.5, -min_distance] |
2 changes: 1 addition & 1 deletion
2
...oyalebuildabot/actions/overhead_action.py → ...ldabot/actions/generic/overhead_action.py
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
6 changes: 5 additions & 1 deletion
6
clashroyalebuildabot/actions/spell_action.py → ...buildabot/actions/generic/spell_action.py
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 |
---|---|---|
@@ -1,16 +1,6 @@ | ||
from clashroyalebuildabot import Cards | ||
from clashroyalebuildabot.actions.action import Action | ||
from clashroyalebuildabot.actions.generic.defense_action import DefenseAction | ||
|
||
|
||
class KnightAction(Action): | ||
class KnightAction(DefenseAction): | ||
CARD = Cards.KNIGHT | ||
|
||
def calculate_score(self, state): | ||
score = [0.5] if state.numbers.elixir.number == 10 else [0] | ||
for det in state.enemies: | ||
lhs = det.position.tile_x <= 8 and self.tile_x == 8 | ||
rhs = det.position.tile_x > 8 and self.tile_x == 9 | ||
|
||
if self.tile_y < det.position.tile_y <= 14 and (lhs or rhs): | ||
score = [1, self.tile_y - det.position.tile_y] | ||
return score |
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 |
---|---|---|
@@ -1,21 +1,6 @@ | ||
from clashroyalebuildabot import Cards | ||
from clashroyalebuildabot.actions.action import Action | ||
from clashroyalebuildabot.actions.generic.bridge_action import BridgeAction | ||
|
||
|
||
class MinipekkaAction(Action): | ||
class MinipekkaAction(BridgeAction): | ||
CARD = Cards.MINIPEKKA | ||
|
||
def calculate_score(self, state): | ||
if state.numbers.elixir.number != 10: | ||
return [0] | ||
|
||
left_hp = state.numbers.left_enemy_princess_hp.number | ||
right_hp = state.numbers.right_enemy_princess_hp.number | ||
|
||
if (self.tile_x, self.tile_y) == (3, 15): | ||
return [1, left_hp > 0, left_hp <= right_hp] | ||
|
||
if (self.tile_x, self.tile_y) == (14, 15): | ||
return [1, right_hp > 0, right_hp <= left_hp] | ||
|
||
return [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
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,6 @@ | ||
from clashroyalebuildabot import Cards | ||
from clashroyalebuildabot.actions.generic.king_action import KingAction | ||
|
||
|
||
class WitchAction(KingAction): | ||
CARD = Cards.WITCH |
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