-
Notifications
You must be signed in to change notification settings - Fork 40
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
22 changed files
with
306 additions
and
548 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .action import Action | ||
|
||
__all__ = ["Action"] |
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 @@ | ||
from abc import ABC | ||
from abc import abstractmethod | ||
|
||
from clashroyalebuildabot.namespaces.cards import Card | ||
|
||
|
||
class Action(ABC): | ||
CARD: Card = None | ||
|
||
def __init__(self, index, tile_x, tile_y): | ||
self.index = index | ||
self.tile_x = tile_x | ||
self.tile_y = tile_y | ||
|
||
if self.CARD is None: | ||
raise ValueError("Each action must set the CARD attribute") | ||
|
||
def __repr__(self): | ||
return f"{self.CARD.name} at ({self.tile_x}, {self.tile_y})" | ||
|
||
@abstractmethod | ||
def calculate_score(self, state): | ||
pass |
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,16 @@ | ||
from clashroyalebuildabot import Cards | ||
from clashroyalebuildabot.actions.action import Action | ||
|
||
|
||
class ArchersAction(Action): | ||
CARD = Cards.ARCHERS | ||
|
||
def calculate_score(self, state): | ||
score = [0.5] if state.numbers["elixir"]["number"] == 10 else [0] | ||
for v in state.enemies.values(): | ||
for position in v["positions"]: | ||
lhs = position.tile_x <= 8 and self.tile_x == 7 | ||
rhs = position.tile_x > 8 and self.tile_x == 10 | ||
if self.tile_y < position.tile_y <= 14 and (lhs or rhs): | ||
score = [1, self.tile_y - 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from clashroyalebuildabot import Cards | ||
from clashroyalebuildabot.actions.spell_action import SpellAction | ||
|
||
|
||
class ArrowsAction(SpellAction): | ||
CARD = Cards.ARROWS | ||
RADIUS = 4 | ||
MIN_TO_HIT = 5 |
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,8 @@ | ||
from clashroyalebuildabot import Cards | ||
from clashroyalebuildabot.actions.spell_action import SpellAction | ||
|
||
|
||
class FireballAction(SpellAction): | ||
CARD = Cards.FIREBALL | ||
RADIUS = 2.5 | ||
MIN_TO_HIT = 3 |
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,19 @@ | ||
from clashroyalebuildabot import Cards | ||
from clashroyalebuildabot.actions.action import Action | ||
|
||
|
||
class GiantAction(Action): | ||
CARD = Cards.GIANT | ||
|
||
def calculate_score(self, state): | ||
score = [0] | ||
left_hp, right_hp = ( | ||
state.numbers[f"{direction}_enemy_princess_hp"]["number"] | ||
for direction in ["left", "right"] | ||
) | ||
if state.numbers["elixir"]["number"] == 10: | ||
if self.tile_x == 3: | ||
score = [1, self.tile_y, left_hp != -1, left_hp <= right_hp] | ||
elif self.tile_x == 14: | ||
score = [1, self.tile_y, right_hp != -1, 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,17 @@ | ||
from clashroyalebuildabot import Cards | ||
from clashroyalebuildabot.actions.action import Action | ||
|
||
|
||
class KnightAction(Action): | ||
CARD = Cards.KNIGHT | ||
|
||
def calculate_score(self, state): | ||
score = [0.5] if state.numbers["elixir"]["number"] == 10 else [0] | ||
for v in state.enemies.values(): | ||
for position in v["positions"]: | ||
lhs = position.tile_x <= 8 and self.tile_x == 8 | ||
rhs = position.tile_x > 8 and self.tile_x == 9 | ||
|
||
if self.tile_y < position.tile_y <= 14 and (lhs or rhs): | ||
score = [1, self.tile_y - 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import math | ||
|
||
from clashroyalebuildabot import Cards | ||
from clashroyalebuildabot.actions.action import Action | ||
|
||
|
||
class MinionsAction(Action): | ||
CARD = Cards.MINIONS | ||
|
||
def calculate_score(self, state): | ||
score = [0.5] if state.numbers["elixir"]["number"] == 10 else [0] | ||
for v in state.enemies.values(): | ||
for position in v["positions"]: | ||
distance = math.hypot( | ||
position.tile_x - self.tile_x, | ||
position.tile_y - self.tile_y, | ||
) | ||
if distance < 1: | ||
score = [1, -distance] | ||
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,19 @@ | ||
from clashroyalebuildabot import Cards | ||
from clashroyalebuildabot.actions.action import Action | ||
|
||
|
||
class MinipekkaAction(Action): | ||
CARD = Cards.MINIPEKKA | ||
|
||
def calculate_score(self, state): | ||
left_hp, right_hp = ( | ||
state.numbers[f"{direction}_enemy_princess_hp"]["number"] | ||
for direction in ["left", "right"] | ||
) | ||
if self.tile_x in [3, 14]: | ||
return ( | ||
[1, self.tile_y, left_hp != -1, left_hp <= right_hp] | ||
if self.tile_x == 3 | ||
else [1, self.tile_y, right_hp != -1, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import math | ||
|
||
from clashroyalebuildabot import Cards | ||
from clashroyalebuildabot.actions.action import Action | ||
|
||
|
||
class MusketeerAction(Action): | ||
CARD = Cards.MUSKETEER | ||
|
||
def calculate_score(self, state): | ||
for v in state.enemies.values(): | ||
for position in v["positions"]: | ||
distance = math.hypot( | ||
position.tile_x - self.tile_x, | ||
position.tile_y - self.tile_y, | ||
) | ||
if 5 < distance < 6: | ||
return [1] | ||
if distance < 5: | ||
return [0] | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import math | ||
|
||
from clashroyalebuildabot.actions.action import Action | ||
|
||
|
||
class SpellAction(Action): | ||
RADIUS = None | ||
MIN_TO_HIT = None | ||
|
||
def calculate_score(self, state): | ||
hit_units = 0 | ||
max_distance = float("inf") | ||
for v in state.enemies.values(): | ||
for position in v["positions"]: | ||
distance = math.hypot( | ||
self.tile_x - position.tile_x, | ||
self.tile_y - position.tile_y + 2, | ||
) | ||
if distance <= self.RADIUS - 1: | ||
hit_units += 1 | ||
max_distance = min(max_distance, -distance) | ||
|
||
return [ | ||
1 if hit_units >= self.MIN_TO_HIT else 0, | ||
hit_units, | ||
max_distance, | ||
] |
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,11 +1,5 @@ | ||
from .bot import Action | ||
from .bot import Bot | ||
from .random import RandomBot | ||
from .two_six_hog_cycle import TwoSixHogCycle | ||
|
||
__all__ = [ | ||
"TwoSixHogCycle", | ||
"RandomBot", | ||
"Action", | ||
"Bot", | ||
] |
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
Oops, something went wrong.