Example #1
0
 def __init__(self, qra, zoom):
   self.qra = qra
   self.zoom = zoom
   self.lonlat = Tiles.qra_lonlat(self.qra)
   (self.lon, self.lat) = self.lonlat
   xytile = Tiles.lonlat_tile(self.lon, self.lat, self.zoom)
   self.osm_tile = OSM_Tile("(POI)", xytile, (0, 0), self.zoom)
Example #2
0
 def getCavernTileMap(self):
     TileMap = []
     #chance = 0.6
     map, caverns = CellularAutomata.generateMap(self.cellwidth,
                                                 self.cellheight,
                                                 chance=0.6,
                                                 steps=6,
                                                 birthLimit=3,
                                                 deathLimit=4)
     for rows in range(0, len(map)):
         row = []
         for columns in range(0, len(map[0])):
             if not map[rows][columns]:
                 row.append(
                     Tiles.Tile((columns, rows),
                                self.tileSheet.returnTile(0, 0), False))
             else:
                 #row.append(Tiles.AnimTile((columns,rows), self.animTileSheet,True,0,3,10))
                 row.append(
                     Tiles.Tile((columns, rows),
                                self.tileSheet.returnTile(2, 0), True))
         TileMap.append(row)
     #Adds the tile that goes to next level
     EndLocation = choice(caverns[-2])
     TileMap[EndLocation[0]][EndLocation[1]] = Tiles.LevelTile(
         (EndLocation[1], EndLocation[0]), self.tileSheet.returnTile(3, 0),
         False)
     return TileMap, caverns
Example #3
0
    def getBlits(self):
        if self.isEarth or not self.seen:
            return {"coords": self.coords, "blits": []}
        blits = []

        if self.visible:
            blits.append({
                "tile": Tiles.tiles[self.tileset][self.fillType],
                "layer": TERRAIN_LAYER
            })

            if self.terrainFeature != None:
                blits.append({
                    "tile": Tiles.features[self.terrainFeature],
                    "layer": FEATURE_LAYER
                })

            if self.character != None:
                blits.append({
                    "tile": self.character.image,
                    "layer": CHARACTER_LAYER
                })
        else:
            terrainTile = Tiles.darken(
                Tiles.tiles[self.tileset][self.fillType])

            blits.append({"tile": terrainTile, "layer": TERRAIN_LAYER})

            if self.terrainFeature != None:
                featureTile = Tiles.darken(Tiles.features[self.terrainFeature])
                blits.append({"tile": featureTile, "layer": FEATURE_LAYER})

        return {"coords": self.coords, "blits": blits}
Example #4
0
  def clip_lcd_tiles(self):
    description_fn = "%s-%s-%dx%d.txt" % (SERVER_TYPE, qra, LCD_TILE_WIDTH, LCD_TILE_HEIGHT)
    try:
	os.remove(description_fn)
    except:
	pass
    poi_xy = composite_tile.lonlat_xy_in_composite_osm_tile(poi.lonlat)
    if DEBUG: print "poi_xy %d %d in composite_osm_tile" % poi_xy
    center_lcd_tile_center_xy = (LCD_TILE_WIDTH / 2, LCD_TILE_HEIGHT / 2)
    if DEBUG: print "center_lcd_tile_center_xy = %s %s" % (center_lcd_tile_center_xy)
    for dy in LCD_TILES_DELTAS:
        for dx in LCD_TILES_DELTAS:
          if DEBUG: print "Creating LCD_Tile %s (%d %d) " % (Tiles.rose(LCD_TILES_OFFSETS, dx, dy), dx, dy)
          lcd_tile_dxy = vadd(poi_xy, vmul(LCD_TILE_SIZE, (dx, dy)))
          composite_box_top_left_xy = vsub(lcd_tile_dxy, center_lcd_tile_center_xy)
          composite_box_bottom_right_xy = vadd(lcd_tile_dxy, center_lcd_tile_center_xy)
          box = composite_box_top_left_xy + composite_box_bottom_right_xy
          lcd_image = self.composite_tile.composite_image.crop(box)
          osm_tl_dxdy = vsub(vidiv(composite_box_top_left_xy, OSM_TILE_SIZE), OSM_TILES_OFFSETS)
          osm_br_dxdy = vsub(vidiv(composite_box_bottom_right_xy, OSM_TILE_SIZE), OSM_TILES_OFFSETS)
	  if DEBUG:
	      print "  LCD_Tile composite_box_top_left_xy = %d %d" % (composite_box_top_left_xy)
	      print "  LCD_Tile osm_tl_dxdy = %d %s upper left is at this location in composite_box: %d %d" % (osm_tl_dxdy + composite_box_top_left_xy)
	      print "  LCD_Tile osm_br_dxdy = %d %s bottom right is at this location in composite_box: %d %d" % (osm_br_dxdy + composite_box_top_left_xy)
	      print "osm_tl_dxdy = %s osm_br_dxdy = %s" % (osm_tl_dxdy, osm_br_dxdy)
          osm_tile_tl = composite_tile.osm_tiles_by_dxdy[osm_tl_dxdy]
          osm_tile_br = composite_tile.osm_tiles_by_dxdy[osm_br_dxdy]
	  if DEBUG:
	      print "  OSM_TILE pixels_per_degree %f %f, %f %f" % (osm_tile_tl.pixels_per_degree+osm_tile_br.pixels_per_degree)
	      print "  OSM_Tile %s top_left_lonlat %f %f" % (osm_tile_tl.name, osm_tile_tl.top_left_lon, osm_tile_tl.top_left_lat)
          lcd_tile_top_left_in_osm_tile = vmod(composite_box_top_left_xy, OSM_TILE_SIZE)
          lcd_tile_bottom_right_in_osm_tile = vmod(composite_box_bottom_right_xy, OSM_TILE_SIZE)
          lcd_tile_top_left_lonlat = osm_tile_tl.xy_lonlat(lcd_tile_top_left_in_osm_tile)
          lcd_tile_bottom_right_lonlat = osm_tile_br.xy_lonlat(lcd_tile_bottom_right_in_osm_tile)
          #print "  LCD_Tile %s (%d,%d) lcd_tile_top_left_in_osm_tile: %d %d" % ((Tiles.rose(LCD_TILES_OFFSETS, dx, dy), dx, dy) + lcd_tile_top_left_in_osm_tile)
          #print "  LCD_Tile %s (%d,%d) top left lon lat %f %f" % ((Tiles.rose(LCD_TILES_OFFSETS, dx, dy), dx, dy) + lcd_tile_top_left_lonlat)
          if False:
            self.lcd_tiles[(dx,dy)] = LCD_Tile(Tiles.rose(LCD_TILES_OFFSETS, dx, dy), (dx,dy), lcd_tile_top_left_lonlat, lcd_tile_bottom_right_lonlat, lcd_image)
          png_fn = self.calculate_lcd_tile_fn(dx, dy)
          bmp_fn = self.calculate_lcd_bmp_fn(dx, dy)
          tl_latlon = Tiles.vswap(lcd_tile_top_left_lonlat)
          br_latlon = Tiles.vswap(lcd_tile_bottom_right_lonlat)
          lcd_image.save(png_fn, "PNG")
	  lcd_image.save(bmp_fn, "BMP")
          description = "%d,%d %d,%d\n" % tuple([round(x*1e6) for x in (tl_latlon[0],tl_latlon[1], br_latlon[0],br_latlon[1])])
	  self.lat_degrees_per_pixel += (br_latlon[0] - tl_latlon[0])
  	  self.lon_degrees_per_pixel += (br_latlon[1] - tl_latlon[1])
	  if dx == 0 and dy == 0:
	      poi_lcd_tile_tl_latlon = tl_latlon
	  #print "Adding LCD map four corners to %s " % (description_fn)
	  with open(description_fn, 'a') as f:
	      f.write(Tiles.rose(LCD_TILES_OFFSETS, dx,dy))
	      f.write(" ")
	      f.write(description)
    self.save_pixels_file(poi_lcd_tile_tl_latlon)
Example #5
0
 def draw_debug(self, draw):
   # draw outlines of original OSM tiles in GREEN
   for dy in OSM_TILES_DELTAS:
       for dx in OSM_TILES_DELTAS:
         box1 = vmul(OSM_TILE_SIZE, (vadd((dx, dy), OSM_TILES_OFFSETS)))
         box2 = vmul(OSM_TILE_SIZE, (vadd((dx, dy), vadd(OSM_TILES_OFFSETS, (1, 1)))))
         box = box1+box2
         draw.rectangle(box, outline='#00ff00')
   # Draw dot at QRA in BLUE
   (px, py) = self.lonlat_xy_in_composite_osm_tile(poi.lonlat)
   #print "qra (px,py) = (%d, %d)" % (px,py)
   Tiles.drawCircle(draw, px, py, 2, '#0000ff')
Example #6
0
  def __init__(self, name, xytile, tile_delta, zoom):
    self.name = name
    self.xytile = xytile
    self.tile_delta = tile_delta
    self.zoom = zoom
    self.osm_tile_image = None
    self.size_in_degrees = Tiles.tile_size_in_degrees(self.xytile, self.zoom)
    self.top_left_lonlat = Tiles.tile_top_left_corner_lonlat(self.xytile, self.zoom)
    (self.top_left_lon, self.top_left_lat) = self.top_left_lonlat
    self.pixels_per_degree = vdiv(OSM_TILE_SIZE, self.size_in_degrees) # lon,lat order
    if DEBUG:
	print "%s size in degrees dlon=%f dlat=%f" % ((self.name,) + self.size_in_degrees)
	print "%s pixels_per_degree = don=%f dlat%f" % ((self.name,) + self.pixels_per_degree)
Example #7
0
    def generate(self, scenery):
        for i in range(len(self.bMap)):

            scenery[self.bMap[i].y][self.bMap[i].x] = tiles.Scenery(
                True, False, self.bMap[i].bImg, self.bMap[i].tImg,
                self.bMap[i].offSet, 0, -10)
            for y in range(self.bMap[i].y - self.bMap[i].ySize // 2,
                           self.bMap[i].y + self.bMap[i].ySize // 2 + 1, 1):
                for x in range(self.bMap[i].x - self.bMap[i].xSize // 2,
                               self.bMap[i].x + self.bMap[i].xSize // 2 + 1,
                               1):
                    if x != self.bMap[i].x or y != self.bMap[i].y:
                        scenery[y][x] = 6
            for y in range(self.bMap[i].y - self.bMap[i].ySize // 2,
                           self.bMap[i].y + self.bMap[i].ySize // 2 + 1):
                for x in range(self.bMap[i].x - (self.bMap[i].xSize // 2 + 2),
                               self.bMap[i].x + self.bMap[i].xSize // 2 + 2):
                    if y == self.bMap[i].y - self.bMap[
                            i].ySize // 2 - 1 or y == self.bMap[
                                i].y + self.bMap[
                                    i].ySize // 2 or x == self.bMap[i].x - (
                                        self.bMap[i].xSize // 2 +
                                        1) or x == self.bMap[
                                            i].x + self.bMap[i].xSize // 2 + 1:
                        scenery[y][x] = 0
Example #8
0
 def __getTileMap(self, map):
     tiles = []
     #Could probably do this using map or filter or replace, one of those functions
     for y in range(len(map)):
         row = []
         for x in range(len(map[0])):
             if map[y][x]:
                 row.append(
                     Tiles.Tile(gridPos=(x, y),
                                collision=False,
                                sprite=self.spritesheet.returnSprite(0, 0)))
             else:
                 row.append(
                     Tiles.Tile(gridPos=(x, y),
                                collision=True,
                                sprite=self.spritesheet.returnSprite(1, 0)))
         tiles.append(row)
     return tiles
Example #9
0
	def getBlits(self):
		if self.isEarth or not self.seen:
			return {
				"coords": self.coords,
				"blits": []
			}
		blits = []

		if self.visible:
			blits.append({
				"tile": Tiles.tiles[self.tileset][self.fillType],
				"layer": TERRAIN_LAYER
			})

			if self.terrainFeature != None:
				blits.append({
					"tile": Tiles.features[self.terrainFeature],
					"layer": FEATURE_LAYER
				})

			if self.character != None:
				blits.append({
					"tile": self.character.image,
					"layer": CHARACTER_LAYER
				})
		else:
			terrainTile = Tiles.darken(Tiles.tiles[self.tileset][self.fillType])

			blits.append({
				"tile": terrainTile,
				"layer": TERRAIN_LAYER
			})

			if self.terrainFeature != None:
				featureTile = Tiles.darken(Tiles.features[self.terrainFeature])
				blits.append({
					"tile": featureTile,
					"layer": FEATURE_LAYER
				})

		return {
			"coords": self.coords,
			"blits": blits
		}
Example #10
0
    def create_tiles(self):
        """
        Create tiles from the good sized of image.
        Return with a Tiles object, which has a list of the image tiles - Tile object.
        """
        tiles = Tiles.Tiles(grid=self.grid)

        for row in range(self.grid):
            for col in range(self.grid):
                x0 = col * self.tile_size
                y0 = row * self.tile_size
                x1 = x0 + self.tile_size
                y1 = y0 + self.tile_size
                tile_image = ImageTk.PhotoImage(
                    self.image.crop((x0, y0, x1, y1)))
                tile = Tiles.Tile(self, tile_image, (row, col))
                tiles.add(tile)
        tiles.set_gap(-1)
        return tiles
Example #11
0
def creation_map_objects():
    """
    Generate based on the numpy array all fields

    Test:
        -check if map format is 6x13 and tiles are 140x140
        -test if the is exact one start and exact one end
        -test the path is without holes and has no loops

    """
    global towerplace_bool, MAP, towerfields
    count_ways = 0
    ty = 0
    for y in range(6):
        tx = 0
        if y > 0:
            tx = 50
        for x in range(13):
            value = MAP[y, x]
            if value == 0:
                if not towerplace_bool:
                    towerfields.append(Tiles(tx, ty, 140, 140,
                                             clickable_field))
            elif value == 5:
                towerfields.append(Tiles(tx, ty, 140, 140, obstacle_map))
            elif value == 8:
                draw_path(count_ways)
                count_ways += 1
            elif value == 1:
                tx += 50
                towerfields.append(Tiles(tx, ty, 140, 140, start_map))
            elif value == 2:
                towerfields.append(Tiles(tx, ty, 140, 140, end_map))
            elif 10 < value < 39:
                first_place = value % 10
                second_place = value // 10
                towerfields.append(
                    Tiles(tx, ty, 140, 140,
                          tower_image[second_place - 1][first_place - 1]))
            tx += 140
        ty += 140
    towerplace_bool = True
Example #12
0
def draw_path(path_pos):
    """
    Generate and store the position of a wayfield on the map at a position with the correct image based on the rotation

    Arguments: postion on path

    Test:
        -Path has to be ready
        -screen has to be 1920x1080 and all Tiles 140x140
        -Test if the end is reached or a position not on the path

    """
    global wayfields

    current_pos = PATH[path_pos][0]
    next_pos = PATH[path_pos + 1][0]
    pos_x = 50 + (PATH[path_pos][1] * 140)
    pos_y = (PATH[path_pos][2]) * 140
    if current_pos == 'up' and next_pos == 'right' or current_pos == 'left' and next_pos == 'down':
        wayfields.append(Tiles(pos_x, pos_y, 140, 140, curve2))
    elif current_pos == 'up' and next_pos == 'left' or current_pos == 'right' and next_pos == 'down':
        wayfields.append(Tiles(pos_x, pos_y, 140, 140, curve1))
    elif current_pos == 'down' and next_pos == 'right' or current_pos == 'left' and next_pos == 'up':
        wayfields.append(Tiles(pos_x, pos_y, 140, 140, curve3))
    elif current_pos == 'down' and next_pos == 'down' or current_pos == 'up' and next_pos == 'up':
        wayfields.append(Tiles(pos_x, pos_y, 140, 140, way_vertical))
    elif current_pos == 'right' and next_pos == 'right' or current_pos == 'left' and next_pos == 'left':
        wayfields.append(Tiles(pos_x, pos_y, 140, 140, way_horizontal))
    elif current_pos == 'right' and next_pos == 'up' or current_pos == 'down' and next_pos == 'left':
        wayfields.append(Tiles(pos_x, pos_y, 140, 140, curve4))
Example #13
0
def generateCellularAutomata(width: int = 40,
                             height: int = 30,
                             chance: float = 0.65,
                             steps: int = 2,
                             birthLimit: int = 3,
                             deathLimit: int = 4) -> list:
    '''Returns a tilemap from the CellularAutomata method'''
    arr, caverns = CellularAutomata.driver(width, height, chance, steps,
                                           birthLimit, deathLimit)

    tileMap = []
    # Iterates over the 2D list returned by the cellauto algorithm
    # and places a non collidable tile at a true value, and a collidable
    # tile at the false values
    for y in range(0, len(arr)):
        row = []
        for x in range(0, len(arr[0])):
            if arr[y][x] == True:
                row.append(
                    Tiles.Tile(gridPos=(x, y),
                               collision=False,
                               sprite=spritesheet.returnSprite(0, 0)))
            elif arr[y][x] == False:
                row.append(
                    Tiles.Tile(gridPos=(x, y),
                               collision=True,
                               sprite=spritesheet.returnSprite(1, 0)))
            '''
            elif arr[y][x] == 'corridoor':
                row.append(Tiles.Tile(gridPos=(x, y),
                                      collision=False,
                                      sprite=spritesheet.returnSprite(0, 2)))
            '''
        tileMap.append(row)
    y, x = choice(caverns[-1])
    tileMap[y][x] = Tiles.LevelTile(gridPos=(x, y),
                                    sprite=spritesheet.returnSprite(0, 2))
    return tileMap, caverns
Example #14
0
def create_map():
    #Create The Map

    #Global Variables Created
    global continent_map
    continent_map = [[Tiles.Tile("Ocean") for y in range(MAP_HEIGHT)]
                     for x in range(MAP_WIDTH)]

    global cities
    cities = []

    #Generate Contents in Map
    generate_land()
    generate_cities()
Example #15
0
    def __init__(self, program):
        self.x = 0
        self.y = 0
        self.surface = Tiles.Hallway()
        self.output = []
        self.Computer = Intcode.Intcode()
        self.Computer.memory = program
        self.Computer.increase_memory(10)

        self.Computer.output = asyncio.Queue()
        self.Computer.output_method = self.Computer.output.put_nowait

        self.output = asyncio.Queue()
        self.Computer.input_method = self.output.get

        self.untested_moves = []
        self.direction = 1
Example #16
0
    def __init__(self, window_width, window_height):

        self.size = window_width, window_height
        self.window_width = window_width
        self.window_height = window_height

        self.screen = pygame.display.set_mode(self.size)
        pygame.display.set_icon(load_image('images', 'icon.png'))
        pygame.display.set_caption('The Dungeons')
        self.clock = pygame.time.Clock()

        self.camera = Camera.Camera(self.window_width, self.window_height)
        self.floor = namedtuple('Floor', ['type', 'name'])('floor', 0)
        self.player = None

        # initialize sprites
        self.game_over_button_sprite = pygame.sprite.GroupSingle()
        self.main_button_sprites = pygame.sprite.Group()
        self.portal_sprite = pygame.sprite.GroupSingle()

        self.player_sprite = pygame.sprite.GroupSingle()
        self.sword_sprite = pygame.sprite.GroupSingle()
        self.animated_sprites = pygame.sprite.Group()
        self.potion_sprites = pygame.sprite.Group()
        self.floor_sprites = pygame.sprite.Group()
        self.enemy_sprites = pygame.sprite.Group()
        self.boxes_sprites = pygame.sprite.Group()
        self.side_sprites = pygame.sprite.Group()
        self.all_sprites = pygame.sprite.Group()
        self.ui_sprites = pygame.sprite.Group()

        self.tiles = Tiles.return_tiles()
        self.connection = sqlite3.connect('database.db')

        # special player variables
        self.player_health = 20
        self.player_score = 0

        self.FPS = 60  # const
        self.k = 19  # special variable which need for right room's drawing
        self.bg_color = pygame.Color(29, 16, 70)

        sound = pygame.mixer.Sound('data\\soundtrack1.wav')
        sound.play(10)
        sound.set_volume(0.03)
Example #17
0
  def retrieve(self):
    if self.composite_image == None:
      self.composite_image = Image.new("RGB", (OSM_TILE_WIDTH * OSM_TILES_SQUARE, OSM_TILE_HEIGHT * OSM_TILES_SQUARE), (0, 0, 0))

      for dy in OSM_TILES_DELTAS:
        for dx in OSM_TILES_DELTAS:
          dxdy = (dx, dy)
          osm_tile = OSM_Tile(Tiles.rose(OSM_TILES_OFFSETS, dx, dy), vadd((self.x, self.y), dxdy), dxdy, zoom)
          self.osm_tiles_by_xytile[osm_tile.xytile] = osm_tile
	  if DEBUG: print "Adding self.osm_tiles_by_dxdy[%s] = osm_tile" % (dxdy,)
          self.osm_tiles_by_dxdy[dxdy] = osm_tile
          osm_tile_image = osm_tile.retrieve()
          box = (vmul(OSM_TILE_SIZE, vadd((dx, dy), OSM_TILES_OFFSETS)) +
                 vmul(OSM_TILE_SIZE, vadd((dx, dy), vadd(OSM_TILES_OFFSETS, (1, 1)))))
          self.composite_image.paste(osm_tile_image, box)
      fn = "%s-%s-%dx%dx%d.png" % (SERVER_TYPE, qra, OSM_TILE_WIDTH, OSM_TILE_HEIGHT, OSM_TILES_SQUARE)
      if DEBUG: print("Saving composite map image to " + fn)
      self.composite_image.save(fn)
    return self.composite_image
 def render(self, screen):
     left = self.left
     top = self.top
     self.max_width = len(self.board[0])
     self.max_height = len(self.board)
     for y in range(self.max_height):
         for x in range(self.max_width):
             if (x != self.max_width - 1 or y != 0) and (
                     x != 0 or y != self.max_height - 1) and self.no_tiles:
                 Tiles.Tile(left, top, self.tile_sprites)
             pygame.draw.rect(screen, color('brown'),
                              (left, top, self.cell_size, self.cell_size),
                              1)
             left += self.cell_size
         top += self.cell_size
         left = self.left
     pygame.draw.rect(screen, color('brown'),
                      (self.left, self.top, self.cell_size * self.width,
                       self.cell_size * self.height), 2)
     self.no_tiles = False
Example #19
0
    def from_file(path, game):
        import json
        with open(path, 'r') as f:
            json_data = f.read()
            data = json.loads(json_data)

            author = data["author"]
            board_data = data["board"]

            board = [[0 for _ in range(16)] for _ in range(16)]

            for i in range(16):  #x
                for j in range(16):  #y
                    board[i][j] = Tiles.from_json_data(board_data[i][j])

            board, starting_red, starting_blue = MapData.link_special_tiles(
                game, board)

            print("Map loaded")
            return MapData(author, board, starting_red, starting_blue)
Example #20
0
    def __init__(self, players, connector=None, configuration=None, score_calc=None):
        self.player_profiles = [player.get_game_info() for player in players]
        self.player_number = len(self.player_profiles)
        self.start_player = -1

        self.tiles = Tiles.read_hand(config.allTileString)
        self.fuuro_lists = [[0] * 20] * 4
        self.dora_list = []
        self.agari_tile = Tiles.Tile()
        self.tumo = False
        self.kyoutaku_bon = 0                                   # number of tensu-bou on table

        self.bakaze = 0                                         # 0 -> Tou-huu ni settee s***e
        self.gyouku = 0                                         # 3 -> Han Cyan all last
        self.honba = 0
        self.turn = 0                                           # curr_player = turn % 4

        self.random_method = random.shuffle                     # default method
        self.configuration = configuration                      # configuration from utility
        self.score_calc = mjscore.MJScore()

        self.client_connector = connector
Example #21
0
 def render(self, screen):
     left = self.left
     top = self.top
     self.max_width = len(self.board[0])
     self.max_height = len(self.board)
     for y in range(self.max_height):
         for x in range(self.max_width):
             if (x != self.max_width - 1 or y != 0) and (
                     x != 0 or y != self.max_height - 1) and self.no_tiles:
                 Tiles.Tile(left, top, self.tile_sprites)
             elif x == self.max_width - 1 and y == 0:
                 pygame.draw.rect(
                     screen, color('orange'),
                     (left, top, self.cell_size, self.cell_size), 0)
                 if not game.orange_moved:
                     screen.blit(
                         GetImage("janitor_orange1.png", (76, 76),
                                  colorkey=-1).load_image(), (left, top))
             elif x == 0 and y == self.max_height - 1:
                 pygame.draw.rect(
                     screen, color('aquamarine3'),
                     (left, top, self.cell_size, self.cell_size), 0)
                 if not game.blue_moved:
                     screen.blit(
                         GetImage("janitor_blue1.png", (76, 76),
                                  colorkey=-1).load_image(), (left, top))
             pygame.draw.rect(screen, color('brown'),
                              (left, top, self.cell_size, self.cell_size),
                              1)
             left += self.cell_size
         top += self.cell_size
         left = self.left
     pygame.draw.rect(screen, color('brown'),
                      (self.left, self.top, self.cell_size * self.width,
                       self.cell_size * self.height), 2)
     self.no_tiles = False
Example #22
0
    def __init__ ( self, alpha,  numFloatInputs, numIntInputs, memorySize, gamma, numTilings, tableDimensionality ) : 
        
        self.alpha = alpha 

        self.numFloatInputs = numFloatInputs 
        self.floatInputs = [] 
        for i in range( numFloatInputs ) : 
            self.floatInputs.append ( 0.0 ) ; 

        self.numIntInputs = numIntInputs 
        self.intInputs = [] 
        for i in range( numIntInputs ) : 
            self.intInputs.append ( 0 ) ; 
 
        self.numTilings = numTilings
        self.tiles = []        
        for i in range ( numTilings ) :
            self.tiles.append ( 0 ) 

    
        self.memorySize = memorySize 
        self.u = []  # CMAC arrays        
        for i in range ( memorySize ) :
            #self.u.append ( 1.0 / ( 1.0 - gamma ) )                
            #self.u.append ( 1.0 / ( 1.0 - gamma - 0.01 ) ) # this is to account for the fact that gamma = 1 for episodic tasks, and gamma < 1 for continuing tasks.
            #self.u.append ( random.randint ( 1, 20 ) ) #1.0 / ( 1.0 - gamma - 0.01 ) ) # this is to account for the fact that gamma = 1 for episodic tasks, and gamma < 1 for continuing tasks.
            self.u.append ( 2 ) #1.0 / ( 1.0 - gamma - 0.01 ) ) # this is to account for the fact that gamma = 1 for episodic tasks, and gamma < 1 for continuing tasks.
            #print ( "Memory Size: ", memorySize, "self.u[", i, "]", self.u[i], "Gamma:" , gamma, "1.0-gamma", 1.0 - gamma ) 

        
        self.tableDimensionality = tableDimensionality 

        #self.printCMACParams ( ) 

        self.Tile = Tiles.Tiles()
        return
Example #23
0
def start(imgName, num):
    tile_names = []
    tile_x = []

    font = cv2.FONT_HERSHEY_SIMPLEX

    path = os.path.dirname(os.path.abspath(__file__))
    train_tiles = Tiles.load_patterns(path + '/new/')
    image = cv2.imread(imgName)

    pre_proc = Tiles.preprocess_image(image)
    cv2.imwrite('pre_proc.jpg', pre_proc)
    cnts_sort, cnt_is_tile = Tiles.find_tiles(pre_proc)

    if len(cnts_sort) != 0:

        tiles = []
        k = 0

        for i in range(len(cnts_sort)):
            if (cnt_is_tile[i] == 1):
                tiles.append(Tiles.preprocess_tile(cnts_sort[i], image, i))

                tiles[k].best_match, tiles[k].diff = Tiles.match_tile(
                    tiles[k], train_tiles, i)
                tile_x.append(tiles[k].coord)
                #        print(tiles[k].best_match)
                tile_names.append(tiles[k].best_match)
                #        print('---------------')
                image = Tiles.draw_results(image, tiles[k])
                k = k + 1
            #if (len(tiles) != 0):
            #    temp_cnts = []
            #drawing contours. not necesary
            #for i in range(len(tiles)):
            #temp_cnts.append(tiles[i].contour)
            #cv2.drawContours(image,temp_cnts, -1, (27,150,194), 5)
        tile_names, tile_x = sort(tile_names, tile_x)
        #print(tile_names)
    cv2.imwrite('found.jpg', image)
    return tile_names
Example #24
0
       except with the aproval of the author. (contact on e-mail).
    Anyone can buy rights to use the source code in any commercial products by messaging the author;
"""



#Import section
import Tiles
from time import sleep
from random import choice
from random import randrange


#global variables:
        #Tiles:
player=Tiles.PlayerTile('8')
grass=Tiles.Tile(True)
grass.setGraphic('"')
wall=Tiles.Tile(False)
wall.setGraphic('[]')
water=Tiles.Tile(False)
water.setGraphic('~')
road=Tiles.Tile(True)
road.setGraphic('::')
start=Tiles.EventTile(True)
start.setGraphic('E')
end=Tiles.EventTile(False)
end.setGraphic('|=|')
tree=Tiles.Tile(False)
tree.setGraphic(chr(134))
grate=Tiles.Tile(False)
Example #25
0
def tiili(x,y,zoom,xo,yo,xd,yd):
    doabc()
    ny = datoja.kartta[datoja.nykyinen]
#    if ny == "viro":
#        return 'http://lbs.nutiteq.ee/topo/%d/%d/%d.jpg' % (zoom, x, y)
#    if ny == "cycle":
#        return 'http://b.tile.opencyclemap.org/cycle/%d/%d/%d.png' % (zoom, x, y)
    if ny == 'sailm': 
        y2=y
        if zoom==13:
            y2=2371-y+5820
        if zoom==14:
            y2=11639-y+4744
        return  'http://mapserver.sailmate.fi/fi/images/%d/%d/%d.png'%(zoom,x,y2)
    if ny == 'osm': 
        return  'http://%s.tile.openstreetmap.de/%d/%d/%d.png'%(datoja.abc,zoom,x,y)
    if ny == 'cycle': 
        return  'http://%s.tile.thunderforest.com/cycle/%d/%d/%d.png?apikey=26202fd82b624164a13dbe93fea33a04'%(datoja.abc,zoom,x,y)
    if ny == 'norja': 
        return  'http://opencache.statkart.no/gatekeeper/gk/gk.open_gmaps?layers=topo2&zoom=%d&x=%d&y=%d' % (zoom, x, y)
    if ny == 'google': 
        return 'https://mts1.google.com/vt/x=%d&y=%d&z=%d' % (x, y, zoom)
#        return 'http://mt.google.com/vt/v=w2.97&hl=en&x=%d&y=%d&z=%d' % (x, y, zoom)
    if ny == 'gsat':
        time.sleep(1)
        return 'http://khm.google.com/kh/v=113&x=%d&y=%d&z=%d' % (x, y, zoom)
 #   if ny == 'norsjo': 
 #       return 'http://opencache.statkart.no/gatekeeper/gk/gk.open_gmaps?layers=sjo_hovedkart2&zoom=%d&x=%d&y=%d' % (zoom, x, y)
    if ny == 'bing':
        import Tiles
        import random
        return 'http://a%d.ortho.tiles.virtualearth.net/tiles/a%s.jpeg?g=90' % (random.randint(0, 3),  Tiles.toMicrosoft(x,y,zoom))
    if ny == 'eniro':
        y2=math.pow(2,zoom)-y-1;
        return 'http://map.eniro.com/geowebcache/service/tms1.0.0/map/%d/%d/%d.png'%(zoom, x, y2)
    if ny == 'svesjo':
        y2=math.pow(2,zoom)-y-1;
        return 'http://map.eniro.com/geowebcache/service/tms1.0.0/nautical/%d/%d/%d.png'%(zoom, x, y2)
    if ny == 'kapsi':
        return 'http://tiles.kartat.kapsi.fi/peruskartta/%d/%d/%d.png'%(zoom, x, y)
#        if y % 2 == 0:
#           return 'https://tile1.kapsi.fi/mapcache/peruskartta_3067/%d/%d/%d.png'%(zoom, x, y)
#        else:
#           return 'https://tile2.kapsi.fi/mapcache/peruskartta_3067/%d/%d/%d.png'%(zoom, x, y)
    if ny == 'ilma':
        return 'http://tiles.kartat.kapsi.fi/ortokuva/%d/%d/%d.png'%(zoom, x, y)
Example #26
0
OPTION_PLAYGAME = '4'
OPTION_QUIT = '5'
""" PROGRAM INITIALIZATION """
# this file is uploaded from the Moby Words project; see http://icon.shef.ac.uk/Moby/mwords.html for details
wordlist = "scrabble.txt"

# build my dictionary
sDict = Dictionary.Dictionary(wordlist)
# debugging: print(sDict.words[1])
# debugging: print(sDict.find("zxzxz"))

# build my anagram cohort dictionary
aDict = Anagrams.Anagrams(sDict.words)

# build my bag of tiles
bag = Tiles.TileBag()
#debugging: print('z: ' + str(bag.valueof('z')))

# this track whether user has been making valid menu choices.
is_valid = False
""" MAIN METHOD FUNCTIONS"""

# user interface outline
# main menu
# - check if word is valid
# - look for anagrams
# - play game


# prints out the main menu
def show_menu():
Example #27
0
 def lonlat_xy_in_composite_osm_tile(self, lonlat):
   osm_tile = self.osm_tiles_by_xytile[Tiles.lonlat_tile(lonlat[0], lonlat[1], self.zoom)]
   #print "OSM tile is '%s' tile_delta %d %d" % ((osm_tile.name,)+ osm_tile.tile_delta)
   top_left_pixel_xy = vmul(OSM_TILE_SIZE, vadd(osm_tile.tile_delta, OSM_TILES_OFFSETS))
   #print "top_left_pixel_xy is %d %d" % top_left_pixel_xy
   return vadd(top_left_pixel_xy, osm_tile.lonlat_xy(lonlat[0], lonlat[1]))
Example #28
0
import Tiles
import Intcode

with open('input', 'r') as f:
    game = f.read().split(',')
game = [int(x) for x in game]

COMP = Intcode.Intcode()
COMP.memory = game
COMP.increase_memory(10)
COMP.run()

GAMEBOARD = Tiles.GameSurface()
for x, y, t in zip(COMP.output[0::3], COMP.output[1::3], COMP.output[2::3]):
    GAMEBOARD.set_color((x, y), t)

print(GAMEBOARD)
print(GAMEBOARD.tilecount[2])
Example #29
0
 def getZoomString(self, coordinate):
     return Tiles.toMicrosoft(int(coordinate.column), int(coordinate.row), int(coordinate.zoom))
Example #30
0
    def getTileMap(self):
        mapPath = Main.getPath(self.path)
        self.map = Img.open(mapPath)
        #Gets a list of all the pixel data in the img in a 1 dimensional list
        self.map = self.map.convert("RGB")
        pixels = list(self.map.getdata())
        #Sets the size so that the pixel list can be turned into a 2 dimensional array like a grid
        width, height = self.map.size
        pixels = [pixels[i * width:(i + 1) * width] for i in range(height)]
        self.pixels = pixels
        self.map.close()

        TileMap = []
        #columns then rows for 2D lists
        for y in range(0, len(self.pixels)):
            row = []
            for x in range(0, len(self.pixels[0])):
                #Tile format (Position, sprite, collision)
                #AnimTile format (gridPos, spritesheet,collision, animRow, NoOfFrames, timePeriod)
                #DamageTile format (gridPos, spritesheet, collision, animRow, NoOfFrames, timePeriod, damageValue)
                #TransportTile format (gridPos, sprite, collision, destination)
                #BLACK : Stone
                if self.pixels[y][x] == (0, 0, 0):
                    row.append(
                        Tiles.Tile((x, y), self.tileSheet.returnTile(2, 0),
                                   True))
                #RED : lava or generic damageTile
                elif self.pixels[y][x] == (255, 0, 0):
                    row.append(
                        Tiles.DangerTileAnim((x, y),
                                             self.animTileSheet,
                                             False,
                                             1,
                                             3,
                                             20,
                                             1,
                                             cost=100))
                #GREEN : grass
                elif self.pixels[y][x] == (0, 255, 0):
                    row.append(
                        Tiles.Tile((x, y), self.tileSheet.returnTile(0, 0),
                                   False))
                #BLUE : water
                elif self.pixels[y][x] == (0, 0, 255):
                    row.append(
                        Tiles.AnimTile((x, y), self.animTileSheet, True, 0, 3,
                                       10))
                #YELLOW : Flowers
                elif self.pixels[y][x] == (255, 255, 0):
                    row.append(
                        Tiles.Tile((x, y), self.tileSheet.returnTile(1, 0),
                                   False))
                #MAGENTA : Transport
                elif self.pixels[y][x] == (255, 0, 255):
                    path = Main.getPath("res/map1.png")
                    row.append(
                        Tiles.TransportTile((x, y),
                                            self.tileSheet.returnTile(3, 0),
                                            False, path))
                #CYAN : ?
                elif self.pixels[y][x] == (0, 255, 255):
                    path = Main.getPath("res/map2.png")
                    row.append(
                        Tiles.TransportTile((x, y),
                                            self.tileSheet.returnTile(3, 0),
                                            False, path))
                #WHITE : ?
                elif self.pixels[y][x] == (255, 255, 255):
                    pass
                else:
                    print("Colour, ", self.pixels[x][y],
                          "has no defining Tile")
            TileMap.append(row)
        return TileMap
Example #31
0
 def getZoomString(self, coordinate):
     return 'x=%d&y=%d&z=%d' % Tiles.toYahoo(int(coordinate.column), int(coordinate.row), int(coordinate.zoom))
Example #32
0
    hand2 = players[1].get_game_info().get_hand()
    hand3 = players[2].get_game_info().get_hand()
    hand4 = players[3].get_game_info().get_hand()
    hands = [hand1, hand2, hand3, hand4]

    controller = GameController(players, None, None, None)

    controller.initialization()

    if False:
        for player in players:
            hand = ""
            for item in player.get_game_info().get_hand().tiles:
                hand += item.get_value()

            Tiles.print_hand(Tiles.read_hand(hand))
            print

    if True:
        result = controller.get_score(1)

        print result


if True:
    result = ''

    player1 = PlayerInfo.Player()
    player2 = PlayerInfo.Player()
    player3 = PlayerInfo.Player()
    player4 = PlayerInfo.Player()
Example #33
0
 def calculate_lcd_tile_fn(self, dx, dy):
     return "%s-%s-%dx%d-%s.png" % (SERVER_TYPE, qra, LCD_TILE_WIDTH, LCD_TILE_HEIGHT, Tiles.rose(LCD_TILES_OFFSETS, dx, dy))
Example #34
0
 def calculate_lcd_bmp_fn(self, dx, dy):
     return "map%s.bmp" % (Tiles.rose(LCD_TILES_OFFSETS, dx, dy))