def set_perk(self, element: Element): if element == Element('BOMB_BLAST_RADIUS_INCREASE'): self.radius_value += RADIUS_PERK_INCREASE self.radius_time += PERK_TIME if element == Element('BOMB_COUNT_INCREASE'): self.count_time = PERK_TIME if element == Element('BOMB_IMMUNE'): self.immune_time = PERK_TIME if element == Element('BOMB_REMOTE_CONTROL'): self.remote_value = REMOTE_PERK_COUNT
def select(self, value): self._element.click() if ("@" in value): value = value.lower() input_elem = Element( self._element.wrapped_element.find_element( By.XPATH, "../following-sibling::input[1]"), self._driver) input_elem.send_keys(value) self._driver.find_element( By.XPATH, u"//a/span[contains(text(), '{}')]".format(value)).click()
def test_get_candidates(self): helium = Element(4, 1, 1, ElementType.HELIUM) hidro1 = Element(1, 1, 1, ElementType.HIDROGEN) hidro2 = Element(1, 1, 1, ElementType.HIDROGEN) hidro3 = Element(1, 1, 1, ElementType.HIDROGEN) elements = [ hidro1, hidro2, hidro3, helium, ] candidates = Helper.get_candidates(elements, ElementType.HELIUM) self.assertListEqual(candidates, [helium]) self.assertNotEqual(candidates, [hidro1])
def _ignition(self, base_elements): '''Elements creation, at the begining every element is hidrogen. ''' for item in base_elements: self._elements.append( Element(item[0], item[1], item[2], ElementType.HIDROGEN))
def _fusion(self, elem_0, elem_1): '''Fusion two elements ''' mid_point = Helper.get_mid_point(elem_0, elem_1) new_element_type = self._get_next_element_type(elem_0.element_type) new_element = Element(1, mid_point[0], mid_point[1], new_element_type) # Id for the new element new_element.node_id = str(id(new_element)) # Optimal internal structure Helper.set_internal_structure(elem_0, elem_1, self.distance_matrix) # Tracking elements new_element.nodes = [elem_0, elem_1] new_elements = set(self._elements) # Elements to remove fusioned = {elem_0, elem_1} self._elements = list(new_elements - fusioned) self._elements.append(new_element)
def find_elements(self, by=By.ID, value=None, timeout=None): found_elems = [] elems = self._find_elements(by, value, timeout) if (elems != None): for elem in elems: found_elems.append(Element(elem)) return found_elems
def estimate_act(self, point: tuple, radius: int) -> float: x, y = point estimate = 0 forward = backward = True for xi in range(1, radius + 1): if forward: forward = self.board.get_at((x + xi, y)) != Element('WALL') estimate += self._estimate_act(x + xi, y) if backward: backward = self.board.get_at((x + xi, y)) != Element('WALL') estimate += self._estimate_act(x - xi, y) for yi in range(1, 4): if forward: forward = self.board.get_at((x, y + yi)) != Element('WALL') estimate += self._estimate_act(x, y + yi) if backward: backward = self.board.get_at((x, y - yi)) != Element('WALL') estimate += self._estimate_act(x, y - yi) return estimate
def init(self, board_string: str): for element in ELEMENTS: self.grouped[element] = [] x = y = 0 for char in board_string: element = Element(char) self.field[x][y] = element self.grouped[element].append((x, y)) x += 1 if x == self.size: x = 0 y += 1
def act_analyzer(self, act: Act, next_point: tuple, board: Board) -> Act: if self.remote_act: d = self.explosion_radius points = {self.last_act} add_empties_around(board, self.last_act, points, dx=d, dy=d) if self.immune_time <= 1 and self.point in points: return Act.none for point in points: if board.get_at(point) in [ Element('OTHER_BOMBERMAN'), Element('MEAT_CHOPPER'), Element('OTHER_BOMB_BOMBERMAN') ]: self.act_of_remove_act() return Act.before if self.last_act_time > 5: self.act_of_remove_act() return Act.before return Act.none if act != Act.none: # can place bomb if self.count_time == 0: if self.last_act is not None: return Act.none # remote if self.remote_value > 0: self.remote_value -= 1 self.remote_act = True # setup last_act if act == Act.before: self.last_act = self.point if act == Act.after: self.last_act = next_point self.last_act_time = 0 return act else: return Act.none
def act_logic(self): before = self.estimation.estimate_act(self.me.point, self.me.explosion_radius) after = self.estimation.estimate_act(self.next_point, self.me.explosion_radius) if before >= after and before >= ESTIMATION_ACK_MIN_SCORE: self.act = Act.before elif after >= ESTIMATION_ACK_MIN_SCORE: self.act = Act.after # act check with predictor if self.act != Act.none: act_point = self.me.point if self.act == Act.before else self.next_point board = self.board.copy() board.set_at(act_point, Element('BOMB_TIMER_4')) # self.graphic = Graphic(board) act_predictor = Predictor(board, self.me) act_predictor.run(self.next_point, meat_chopper_d=2) if len(act_predictor.tree[PREDICTOR_DEEP]) == 0: self.act = Act.none if self.act == Act.before: proposal = act_predictor.proposal() if self.next_point not in proposal.keys(): self.act = Act.none
def find_element(self, by=By.ID, value=None, timeout=None): elem = self._find_element(by, value, timeout) return Element(elem, self)
def find_bomberman(self) -> tuple: points = self.find(Element('BOMBERMAN'), Element('BOMB_BOMBERMAN'), Element('DEAD_BOMBERMAN')) return points[0]
# but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public # License along with this program. If not, see # <http://www.gnu.org/licenses/gpl-3.0.html>. # #L% ### from math import sqrt from typing import Dict, List from core.element import Element, ELEMENTS DEFAULT_ELEMENT = Element('WALL') class Board: def __init__(self, board_string: str): board_string = board_string.replace('\n', '') self.size = int(sqrt(len(board_string))) self.field: List[List[Element]] = self.create_2d_array(self.size, self.size, DEFAULT_ELEMENT) self.grouped: Dict[Element, list] = {} self.init(board_string) def init(self, board_string: str): for element in ELEMENTS: self.grouped[element] = [] x = y = 0 for char in board_string:
def die_check(self): state = self.board.get_at(self.me.point) if state == Element('DEAD_BOMBERMAN'): self.me = Me()
from core.board import Board from core.element import Element ALL_EMPTY = [ Element('BOMBERMAN'), Element('BOMB_BOMBERMAN'), Element('OTHER_BOMBERMAN'), Element('OTHER_DEAD_BOMBERMAN'), Element('OTHER_BOMB_BOMBERMAN'), Element('DESTROYED_WALL'), Element('MEAT_CHOPPER'), Element('DEAD_MEAT_CHOPPER'), Element('BOMB_BLAST_RADIUS_INCREASE'), Element('BOMB_COUNT_INCREASE'), Element('BOMB_IMMUNE'), Element('BOMB_REMOTE_CONTROL'), Element('BOOM'), Element('NONE') ] def add_empties_around(board: Board, point: tuple, points: set, *, dx=1, dy=1): x, y = point forward = backward = True for xi in range(1, dx + 1): if forward: forward = _add_if_empty(board, x + xi, y, points) if backward: backward = _add_if_empty(board, x - xi, y, points) forward = backward = True for yi in range(1, dy + 1):
def setUp(self) -> None: self.element = Element(1, 0, 0, ElementType.HIDROGEN) self.elements = [(1, 0, 0)] self.star = Star([(1, 0, 0)], [[0]]) return super().setUp()