def do_missions(mission_tuple, base_coordinate=None): global controller timer = time.clock() while True: try: if time.clock() - timer > 300: restart_bluestacks() if mission_tuple is not MISSION_EXCEPTION: controller = Controller(get_screenshot()) do_missions(MISSION_EXCEPTION) for m in mission_tuple: if mission(m, base_coordinate): controller = Controller(get_screenshot()) except BreakMissions: break except LoopDone: timer = time.clock() while True: controller = Controller(get_screenshot()) if get_coordinates(SHOP_BUTTON): break if time.clock() - timer > 20: break trophies = trophy_recognizer.recognize() print('{} trophies'.format(trophies)) if 0 < trophies < TROPHY_TARGET: break except GameException as game_exception: if game_exception.args[0] == EXCEPTION_FOR_EXCEPTION_LOOP: raise GameException(EXCEPTION_FOR_MAIN_LOOP) else: do_missions(MISSION_START_GAME) do_missions(mission_tuple, base_coordinate) break
def restart_bluestacks(): global controller while get_coordinates(BLUESTACKS_EXIT_BUTTON): controller = Controller(get_screenshot()) click_points_by_name(BLUESTACKS_EXIT_BUTTON) time.sleep(1) while not get_coordinates(BLUESTACKS_EXIT_BUTTON): controller = Controller(get_screenshot()) if get_coordinates(START_BLUESTACKS): controller.click(get_coordinates(START_BLUESTACKS)[0], click_times=2) time.sleep(10) raise GameException(EXCEPTION_FOR_MAIN_LOOP)
def produce_army(): global controller while True: controller = Controller(get_screenshot()) barracks_coordinates = get_coordinates(BARRACKS_LV10) if len(barracks_coordinates) >= BARRACKS_NUMBER: break for coordinate in barracks_coordinates[:4]: do_missions(MISSION_PRODUCE_ARMY, [coordinate]) controller.click_blank()
def __init__(self, port): self.zoom = 1 self.disp = Display(self.zoom) #robot displays by default at 100 pixels square. #read robot is approx 26cm square #multiply default scaled distances by scale to get cm #internally the model works in default scaled pixels. But it returns #cm on the UI and TCP interfaces. self.scale = 26.0 / 100 timenow = time.time() self.robot = RobotModel(self.disp, 100, self.scale, timenow) self.world = WorldModel(self.disp, self.robot, timenow) self.world.add_default_walls() if (port != 0): self.controller = Controller(port, self.robot, 1) else: self.controller = Controller(55443, self.robot, 0) self.robot.set_controller(self.controller) self.robot.init_robot_posn(500, 350, 0) self.robot.set_ir_angles(0, 0) self.robot.stop() self.active = True
from src.control import Controller if __name__ == '__main__': Controller().run()
__author__ = 'CRVV' import time from src.control import Controller from src.image_process import get_coordinates from src.image_process import get_screenshot from src.trophy import TrophyRecognizer from src.resource import * controller = Controller(get_screenshot()) trophy_recognizer = TrophyRecognizer() def do_missions(mission_tuple, base_coordinate=None): global controller timer = time.clock() while True: try: if time.clock() - timer > 300: restart_bluestacks() if mission_tuple is not MISSION_EXCEPTION: controller = Controller(get_screenshot()) do_missions(MISSION_EXCEPTION) for m in mission_tuple: if mission(m, base_coordinate): controller = Controller(get_screenshot()) except BreakMissions: break except LoopDone: timer = time.clock()