def find_direction(self): """ This is an example of direction solver subroutine.""" _direction = Direction('NULL').to_string() if self._board.is_my_bomberman_dead(): print("Bomberman is dead. Sending 'NULL' command...") return _direction # here's how we find the current Point of our bomberman _bm = self._board.get_bomberman() _bm_x, _bm_y = _bm.get_x(), _bm.get_y() # Let's check whether our bomberman is not surrounded by walls if 4 == self._board.count_near(_bm_x, _bm_y, Element('DESTROY_WALL')): print("It seems like walls surround you. Self-destroying.") return Direction('ACT').to_string() # Let's drop a bomb then #print(self._board.to_string()) print("Found your Bomberman at {}".format(_bm)) #put the bomb near something that could blow if self._board.is_at(_bm_x, _bm_y, Element('BOMB_BOMBERMAN')): print("Run") else: print("Lets watch out") _targets = self._board.get_targets() for target in _targets: target_element = self._board.get_at(target.get_x(), target.get_y()) if self._board.is_near(_bm_x, _bm_y, target_element): print("Seems we've got the target, lets drop the bomb!".format(target_element)) return Direction('ACT').to_string() # Let's drop a bomb then # here's how we get the list of barriers Points _barriers = self._board.get_barriers() _deadline = time() + 30 while time() < _deadline: # here we get the random direction choise __dir = Direction(choice(('LEFT', 'RIGHT', 'DOWN', 'UP'))) # now we calculate the coordinates of potential point to go _x, _y = __dir.change_x(_bm.get_x()), __dir.change_y(_bm.get_y()) # if there's no barrier at random point if not self._board.is_barrier_at(_x, _y): # here we count the attempt to choose the way self._count += 1 # and check whether it's not the one we just came from if not self._last == (_x, _y) or self._count > 5: # but we will go back if there were no others twice _direction = __dir.to_string() self._last = _bm.get_x(), _bm.get_y() self._count = 0 break else: # it seem that we are surrounded print("It's long time passed. Let's drop a bomb") _direction = Direction('ACT').to_string() # let's drop a bomb :) return _direction
def get_future_blasts(self): _bombs = set() _bombs.update(self.get_bombs()) _bombs.update(self._find_all(Element('OTHER_BOMB_BOMBERMAN'))) _points = set() for _bomb in _bombs: _bx, _by = _bomb.get_x(), _bomb.get_y() _points.add(_bomb) for _d in ('LEFT', 'RIGHT', 'DOWN', 'UP'): __dir = Direction(_d) __x, __y = _bx, _by for _ in range(3): __x, __y = __dir.change_x(__x), __dir.change_y(__y) __pt = Point(__x, __y) if not (__pt.is_bad(self._size) or __pt in self.get_walls()): break _points.add(__pt) return list(_points)
def find_direction(self): """ This is an example of direction solver subroutine.""" _direction = Direction('NULL').to_string() if self._board.is_my_bomberman_dead(): print("Bomberman is dead. Sending 'NULL' command...") return _direction # here's how we find the current Point of our bomberman _bm = self._board.get_bomberman() _bm_x, _bm_y = _bm.get_x(), _bm.get_y() # Let's check whether our bomberman is not surrounded by walls if 4 == self._board.count_near(_bm_x, _bm_y, Element('DESTROY_WALL')): print("It seems like walls surround you. Self-destroying.") return Direction('ACT').to_string() # Let's drop a bomb then # print(self._board.to_string()) print("Found your Bomberman at {}".format(_bm)) # here's how we get the list of barriers Points _barriers = self._board.get_barriers() _deadline = time() + 30 while time() < _deadline: if round(time()) % 5 == 0: return Direction('ACT').to_string() # here we get the random direction choice __dir = Direction(choice(('LEFT', 'RIGHT', 'DOWN', 'UP'))) # now we calculate the coordinates of potential point to go _x, _y = __dir.change_x(_bm.get_x()), __dir.change_y(_bm.get_y()) # if there's no barrier at random point if not self._board.is_barrier_at(_x, _y): # here we count the attempt to choose the way self._count += 1 # and check whether it's not the one we just came from if not self._last == (_x, _y) or self._count > 5: # but we will go back if there were no others twice _direction = __dir.to_string() self._last = _bm.get_x(), _bm.get_y() self._count = 0 break else: # it seem that we are surrounded print("It's long time passed. Let's drop a bomb") _direction = Direction('ACT').to_string() # let's drop a bomb :) return _direction