def main(): random_tile = tiles.Tile() cold_tile = tiles.Tile("Michael Dresser", "wl") print(random_tile) print(cold_tile) input()
def makeMap(self, cols, rows): lands = ["grassland", "forest", "mountain"] lands_weight = [5, 3, 2] land_distro = [] land_chance = 0.5 # Apply weights to land types because py2 doesn't have random.choices() for i in range(len(lands)): for j in range(lands_weight[i]): land_distro.append(lands[i]) waters = ['ocean'] # Set up the new tile array new_map = [] for r in range(rows): new_row = [] for c in range(cols): # Choose terrain type for tile is_land = random.random() < land_chance if is_land: new_terrain = random.choice(land_distro) else: new_terrain = 'ocean' # Add tile to grid new_row.append(tiles.Tile(self, new_terrain, c, r)) new_map.append(new_row) return new_map
def tile_array_placement(self, newTiles=True): screenLst = [] for d1Idx in range(self.tilesArr.shape[0]): for d2Idx in range(self.tilesArr.shape[1]): tileXpos = (self.tileSize * d1Idx + self.BORDER[0]) tileYpos = (self.tileSize * d2Idx + self.BORDER[0]) if newTiles == True: self.tilesArr[d1Idx][d2Idx] = tiles.Tile( tileXpos, tileYpos, self.tileSize, [d1Idx, d2Idx]) if -2 * self.tileSize < tileXpos < self.WINSPECS[ self.windowResolutionIdx][ 0] + self.tileSize and -2 * self.tileSize < tileYpos < self.WINSPECS[ self.windowResolutionIdx][1] + self.tileSize: screenLst.append((d1Idx, d2Idx)) self.tilesOnScreen = np.zeros(len(screenLst), dtype=tuple) for idx, x in enumerate(screenLst): self.tilesOnScreen[idx] = x self.firstTileOnScrIdxX = self.tilesOnScreen[0][0] self.firstTileOnScrIdxY = self.tilesOnScreen[0][1] self.selectedTile = self.tilesArr[0][0]
def my_rides(): rides, visited_tiles, cluster, max_square, w = [], [], [], [], 0 if os.path.exists(conf.ride_file): with open(conf.ride_file, 'r') as rides_file: reader = csv.DictReader(rides_file) for row in reader: row['route'] = polyline.decode(row['polyline']) rides.append(row) if len(rides) > 0: most_visited, visited_tiles = tiles.parse(rides) max_square_tl, w = tiles.max_square(visited_tiles, most_visited, conf.max_square_bounds) max_square = max_square_tl.square(w) square_center = tiles.Tile(max_square_tl.x + int(w / 2), max_square_tl.y + int(w / 2)) cluster = tiles.max_cluster(visited_tiles, square_center) for r in rides: # redo route point decoding on browser, amount of data is huge and takes time/bandwidth if transmitted del r['route'] return render_template('app.html.j2', rides=json.dumps(rides), tiles=json.dumps( [t.polygon() for t in visited_tiles]), cluster=json.dumps([t.polygon() for t in cluster]), max_square=json.dumps({ 'shape': max_square, 'l': w }))
def handleLeftButton(self): self.sceneDirty = True mousePos = pygame.mouse.get_pos() if self.selectMode: if self.selectionStartX == -1: self.selectionStartX = mousePos[0] if self.selectionStartY == -1: self.selectionStartY = mousePos[1] else: ts = self.engine.scene.getTilestackAt( self.scene.viewport.x + mousePos[0], self.scene.viewport.y + mousePos[1]) if self.layerInUse == "base": if isinstance(self.selectedTile, int): ts.addBaseTile( tiles.Tile(self.tileFactory, self.selectedTile)) elif isinstance(self.selectedTile, str): # an irregularly-sized tile, so paint it's pieces separately self.paintIrregularTile(mousePos) else: ts.addRoofTile(tiles.Tile(self.tileFactory, self.selectedTile))
def update(self, *args): self.update_player_decisions() self.vote_direction() if self.game.ticks - self.game.last_player_move >= 1: self.game.last_player_move += 1 # resolving effects # stun if self.stunned: self.stunned -= 1 return # Vision reduction if self.impaired_vision_turns != 0: self.impaired_vision_turns -= 1 else: self.vision_radius = self.settings.vision_radius dest = (self.pos_x + self.direction.x, self.pos_y + self.direction.y) collision = bool(self.game.wall_graph.get(self.pos)) and dest in self.game.wall_graph.get(self.pos) if not collision: self.pos_x += self.direction.x self.pos_y += self.direction.y consumed = self.game.board[self.pos_y][self.pos_x].on_step(self) if consumed: self.game.board[self.pos_y][self.pos_x].kill() self.game.board[self.pos_y][self.pos_x] = tiles.Tile(self.settings, self.pos_x, self.pos_y) if self.pos == self.game.minotaur.pos: if self.power / len(self.player_list) > 5: self.game.minotaur.kill() logger.info("Minotaur is dead") self.game.text_display.print("Zabiliście Minotaura!") else: self.game.squad.dead = True logger.info("Player is dead") self.game.text_display.print("Nie żyjecie!") for player in self.player_list: player.update_goals()
def __init__(self, scene): self.scene = scene self.root_obj = None self.tiles = dict() id_counter = 0 for obj in self.scene.objects: if 'TILE' in obj: # Mutate the game object into a tile: new_tile = tiles.Tile(obj, id_counter) # Check the mutation succeeded assert isinstance(new_tile, tiles.Tile) self.tiles[new_tile.name] = new_tile self.root_obj = new_tile.parent id_counter += 1 self.pieces = list() self.direction = False
def makeMap(self, cols, rows): # Apply weights to land types because py2 doesn't have random.choices() lands = ["grassland"] * 5 + ["forest"] * 3 + ["mountain"] * 2 waters = ['ocean'] land_chance = 0.5 # Set up the new tile array new_map = [] for r in range(rows): new_row = [] for c in range(cols): # Choose terrain type for tile is_land = random.random() < land_chance if is_land: new_terrain = random.choice(lands) else: new_terrain = random.choice(waters) # Add tile to grid new_tile = tiles.Tile(self, new_terrain, c, r) new_row.append(new_tile) new_map.append(new_row) return new_map
signal.signal(signal.SIGINT, signal_handler) # ************************** River specific code start ************************** #One time setup of the scenario map variables JohnRiverMap = [] #This is the scenario map which holds all the tiles JohnRiverTiles = [ ] #Important tiles, will be randomized over the map. (Only placed once) JohnRiverFluffTiles = [ ] #"filler tiles" to populate around the "real scenario tiles". (Can appear multiple times) JohnRiverAvailableItems = [ "Lost Lure", "Fishing Hook", "Wrench" ] #Available items which can be placed randomly over the map. #These are the important scenario tiles. Put your items and events here. #Usage:Tiles.Tile("Tile description",ignore this field, pass a number,"name of an event you can test for and act on","name of item which can be found on tile" JohnRiverTiles.append( Tiles.Tile("a pool of floating fish", 1, "", "a nearly-dead fish")) JohnRiverTiles.append( Tiles.Tile("someone 'fishing' in a boat", 1, "Fisherman", "")) JohnRiverTiles.append( Tiles.Tile("a snake in the water", 1, "Snake", "one ticked off snake")) JohnRiverTiles.append( Tiles.Tile("water with a shiny surface", 1, "Net", "fishing net")) JohnRiverTiles.append( Tiles.Tile("a diner on the shore", 1, "PulpFictionRestaurant", "a greasy spoon")) JohnRiverTiles.append( Tiles.Tile("open waters with an abandon boat", 1, "BrokenBoat", "spare boat parts")) JohnRiverTiles.append( Tiles.Tile("shack with a tin roof .... RUSTED..", 1, "B52", "")) JohnRiverTiles.append(
def score_word(word): return sum([tiles.Tile(i) for i in word])
import sea_monster cur_dir = os.path.dirname(os.path.abspath(__file__)) mytiles = [] with open(f"{cur_dir}/input") as f: cur_line = f.readline() while cur_line != "": tile_id = int(cur_line.strip().split()[1][:-1]) tile_layout = [] cur_line = f.readline() while cur_line.strip() != "": tile_layout.append([x for x in cur_line.strip()]) cur_line = f.readline() mytiles.append(tiles.Tile(tile_id, tile_layout)) cur_line = f.readline() corners = [] tile_lookup = {} for tile in mytiles: tile.determine_possible_neighbors(mytiles) # tile.print_neighbor_candidates() if tile.number_of_edges_possible_to_connect() == 2: corners.append(tile.id) tile_lookup[tile.id] = tile corner_val = 1 for x in corners: corner_val *= x
signal.signal(signal.SIGINT, signal_handler) # ************************** River specific code start ************************** #One time setup of the scenario map variables RiverMap = [] #This is the scenario map which holds all the tiles RiverTiles = [ ] #Important tiles, will be randomized over the map. (Only placed once) RiverFluffTiles = [ ] #"filler tiles" to populate around the "real scenario tiles". (Can appear multiple times) RiverAvailableItems = [ "Gold Coin", "Fishing Hook", "Wrench" ] #Available items which can be placed randomly over the map. #These are the important scenario tiles. Put your items and events here. #Usage:Tiles.Tile("Tile description",ignore this field, pass a number,"name of an event you can test for and act on","name of item which can be found on tile" RiverTiles.append( Tiles.Tile("a pool of floating fish", 1, "", "a nearly-dead fish")) RiverTiles.append(Tiles.Tile("someone fishing in a boat", 1, "Fisherman", "")) RiverTiles.append(Tiles.Tile("river Tile 2", 1, "", "")) RiverTiles.append( Tiles.Tile("a snake in the water", 1, "Snake", "a dead snake")) RiverTiles.append( Tiles.Tile("water with a shiny surface", 1, "Net", "fishing net")) RiverTiles.append(Tiles.Tile("river Tile 4", 1, "", "old lure")) RiverTiles.append(Tiles.Tile("river Tile 5", 1, "", "torn shirt")) #These are the filler scenario tiles. Don't put items here. You can do it separately when the GenerateMap() code is called You can put events here. RiverFluffTiles.append(Tiles.Tile("clear, open water", 0, "", "")) RiverFluffTiles.append(Tiles.Tile("blue water", 0, "", "")) RiverFluffTiles.append(Tiles.Tile("beautiful, blue water", 0, "", "")) RiverFluffTiles.append(Tiles.Tile("slightly, murky water", 0, "", "")) #Generate the scenario map! RiverMap = GenerateMap(5, 5, RiverTiles, RiverFluffTiles, RiverAvailableItems)
def clear(self): self._allTiles = { xyPos: tiles.Tile(self, xyPos) for xyPos in self.allPoses() } self.regionSources = []
seq = tiles.QuiltSequence(seed_quilt, name="triples", n_columns=3) seq.extend_sequence(reps=6) seq.extend_sequence(reps=7, fg_colors=["aqua", "CornFlowerBlue", "navy"], bg_colors=["white", "aqua", "CornFlowerBlue", "navy"], left_edge_swatch=["CornFlowerBlue", "aqua"], top_edge_swatch=["CornFlowerBlue", "aqua"]) seq.implement(overwrite=True) seq.extend_sequence(reps=7, fg_colors=["aqua", "CornFlowerBlue", "navy"], bg_colors=["CornFlowerBlue", "navy"]) seq.implement() t = tiles.Tile(bg_color="white", ellipses=[(-1, 0, 1, 1, webcolors.name_to_rgb("red")), (1, 0, 1, 1, webcolors.name_to_rgb("red"))], name="tmp", tile_size=(70, 70)) # (-1,1,2,2,webcolors.name_to_rgb("red")) # Tile filename will be "tmp_40" t.create_tile_image(overwrite=True) q = tiles.Quilt(grid_size=(5, 5), ellipses) reload(tiles) u = tiles.Tile(bg_color="white", ellipses=[(-1, -1, 2, 2, "red"), (1, 1, 2, 2, "SeaGreen"), (0, 1, .5, .5, "blue")], tile_size=[80, 80], name="tmp") u.create_tile_image(overwrite=True) [webcolors.rgb_to_name(x) for x in u.edge_colors]
def __init__(self, settings: Settings): ### PYGAME INITS pygame.init() pygame.font.init() pygame.mixer.init() ### self.settings = settings self.main_surf = pygame.Surface(self.settings.resolution) self.background = make_background(pygame.image.load("assets/tile.png"), self.settings.resolution) self.display = pygame.display.set_mode( (self.settings.resolution[0] + 300, self.settings.resolution[1])) self.display.set_colorkey(self.settings.background_color) self.board = [] self.orphans = [ ] # Tile objects which for some reason are not in self.board # fill board with empty tiles for i in range(settings.width): row = [] for j in range(settings.height): row.append(tiles.Tile(settings, i, j)) self.board.append(row) self.ticks = 0.0 # game clock. Increments by 1 every turn. Player moves on 1, 2, 3.. etc. Minotaur on 1.5, 2.5, 3.5.. etc. # This should be OK in terms of floating point math self.last_tick_time = time.time() self.labyrinth_finished = False self.last_player_move = 0 self.last_minotaur_move = -0.5 self.running = False self.running = True ### SERVER INITS self.server_queue = Queue() # main queue to receive movements self.new_player_queue = Queue() # queue to receive new player objects self.goal_queue = Queue() # queue to send new goals self.info_queue = Queue() # queue to send gametime info self.server = server.Server("0.0.0.0", 6666, 6665, self.server_queue, self.new_player_queue, self.goal_queue, self.info_queue) self.server.start() ### unscaled = pygame.image.load( "assets/wall_horizontal.png").convert_alpha() self.wall_horizontal = pygame.transform.scale( unscaled, (self.settings.tile_size * 7 // 6, self.settings.tile_size)) unscaled = pygame.image.load( "assets/wall_vertical.png").convert_alpha() self.wall_vertical = pygame.transform.scale( unscaled, (self.settings.tile_size // 6, self.settings.tile_size)) # prepare sound self.sound_bank = {} self.make_sound_bank() c = pygame.mixer.Channel(AMBIENT_CHANNEL) if not self.settings.mute: c.play(self.sound_bank["ambient"], loops=-1) self.unmute_thread: DelayedCall = None # self.clock = pygame.time.Clock() self.text_display = textDisplay.TextDisplay((300, 300), "dejavu", 24) self.text_display.print("Test") self.squad = group.Squad(settings, self) self.minotaur = minotaur.Minotaur(settings, self) self.minotaur.pos = (15, 15) self.all_sprites = pygame.sprite.Group() self.all_sprites.add(self.squad) self.all_sprites.add(self.minotaur) self.trap_gen = contentGen.TrapContentGen(settings, self) self.content_gens: List[contentGen.ContentGen] = [ contentGen.TreasureContentGen(settings, self) for i in range(3) ] self.content_gens.append(self.trap_gen) self.content_gens.append( contentGen.OutOfLabirynthContentGen(settings, self)) self.content_gens.append(contentGen.WeaponContentGen(settings, self)) self.content_gens.append(contentGen.MinotaurContectGen(settings, self)) for i in range(150): self.add_special_tile() self.wall_list, entrance_wall, exit_wall = labgen.actually_gen_lab( settings.height) self.squad.pos = entrance_wall.x1, entrance_wall.y1 exit_tile = tiles.LabExit(self.settings, exit_wall.x1 - 1, exit_wall.y1) self.board[exit_wall.y1][exit_wall.x1 - 1] = exit_tile self.wall_graph = wall_graph( self.wall_list) # Graph representing nodes blocked by walls self.nrwg = minotaur.non_retarded_wall_graph( self.wall_graph, settings) # Graph representing nodes accessible
def random_tile(): return tiles.Tile(tiles.COLORS)
def main(): london_x1 = 51.700559 london_y1 = -0.497709 london_x2 = 51.308527 london_y2 = 0.246893 big_tile = tiles.Tile(london_x1, london_y1, london_x2, london_y2) smaller_tiles = tiles.fragment_tile(big_tile, tiles.m_to_lat(200), tiles.m_to_lon(200 / 3, london_x1)) filename = 'fusion.csv' done_tiles = {} for i in xrange(len(smaller_tiles)): done_tiles[i] = -1.0 for i in xrange(len(smaller_tiles)): tile = smaller_tiles[i] key = tile.key if done_tiles[key] >= 0: continue pollution_value = pollution.get_pollution_value( tile.start_x, tile.start_y, 0) done_tiles[key] = pollution_value neighbour_keys = [ key + 1, key - 1, (key + 169), (key - 169), (key + 170), (key + 168), (key - 170), (key - 168) ] weights = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for j in xrange(len(neighbour_keys)): index = neighbour_keys[j] if 0 < index < len(smaller_tiles): if done_tiles[index] >= 0: done_tiles[index] = (done_tiles[index] + (weights[j] * pollution_value)) / 2.0 else: done_tiles[index] = weights[j] * pollution_value print "Progress: " + str(i) + "/" + str(len(smaller_tiles)) with open(filename, 'w') as f: for tile in smaller_tiles: line = "\"" + tile.kml() + "\"" + ", " + str( done_tiles[tile.key]) + ", " + str(tile.key) + "\n" f.write(line) success = False tries = 0 while (success is False) and tries < 3: tries += 1 try: print "Try no:" + str(tries) + " to update table" update_table(filename) success = True except Exception: print "Failed to update table" if success: print "Last fusion update: " + str(datetime.datetime.now())