def __init__(self): self.equal = True self.images = {} self.result = {} self.area1 = Area(5,5,200,200,"Your Area") self.area2 = Area(5,210,200,200,"Correct") self.area3 = Area(5,415,200,200,"Difference")
def __init__(self, numOfRows, numOfCols, cellSizeRow, cellSizeCol, rowFirstIndex=0, colFirstIndex=0): ''' Constructor ''' self.cellSize = (cellSizeRow, cellSizeCol) self.gridSize = (numOfRows, numOfCols) self.xCellRange = (colFirstIndex, numOfCols - colFirstIndex) self.yCellRange = (rowFirstIndex, numOfRows - rowFirstIndex) #create matrix - Grid : with numOfRows*numOfCols cells self.grid = [[Cell for x in range(numOfCols)] for y in range(numOfRows)] for i in range(numOfCols): for j in range(numOfRows): xMin = i * (cellSizeCol) xMax = (i + 1) * (cellSizeCol) yMin = j * (cellSizeRow) yMax = (j + 1) * (cellSizeRow) area = Area(i * (cellSizeCol), (i + 1) * (cellSizeCol), j * (cellSizeRow), (j + 1) * (cellSizeRow)) self.grid[j][i] = Cell(j, i, area)
def __init__(self, batch=1, time=200, mapSize=100, taskNum=15, trajectoryTime=110, taskTime=100): self.batch = batch self.map_size = mapSize self.time = time self.task_num = taskNum self.trajectoryTime = trajectoryTime self.taskTime = taskTime self.area = Area(0, 1) # In channel, 1st and 2nd are (x, y) launching location, # 3rd and 4th are (x, y) destination location self.tasks = np.zeros(shape=(batch, taskTime, taskNum, 5), dtype=int) self.trajectors = np.zeros(shape=(batch, trajectoryTime, mapSize, mapSize), dtype=int) self.Rfeature = np.zeros(shape=(batch, mapSize, mapSize, 2), dtype=np.float32) self.totalFlyingTime = 0 self.totalUavNum = 0 if os.path.exists('./log.txt'): os.remove('log.txt')
def __init__(self): self.images = {} self.result = {} self.area1 = Area(GAP, GAP, WIDTH, HEIGHT) self.area2 = Area(GAP, 1 * (GAP + HEIGHT + 1) + GAP, WIDTH, HEIGHT) self.area3 = Area(GAP, 2 * (GAP + HEIGHT + 1) + GAP, WIDTH, HEIGHT) self.area4 = Area(GAP + WIDTH + GAP, 2 * (GAP + HEIGHT + 1) + GAP, WIDTH, HEIGHT) self.area5 = Area(GAP + WIDTH + GAP, 1 * (GAP + HEIGHT + 1) + GAP, WIDTH, HEIGHT) self.count = 0 self.mousex = 0 self.mousey = 0 self.img2 = None self.img3 = None self.img4 = None self.nr = 0
def test_print_area_2(self): input_cells = [{'x': 0, 'y': 0}, {'x': 1, 'y': 3}] area = Area(input_cells) self.assertEqual( area.print_area(), "[X][ ][ ][ ][ ][ ][ ][ ]\n" + "[ ][ ][ ][ ][ ][ ][ ][ ]\n" + "[ ][ ][ ][ ][ ][ ][ ][ ]\n" + "[ ][X][ ][ ][ ][ ][ ][ ]\n" + "[ ][ ][ ][ ][ ][ ][ ][ ]\n" + "[ ][ ][ ][ ][ ][ ][ ][ ]\n" + "[ ][ ][ ][ ][ ][ ][ ][ ]\n" + "[ ][ ][ ][ ][ ][ ][ ][ ]\n")
def test_check_environment(self): input_cells = [ { 'x': 0, 'y': 0 }, ] area = Area(input_cells) self.assertEqual(area.check_environment(0, 1), 1)
def warp(self, coordinates): # Don't recreate if warped to the same map new_area = coordinates[0] x = coordinates[1] y = coordinates[2] if self.__area != new_area: self.__area = new_area self.__map = Area(new_area) self.__UI.warp(x, y)
def reset(self): self.construction_site = ConstructionSite( name=self.construction_site_name, location=self.construction_site_location) self.delivery_area = Area(name=self.delivery_area_name, pos=self.delivery_area_pos, width=self.delivery_area_width, length=self.delivery_area_length) self.building_area = Area(name=self.building_area_name, pos=self.building_area_pos, width=self.building_area_width, length=self.building_area_length) self.storage_area = Area(name=self.storage_area_name, pos=self.storage_area_pos, angle=self.storage_angle, width=self.storage_area_width, length=self.storage_area_length) self.demand_points = [self.building_area] self.construction_site.add_area( [self.delivery_area, self.building_area, self.storage_area]) self.crane = Crane(pos=self.crane_pos, sweeping_range=self.crane_sweeping_range, demand_points=self.demand_points) self.crane.init_parts() self.construction_site.add_crane([self.crane]) self.access_road = Road(pos=self.road_pos) self.access_road.calculate_length() self.truck = Truck(road=self.access_road) self.package1 = Package(name=self.package_name, width=self.package_width, length=self.package_length, crane=self.crane, truck=self.truck) self.crane.hook.package = self.package1 self.packages = [self.package1] self.construction_site.add_package(self.packages) return L1.index((int( changement_repere(self.crane.hook.pos[0], self.crane.hook.pos[1], self.crane.hook.angle)[0]), (int( changement_repere(self.crane.hook.pos[0], self.crane.hook.pos[1], self.crane.hook.angle)[1]))))
def __init__(self): super(BootStrap, self).__init__() self.score = cocos.text.Label('30', font_name='Times New Roman', font_size=24, color=(255, 215, 0, 255)) self.score.position = 20, 440 self.add(self.score, 99999) self.arena = Area() self.add(self.arena)
def __init__(self, hero): self.hero = hero self.bed = Area("Bed", ["blanket"], [], "Wait, it was all just a dream") self.evil_lair = Area( "Evil Lair", ["hostage folk", "Sword of Destiny"], [kagnor], f"Ahhh, {self.hero.name}, you have some at last...") self.dark_forest = Area( "Dark Forest", ["torch", "potion", "Flame Storm"], [pumpkinMan, goblin, goblin], "The dark forest is dark, only in darkness will you gain the thirst to seek the light" ) self.outside = Area("Outside", ["not hostage folk", "necklace of destiny"], [skeleton], "The sky is dark, story story story") self.home = Area("Home", ["map"], [], "Some Story") self.createJourney() self.welcome() self.startJourney(self.home)
def add_area(self, name=None, level=None, difficulty=None, description=None): new_area = Area(name=name, level=level, difficulty=difficulty, description=description) self.areas.append(new_area) return new_area
def reset(self): self.board = [] posy = 19 for _ in range(8): posx = 22 helper = [] for _ in range(8): helper.append(Area(posx, posy)) posx += 77 self.board.append(helper) posy += 77 self.add_figures()
def display(self, screen): if self.shape is None: self.shape = Area(name="Truck", pos=self.road.pos[0], angle=-90, width=self.width, length=self.length) self.shape.set_color() self.shape.pos = self.pos_on_road()[0] self.shape.angle = math.degrees(self.pos_on_road()[1]) self.shape.display_from_center(screen)
def bayesian_updating_iteration(params, until_convergence: bool = True, sensitivity_analysis: bool = False): start_time = dt.now() DataGenerator.param_validation(params=params) targets_locations = eval(params['TARGET_LOCATIONS']) if targets_locations is None and params.getint('NUM_TARGETS'): targets_locations = Area.generate_targets( num_targets=params.getint('NUM_TARGETS')) area = Area(num_cells_axis=params.getint('N'), t_interval=params.getint('T_INTERVAL'), pta=params.getfloat('pta'), alpha=params.getfloat('alpha'), targets_locations=targets_locations) agent = Agent(current_location=eval(params['AGENT_POSITION']), lambda_strength=params.getint('LAMBDA_SENSOR'), p_S=Agent.get_p_S_from_initial_prior( prior=params.getfloat('INITIAL_PRIOR_P'), area=area), entropy_updates=[], information_gain_updates=[], converge_iter=200 - 1, p_S_history=[]) """ 2 Running modes: until convergence (all the targets identified and not False Positives) or until infinity """ if not sensitivity_analysis: agent.bayesian_update(area=area, until_convergence=until_convergence, verbose=True, stop_after_iteration=200) print('Bayesian Updating Done in {}'.format(dt.now() - start_time)) else: target_prob = agent.get_prob_history(targets_locations[2]) # non_target_loc = random.choice([loc for loc in zip(range(params.getint('N')), range(params.getint('N'))) if loc not in targets_locations]) # Randomly selected non targets list_of_loc = [(9, 10), (7, 15), (1, 16)] agent_pos = eval(params['AGENT_POSITION']) non_target_prob = {} for loc in list_of_loc: dist = np.round( np.sqrt( np.power(loc[0] - agent_pos[0], 2) + np.power(loc[1] - agent_pos[1], 2))) non_target_prob[dist] = agent.get_prob_history(loc) ent_upd, info_gain_upd, conv_iter = agent.get_metrics() return ent_upd, info_gain_upd, conv_iter, target_prob, non_target_prob
def __init__(self, batch=1, time=200, mapSize=100, taskNum=15, trajectoryTime=70, taskTime=60): self.batch = batch self.map_size = mapSize self.time = time self.task_num = taskNum self.area = Area(0, 1) self.trajectoryTime = trajectoryTime self.taskTime = taskTime '''------------main net-----------------''' # channels: mainTaskList[0] and mainTaskList[1] is launching location # channels: mainTaskList[2] and mainTaskList[3] is landing location # channels: mainTaskList[5] is launching time # mainTaskList = (3000, 60, 15, 5) self.mainTaskList = np.zeros(shape=(batch, taskTime, taskNum, 5), dtype=int) # every timestep, number of uav on each grid # used for generate density map (label) and init density (input) self.trajectors = np.zeros(shape=(batch, trajectoryTime, mapSize, mapSize), dtype=int) # subOutput = (3000, 60, 100, 100), tasklist as input for MainNet self.subOutput = np.zeros(shape=(batch, taskTime, mapSize, mapSize), dtype=float) # Rnet input self.Rfeature = np.zeros(shape=(batch, mapSize, mapSize, 2), dtype=np.float32) '''------------sub net-----------------''' # subTaskList = (3000*60, 15, 5), tasklist as input for SubNet self.subTaskList = np.zeros(shape=(batch * taskTime, taskNum, 5), dtype=float) # subLabel = (3000*60, 100, 100), as label for SubNet self.subLabel = np.zeros(shape=(batch * taskTime, mapSize, mapSize), dtype=float) self.counter = np.zeros(shape=(batch * taskTime, mapSize, mapSize), dtype=int) self.startValue = 0.25 self.endValue = 0.75 '''------------statistic-----------------''' self.totalFlyingTime = 0 self.totalUavNum = 0 if os.path.exists('./log.txt'): os.remove('log.txt')
def play(): player = Player() os.system('cls') print('Select complexity:') options = [ f'{name} (freedom: {int(complexity * 100)}%)' for name, complexity in complexities ] area = Area(120, 20, complexities[select_option(options)][1], player) while player.area is not None: area.draw() act(area) if player.won: print("You won") else: print("Game over")
def __init__(self, phase, server_seq): signal.signal(signal.SIGINT, self.stop) signal.signal(signal.SIGTERM, self.stop) self.phase = phase self.server_seq = server_seq self.is_running = True self.get_max = 1000 self.players = {} self.area_id = 0 self.areas = {} self.areas[self.area_id] = Area(e.AREA_LOBBY) self.area_id += 1 self.curr_time = 0 self.delta_time = 0 self.last_time = 0
def __init__(self): self.message = Message() self.game_on = True self.client = mqtt.Client() print("Server created") self.handle_methods() self.client.connect("127.0.0.1") self.subscribe_on_topics() self.state = GameState.waiting print "--- Game waiting for players ---" self.id_to_sub = {} self.area = Area() self.vis = Visualiser(self.area) # thread logic thread = Thread(target=self.game_loop, args=()) thread.start() self.client.loop_forever()
def display(self, screen): self.background = pygame.Surface((2 * self.length, 2 * self.length), pygame.SRCALPHA).convert_alpha() self.background.fill(pygame.Color(0, 0, 0, 0)) # fill with transparent color if self.shape == "LINE": pygame.draw.line( surface=self.background, color=pygame.Color("black"), start_pos=(self.length, self.length), end_pos=(self.length + self.length * math.sin(math.radians(self.angle)), self.length + self.length * math.cos(math.radians(self.angle))), width=8) screen.blit(self.background, (self.pos[0], self.pos[1])) elif self.shape == "AREA": if self.area is None: self.area = Area(name="Boom", pos=(self.pos[0] + self.length, self.pos[1] + self.length), angle=self.angle, width=8, length=self.length, color=pygame.Color("black")) self.area.init_background() self.area.angle = self.angle # update the angle in the area class pygame.draw.polygon(surface=self.background, color=pygame.Color("black"), points=self.area.coordinates_from_side()) screen.blit(self.background, (self.pos[0], self.pos[1]))
def __init__(self, batch=1, time=200, mapSize=100, taskNum=15, trajectoryTime=70, taskTime=60): self.batch = batch self.map_size = mapSize self.time = time self.task_num = taskNum self.trajectoryTime = trajectoryTime self.taskTime = taskTime self.area = Area(0, 1) # In channel, 1st and 2nd are (x, y) launching location, # 3rd and 4th are (x, y) destination location self.tasks = np.zeros(shape=(batch, taskTime, taskNum, 5), dtype=int) self.trajectors = np.zeros(shape=(batch, trajectoryTime, mapSize, mapSize), dtype=int) # tasksSlice = (3000*60, 15, 4) self.tasksSlice = np.zeros(shape=(batch * taskTime, taskNum, 4), dtype=float) # tasksSlice = (3000*60, 100, 100, 1) self.trajectorsSlice = np.zeros(shape=(batch * taskTime, mapSize, mapSize, 1), dtype=float) self.counter = np.zeros(shape=(batch * taskTime, mapSize, mapSize, 1), dtype=int) self.taskMap = np.zeros(shape=(batch, taskTime, mapSize, mapSize), dtype=int) self.totalFlyingTime = 0 self.totalUavNum = 0 self.startValue = 0.25 self.endValue = 0.75 if os.path.exists('./log.txt'): os.remove('log.txt')
def _get_generated_params_for_sequence(self, random_num_targets:bool=True) -> Tuple[Any, Area, int, List[Location]]: """ Used for generating the parameters for the X data generation as agent location, number of targets, location of the targets, etc. If random_num_targets is True -> generating num of targets from 1 to N :return: agent, area, num_of_targets, targets_location """ params = config["PARAMS"] if random_num_targets: num_targets = np.random.randint(1, params.getint('N')) else: num_targets = params.getint('NUM_TARGETS') targets_locations = Area.generate_targets(num_targets=num_targets) area = Area(num_cells_axis=params.getint('N'), t_interval=params.getint('T_INTERVAL'), pta=params.getfloat('pta'), alpha=params.getfloat('alpha'), targets_locations=targets_locations) agent = Agent.Agent(current_location=eval(params['AGENT_POSITION']), lambda_strength=params.getint('LAMBDA_SENSOR'), p_S=Agent.Agent.get_p_S_from_initial_prior(prior=params.getfloat('INITIAL_PRIOR_P'), area=area), entropy_updates=[], information_gain_updates=[], converge_iter=200 - 1, p_S_history=[]) return agent, area, len(targets_locations), targets_locations
def __init__(self): self.__state = None # Cutscene, overworld, combat self.__area = 0 # Area of the map currently displayed self.__map = Area(0) self.__UI = GUI(self) self.__UI.start()
def __init__(self, checkpoint_type, color, contour_color): self.contour_color = contour_color self.area = Area(color) self.upper_color = Color.Color(color, 1) self.lower_color = Color.Color(color, 0) self.type = checkpoint_type
def __init__(self, handle): """Initialize the OficinaActivity object. @param self @param handle """ activity.Activity.__init__(self, handle) self.max_participants = 1 logging.debug('Starting Paint activity (Oficina)') self.fixed = Gtk.Fixed() self._width = Gdk.Screen.width() self._height = Gdk.Screen.height() self.fixed.show() self.fixed.modify_bg(Gtk.StateType.NORMAL, style.COLOR_WHITE.get_gdk_color()) self.textview = Gtk.TextView() self.textview.set_events(Gdk.EventMask.POINTER_MOTION_MASK | Gdk.EventMask.POINTER_MOTION_HINT_MASK | Gdk.EventMask.BUTTON_PRESS_MASK | Gdk.EventMask.BUTTON_RELEASE_MASK | Gdk.EventMask.BUTTON_MOTION_MASK | Gdk.EventMask.TOUCH_MASK) self.textview.connect('event', self.__textview_event_cb) self.textview.connect("motion_notify_event", self.__textview_mouse_move_cb) self.fixed.put(self.textview, 0, 0) # These attributes are used in other classes, so they should be public self.area = Area(self) self.area.show() self.fixed.put(self.area, 0, 0) self.board = BulletinBoard(self) self.fixed.put(self.board.fixed, 0, 0) self._sw = Gtk.ScrolledWindow() self._sw.set_kinetic_scrolling(False) self._sw.show() self._sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) self.set_canvas(self._sw) self.toolset_intialize_from_journal() toolbar_box = DrawToolbarBox(self) toolbar_box.toolbar.insert(self.board.button, -1) #toolbar_box.toolbar.insert(self.board.share_button, -1) #toolbar_box.toolbar.insert(self.board.button, -1) self.board.button.show() toolbar_box.show_all() #self.board.box_button.hide() #self.board.share_button.hide() self.connect("key_press_event", self.key_press) # setup self.area only once def map_cp(widget): def size_allocate_cb(widget, allocation): widget.disconnect(self._setup_handle) self.area.setup(allocation.width, allocation.height) self.center_area() self.canvas.add_with_viewport(self.fixed) # to remove the border, we need set the shadowtype # in the viewport child of the scrolledwindow self.canvas.get_children()[0].set_shadow_type(Gtk.ShadowType.NONE) self.disconnect(self._setup_handle) self._setup_handle = self._sw.connect('size_allocate', size_allocate_cb) self._setup_handle = self.connect('map', map_cp) # Handle screen rotation Gdk.Screen.get_default().connect('size-changed', self._configure_cb)
verify = False #Manually verify detected areas? calibFlag = True #Detect with corrected or uncorrected images maxim = 0 #Image number of maximum areal extent imband = 'R' #Desired image band equal = True #Images with histogram equalisation? threshold = 5 #Threshold for number of retained polygons diff = 'light' #Image enhancement parameter 1 phi = 50 #Image enhancement parameter 2 theta = 20 #Image enhancement parameter 3 maxcol = 8 #Max value from which areas will be distinguished mincol = 1 #Min value from which areas will be distinguished maxim = 3 #Image number with maximum area of interest pxext = [0, 1200, 2000, 1500] #Plotting extent for interactive plots #Set up Area object, from which areal extent will be measured lakes = Area(camimgs, cameraenvironment, homogmatrix, calibFlag, imband, equal) #Set image enhancement parameters. If these are undefined then they will be #set to a default enhancement of ('light', 50, 20) lakes.setEnhance(diff, phi, theta) #Set colour range, from which extents will be distinguished. If colour range #is not specified, it will be manually defined lakes.setColourrange(maxcol, mincol) #Set mask and image with maximum area of interest lakes.setMax(camamask, maxim) #Set px plotting extent for easier colourrange definition and area verification lakes.setPXExt(pxext[0], pxext[1], pxext[2], pxext[3])
if position is not None: if len(inputs) < 64: inputs.append(position) re_input = loop_input( input( "Tekrar konum girmek için 1 , konum girme işlemini sonlandırmak için 2 giriniz: " )) while re_input == -1: re_input = loop_input( input( "Tekrar konum girmek için 1 , konum girme işlemini sonlandırmak için 2 giriniz: " )) if re_input == 2: break else: print("Maksimum girdi sayısına ulaşıldı") break rep_count = positive_int_input(input("Oyun tekrar sayısını giriniz:")) while (rep_count is None): rep_count = positive_int_input(input("Oyun tekrar sayısını giriniz:")) game_area = Area(inputs) for i in range(rep_count): print("{0}. oyun\n".format(i + 1)) print(game_area.print_area()) game_area.update_cells() game_area.upgrade() print("------------------------\n\n")
#CRAWL MAIN FILE import Dictionary import json import os from Area import Area from Item import Item from pprint import pprint script_dir = os.path.dirname(__file__) #<-- absolute dir the script is in turnNumber = 1 item_dict = [] area = Area() cheese = Item("Cheese Wheel", 10) area.objects.append(cheese) area.objects.append(cheese) class ItemEntry: filename = "" json = "" def __init__(self, filename, json): self.filename = filename self.json = json # loading items code def loadItem(filename):
################### MAIN #################### # some initialization procedures pygame.init() bot = Bot() # initializes the screen, window name and the key repeater # if the key is held the key is repeated size = width, height = 300, 440 screen = pygame.display.set_mode((width, height)) pygame.display.set_caption('TETRIS') pygame.key.set_repeat(75) while 1: # build a matrix for from the width and height area = Area(width - 100, height) # initializes the shape queue (first number is current shape, second is upcoming) # randomizes the shape color shape_queue = [] for i in range(5): shape_queue.append(randint(0, 6)) shape_color = (randint(1, 255), randint(1, 255), randint(1, 255)) # creates a new shape: 0 is the shape id shape = Shape(shape_color, shape_queue[0]) # init Heads up Display hud = Hud(width, height) gameOver = Gameover(width, height, area.score)
#!/usr/bin/python3 from Area import Area import sys if __name__ == '__main__': if sys.argv[1].endswith('.pdf'): Area(sys.argv[1], 3, 30, 500, 530, 275, 'NoteStd').extract() Area(sys.argv[1], 4, 30, 108, 530, 180, 'QITotal').extract() Area(sys.argv[1], 7, 30, 108, 530, 190, 'IndiceComp').extract()
"A Hanky too far", "The princess has lost her gold-laced hankerchief, you of course being the noble squire you are must go fetch it" )) quests.add_quest( Quest( "Royal Appointment", "Its that time of year, the king is overdue for his annual bath. He's asked for you to guard him on his journey to the natural springs north of town" )) quests.add_quest( Quest( "Scape Goat", "Barry, the untrustworthy squire in the neighbouring room has told the king you nicked his favourite snuff-box. You better sort Barry out straight away" )) hasselbad_area = Area( "Hasselbad", "A town on the easten shores of Lake Coleridge. Nestled in the southern foothills of the Shneeburg Alps it is a haven for outlaws, who hide amongst the fishermen and lumberjacks." ) korknev_area = Area( "Korknev", "More of a roadside stop than a town, on the road between Hasselbad and Noamsted it carries a fair amount of merchantile traffic, hardly any of it legal" ) noamsted_area = Area( "Noamsted", "The main town of the region. Noamsted is home to all types, on one street you could buy a rug, a dead body and someone to dispose of them both. The ruling class is mostly made up of old money, originally brought here for the iron mining. It has its fair share of blacksmiths and armories." ) tidefrost_area = Area( "Tidefrost", "A small hunting village right on the edge of the Schneeburg alps. Any further north and there would be more foxbears than villagers." ) hasselbad_area.items += [