コード例 #1
0
    def load_tiles(self):
        tilenames = self.get_object(0xF004, rw=False)
        tileattrs = self.get_object(0xF002, rw=False)
        tilecompositions = self.get_object(0xF013, rw=False)
        tilefauxprops = self.get_object(0xF010, rw=False)
        tilesheets = self.objects(hints.GRAPHICS_TILESHEET, True, rw=False)
        if not tilenames: raise util.DelverLibraryIncomplete(util.DLI_MSG)
        self.tiles = []
        tile_Nothing = tile.Tile(0, tilenames[0], tileattrs[0],
                                 tilefauxprops[0], tilesheets[0].get_tile(0))

        for n, attr in enumerate(tileattrs):
            tileres_n = (n >> 4) & 0xFF
            if not (tileattrs[n] or tilesheets[tileres_n]):
                self.tiles.append(tile_Nothing)
                continue
            if n < 0x1000:
                self.tiles.append(
                    tile.Tile(n, tilenames[n], tileattrs[n], tilefauxprops[n],
                              tilesheets[tileres_n].get_tile(n & 0x00F)))
            elif n < 0x2000:
                self.tiles.append(
                    tile.CompoundTile(n, tilenames[n], tileattrs[n],
                                      tilefauxprops[n], self,
                                      tilecompositions[n - 0x1000]))
            else:
                assert 0, "Turns out there are more tiles than I thought."
コード例 #2
0
ファイル: test_table_unittest.py プロジェクト: Glib79/kik
    def test_is_on_correct_move(self):
        self.table.table = {}
        self.table.posible_moves = []

        t1 = tile.Tile(
            ['g', 'g', 'y', 'y', 'g', 'b', 'r', 'y', 1, 0, 0, 1, 0, 0, 1, 1])
        points, pfc = self.table.is_on_correct_move((0, 0), t1)
        self.assertEqual(points, 0)
        self.assertDictEqual(pfc, {})

        self.table.set_on_table((0, 0), t1)
        t2 = tile.Tile(
            ['r', 'b', 'g', 'y', 'r', 'r', 'r', 'r', 0, 0, 1, 1, 1, 1, 0, 0])
        points, pfc = self.table.is_on_correct_move((0, 1), t2)
        self.assertFalse(points)
        self.assertDictEqual(pfc, {})
        points, pfc = self.table.is_on_correct_move((0, -1), t2)
        self.assertEqual(points, 3)
        self.assertDictEqual(pfc, {})

        self.table.set_on_table((0, -1), t2)
        t3 = tile.Tile(
            ['r', 'b', 'y', 'g', 'r', 'r', 'r', 'r', 1, 0, 0, 1, 1, 1, 0, 0])
        points, pfc = self.table.is_on_correct_move((1, 0), t3)
        self.assertEqual(points, 4)
        self.assertDictEqual(pfc, {'g': 2})
コード例 #3
0
def main():
    import tile

    solver = AnagramSolver(min_letters = 2, max_letters = 20) #18 allows for 3x qu
    free_tiles = [tile.Tile(letters = alpha) for alpha in 'techerasdfasdf']
    t = tile.Tile(letters = 't')
    a = tile.Tile(letters = 'a')
    fixed_tiles = [None,None,a]
    wrong_pos_tiles = [[],[t]]
    best = solver.best_words(free_tiles, fixed_tiles, wrong_pos_tiles,
                             min_tiles = 7, max_tiles = 7)
    for word in best:
        for tile_ in word:
            print(tile_.letters, end='')
        print('')

    go = True
    while go:
        user_input = input('Letters or ''Q'' (''Qu'' already included): ')
        if user_input.upper() == 'Q':
            go = False
        elif not user_input.isalpha():
            continue
        else:
            tiles = [tile.Tile(letters = letter) for letter in user_input]
            tiles.append(tile.Tile(letters = 'qu'))
            best = solver.best_words(tiles, list_limit = 10)
            for word in best:
                for tile_ in word:
                    print(tile_.letters, end = '')
                print('')
コード例 #4
0
 def parse_map(self):
     for i in range(SIZE):
         for j in range(SIZE):
             if self.tiles[i][j] == 'X':
                 self.cases[i][j] = tile.Tile("grey", x=i*TILE_SIZE , y=j*TILE_SIZE, batch=self.batch)
             elif self.current_level[i][j] == "f":
                 self.cases[i][j] = tile.Tile("stair",x=i*TILE_SIZE ,y=j*TILE_SIZE, batch=self.batch)
             elif self.tiles[i][j] == 0:
                 self.cases[i][j] = tile.Tile("blue",x=i*TILE_SIZE ,y=j*TILE_SIZE, batch=self.batch)
コード例 #5
0
    def test_get_hand(self):
        t1 = tile.Tile(
            ['r', 'g', 'g', 'g', 'g', 'b', 'r', 'y', 1, 1, 0, 0, 0, 0, 1, 1])
        t2 = tile.Tile(
            ['r', 'g', 'g', 'g', 'g', 'b', 'r', 'y', 1, 1, 0, 0, 0, 0, 1, 1])
        self.hand.add_tile(t1)
        self.hand.add_tile(t2)

        self.assertListEqual(self.hand.get_hand(), self.hand.tiles)
コード例 #6
0
    def test_get_chosen(self):
        t1 = tile.Tile(
            ['r', 'g', 'g', 'g', 'g', 'b', 'r', 'y', 1, 1, 0, 0, 0, 0, 1, 1])
        t2 = tile.Tile(
            ['r', 'g', 'g', 'g', 'g', 'b', 'r', 'y', 1, 1, 0, 0, 0, 0, 1, 1])
        self.hand.add_tile(t1)
        self.hand.add_tile(t2)

        self.assertIs(self.hand.get_chosen(), t1)
        self.hand.set_chosen(1)
        self.assertIs(self.hand.get_chosen(), t2)
コード例 #7
0
    def test_len(self):
        # new created hand should have len = 0
        self.assertEqual(len(self.hand), 0)

        # add two hand 2 tiles and check its len
        t1 = tile.Tile(
            ['r', 'g', 'g', 'g', 'g', 'b', 'r', 'y', 1, 1, 0, 0, 0, 0, 1, 1])
        t2 = tile.Tile(
            ['r', 'b', 'b', 'b', 'g', 'b', 'y', 'r', 1, 1, 0, 0, 1, 1, 0, 0])
        self.hand.add_tile(t1)
        self.hand.add_tile(t2)
        self.assertEqual(len(self.hand), 2)
コード例 #8
0
 def __init__(self, spriteFull, label, size, maxUsers, enabled, startRoom):
     """ Class constructor.
 spriteFull: sprite used to paint the room floor on screen.
 label: room label.
 size: room size.
 maxUsers: maximum users number on this room.
 enabled: sets this room as enabled or disabled for common users.
 startRoom: sets this room as a start room or not.
 """
     ggmodel.GGModel.__init__(self)
     self.spriteFull = spriteFull
     self.size = size
     self.label = label
     self.maxUsers = maxUsers
     self.__tiles = []
     for i in range(0, self.size[0]):
         line = []
         for j in range(0, self.size[1]):
             image = os.path.join(
                 GG.utils.TILE,
                 self.spriteFull[random.randint(0,
                                                len(self.spriteFull) - 1)])
             line.append(tile.Tile([i, j], image, self))
         self.__tiles.append(line)
     self.__items = []
     self.__specialTiles = []
     self.__population = 0
     self.__enabled = enabled
     self.__startRoom = startRoom
     self.save("room")
コード例 #9
0
ファイル: test.py プロジェクト: DSSzymanski/minesweeper
 def test_update(self):
     test_tile = t.Tile(0, 0, 30)
     self.assertEqual(test_tile.state_flag, 0)
     test_tile.update()
     self.assertEqual(test_tile.state_flag, 1)
     test_tile.update()
     self.assertEqual(test_tile.state_flag, 1)
コード例 #10
0
    def move(self):
        if self.walkTime >= globals.TIME_WALK:
            self.walkTime = 0
            if type(globals.MAP[self.y + self.dirY][self.x +
                                                    self.dirX]) is tile.Trap:
                self.death()
            else:
                if type(globals.MAP[self.y + self.dirY][self.x +
                                                        self.dirX]) is Mob:
                    globals.MAP[self.y + self.dirY][self.x + self.dirX].death()
                globals.MAP[self.y][self.x] = tile.Tile(self.x, self.y)
                self.x = self.x + self.dirX
                self.y = self.y + self.dirY
                globals.MAP[self.y][self.x] = self

            self.endCheck = globals.isWall(self.x + self.dirX,
                                           self.y + self.dirY)
            self.walking = not self.endCheck
        else:
            self.walkTime += globals.LT
            self.walkRect.x = globals.calcX(
                self.x) - globals.marginLeft + self.dirX * (
                    self.walkTime / globals.TIME_WALK * globals.OBJECT_WIDTH)
            self.walkRect.y = globals.calcY(
                self.y) - globals.marginTop + self.dirY * (
                    self.walkTime / globals.TIME_WALK * globals.OBJECT_WIDTH)
コード例 #11
0
ファイル: player.py プロジェクト: elkofy/gamejam
    def checkState(self):
        if type(globals.MAP[self.y][self.x]) is tile.Fruits:
            self.energie += 20
            self.eat_sound.play()
            globals.MAP[self.y][self.x] = tile.Tile(self.x, self.y)
        if type(globals.MAP[self.y][self.x]) is tile.Bed:
            if globals.LOGS:
                print(globals.Jour)
            self.zz_sound.play()
            if not globals.Jour:
                if globals.NUM_LVL < globals.MAX_LEVEL:
                    globals.Jour = True
                    globals.LVL_CHANGED = True
                    globals.NUM_LVL += 1
                else:
                    gameover.end_screen()
            else:
                globals.Jour = False
                globals.LVL_CHANGED = True

            self.energie = MAX_ENERGY

        if type(globals.MAP[self.y][self.x]) is tile.Trap:
            if globals.MAP[self.y][self.x].state:
                self.death()

        if globals.Jour and self.energie <= 0:
            self.death()
コード例 #12
0
ファイル: tester.py プロジェクト: grokcore/dev.lexycross
def testRun():
    firstTurn = True

    theBag = bag.Bag()
    theBoard = board.Board(15, (7, 7))

    boardY = 7
    for boardX in range(4, 11):
        testTile = tile.Tile("A", 1)
        theBoard.squares[boardY][boardX] = (
            testTile, theBoard.squares[boardX][boardY][1])
        theBoard.squares[boardY][boardX][0].locked = True

    printBoard(theBoard)

    players = []
    h = heuristic.notEndGameHeuristic(heuristic.tileQuantileHeuristic(
        0.1, 1.0))

    players.append(ai.AI(theBoard, theBag, theHeuristic=h, theDifficulty=10.0))

    active = 0
    print "OK"
    #calculate the move
    rack = "SERPENT"
    max = 9
    for x in range(0, 1000000):
        players[active].tray = setTray(rack)
        playedMove = players[active].executeTurn(firstTurn)
        #play that move.. if it played
        success = players[active].play(firstTurn)
        #printBoard(theBoard)
        firstTurn = False
コード例 #13
0
ファイル: LevelLoader.py プロジェクト: LexCoolplay/Yandex
def load_level(name):
    mapdata = pytmx.load_pygame(os.path.join('data/Maps', name + '.tmx'))
    print(mapdata.layers)
    tiles = pygame.sprite.Group()
    obstacles = pygame.sprite.Group()
    for y in range(mapdata.height):
        for x in range(mapdata.width):
            image = mapdata.get_tile_image(x, y, 0)
            if image:
                image.set_alpha(None)
                block = tile.Tile(image)
                block.set_position((x * 32, y * 32))
                tiles.add(block)
            # print(image, end=' ')
        #print()

    for y in range(mapdata.height):
        for x in range(mapdata.width):
            image = mapdata.get_tile_image(x, y, 1)
            if image:
                image.set_alpha(None)
                block = tile.Obstacle(image)
                block.set_position((x * 32, y * 32))
                obstacles.add(block)
    for i in mapdata.objects:
        finish = i
    return mapdata, tiles, obstacles, finish
コード例 #14
0
def triangle(width):
	r"""
	Generates a triangluar puzzle of a given width.
	
	Returns a dictionary {(x,y):Tile,...} for a set of tiles arranged like so:
	
	        /\
	       /02\
	      /____\
	     /\    /\
	    /01\11/21\
	   /____\/____\
	  /\    /\    /\
	 /00\10/20\30/40\
	/____\/____\/____\
	
	`-------v--------'
	    width = 5
	"""
	assert width%2 == 1, \
		"Must be an odd width."
	
	tiles = {}
	
	# Generate a pyramid of triangular tiles
	for y in range(width):
		for x in range(width - 2*y):
			tiles[(x,y)] = tile.Tile()
	
	return tiles
コード例 #15
0
 def load(self, dict):
     ggmodel.GGModel.load(self, dict)
     self.spriteFull = dict["spriteFull"]
     self.label = dict["label"]
     self.size = dict["size"]
     self.maxUsers = dict["maxUsers"]
     self.__enabled = dict["enabled"]
     self.__startRoom = dict["startRoom"]
     self.__specialTiles = dict["specialTiles"]
     self.__population = 0
     self.__tiles = []
     self.__items = []
     for i in range(0, self.size[0]):
         line = []
         for j in range(0, self.size[1]):
             image = os.path.join(
                 GG.utils.TILE,
                 self.spriteFull[random.randint(0,
                                                len(self.spriteFull) - 1)])
             line.append(tile.Tile([i, j], image, self))
         self.__tiles.append(line)
     for dataTile in dict["tiles"]:
         self.__tiles[dataTile["position"][0]][
             dataTile["position"][1]].setImage(dataTile["spriteName"], True)
     for itemDict in dict["items"]:
         item = ggmodel.GGModel.read(itemDict["id"], "room", itemDict)
         pos = itemDict["position"]
         self.__tiles[pos[0]][pos[1]].stackItem(item)
         item.setTile(self.__tiles[pos[0]][pos[1]])
         item.setStartPosition(item.getTile().position)
         self.__items.append(item)
         item.setRoom(self)
コード例 #16
0
ファイル: board.py プロジェクト: Dylan-Dotti/PythonSnakeGame
    def __init__(self,
                 rows=10,
                 cols=10,
                 snake_death_callback=None,
                 *args,
                 **kwargs):
        super(Board, self).__init__(*args, **kwargs)
        self.snake_death_callback = snake_death_callback
        self.num_rows = rows
        self.num_columns = cols
        self._grid = [list() for i in range(self.num_rows)]

        for r in range(self.num_rows):
            for c in range(self.num_columns):
                new_tile = tile.Tile(r, c, self)
                tk.Grid.rowconfigure(self, r, weight=1)
                tk.Grid.columnconfigure(self, c, weight=1)
                new_tile.grid(row=r,
                              column=c,
                              padx=0.5,
                              pady=0.5,
                              sticky=tk.NSEW)
                self._grid[r].append(new_tile)

        self.food_positions = {}
        self.player_snake = None
コード例 #17
0
ファイル: board.py プロジェクト: AnubisAbydos/Final-Project
 def __init__(self):
     # row(left A-J) by column(top 1-10)
     self.boardGrid = [[0 for i in range(10)] for j in range(10)]
     # load boardGrid
     for i in range(10):
         for j in range(10):
             self.boardGrid[i][j] = tile.Tile()
     # Set Special Rules Tiles
     # Red (Top)
     self.boardGrid[0][3].setBase(TeamColor.RED)
     self.boardGrid[0][4].setBase(TeamColor.RED)
     self.boardGrid[0][5].setBase(TeamColor.RED)
     self.boardGrid[0][6].setBase(TeamColor.RED)
     # Blue (Bottom)
     self.boardGrid[9][3].setBase(TeamColor.BLUE)
     self.boardGrid[9][4].setBase(TeamColor.BLUE)
     self.boardGrid[9][5].setBase(TeamColor.BLUE)
     self.boardGrid[9][6].setBase(TeamColor.BLUE)
     # Yellow (Right)
     self.boardGrid[3][9].setBase(TeamColor.YELLOW)
     self.boardGrid[4][9].setBase(TeamColor.YELLOW)
     self.boardGrid[5][9].setBase(TeamColor.YELLOW)
     self.boardGrid[6][9].setBase(TeamColor.YELLOW)
     # Green (Left)
     self.boardGrid[3][0].setBase(TeamColor.GREEN)
     self.boardGrid[4][0].setBase(TeamColor.GREEN)
     self.boardGrid[5][0].setBase(TeamColor.GREEN)
     self.boardGrid[6][0].setBase(TeamColor.GREEN)
     # Victory Points (Center)
     self.boardGrid[4][4].isVictoryPoint = True
     self.boardGrid[5][5].isVictoryPoint = True
     # Research Points (Center)
     self.boardGrid[4][5].isResearch = True
     self.boardGrid[5][4].isResearch = True
コード例 #18
0
ファイル: gameboard.py プロジェクト: bsaliba1/cs-coursework
 def createBoard(self):
     """
     - create a 2D array of tile objects (num_rows x num_cols) 
     """
     for row in range(self.num_rows):
         self.board.append([]) # add new row
         for col in range(self.num_cols):
             self.board[row].append(tile.Tile(row, col)) # add tile objects to each row
コード例 #19
0
ファイル: xboard.py プロジェクト: meganmelau/Tsuro
def get_exit_port(index, rotate_degree, entry_port):
    tile_config = convert_representation(get_representation(index))
    target_tile = tile.Tile(tile_config)
    rotation_time = rotate_degree // 90
    for i in range(rotation_time):
        target_tile = target_tile.rotate_90()
    exit_port = target_tile.get_path(convert_letter_to_int(entry_port))
    return convert_int_to_letter(exit_port)
コード例 #20
0
ファイル: test.py プロジェクト: DevDevDevDevDev/Mahjong
def str2tile_set(s):
    suits = s.split(' ')
    tiles = set()

    for i in xrange(3):
        if suits[i] != '-':
            for s in suits[i]:
                tiles.add(tile.Tile(i, int(s) - 1))

    if suits[3] != '-':
        for s in suits[3]:
            tiles.add(tile.Tile(tile.WIND_SUIT, int(s) - 1))

    if suits[4] != '-':
        for s in suits[4]:
            tiles.add(tile.Tile(tile.DRAGON_SUIT, int(s) - 1))
    return tiles
コード例 #21
0
ファイル: player.py プロジェクト: dourches-m/Zappy
    def __init__(self, sock):
        with open(os.path.dirname(__file__) + '/adjectives') as f1:
            with open(os.path.dirname(__file__) + '/animals') as f2:
                adjs = f1.readlines()
                anims = f2.readlines()
                self.name = str(random.choice(adjs))[:-1] + ' ' + \
                str(random.choice(adjs))[:-1] + ' ' + \
                str(random.choice(anims))[:-1]
        self.level = 1
        self.cycles = 0
        self.group = [self.name]
        self.tmp_group = []
        self.state = 'FirstIncant'
        self.broad_queue = deque([])
        self.inventory = {'linemate': 0,
                          'deraumere': 0,
                          'sibur': 0,
                          'mendiane': 0,
                          'phiras': 0,
                          'thystame': 0,
                          'food': 10}
        random.seed(time.time())
        self.fiability = 75
        self.get_food = False
        self.look_counter = 0
        self.sent_orders = deque([])
        self.no_pop_commands = {'dead' : self.callback_die, 'message': self.callback_broadcast,
                                'eject:' : self.callback_eject, 'Current' : self.callback_level_up,
                                'Elevation' : self.callback_incant}

        self.state_dict = {'FirstIncant' : self.get_lv2,
                           'Hungry' : self.search_food,
                           'LFG' : self.search_group,
                           'PrepLead': self.prep_lead,
                           'PrepWork': self.prep_work,
                           'Leading' : self.lead_search,
                           'Gathering' : self.work_search,
                           'Incanting' : self.incanting,
                           'GoIncanting' : self.go_incant,
                           'end incant' : self.end_incant
                           }

        self.answer_dict = {'Inventory' : self.inventory_answer, 'Look' : self.look_answer,
                            'Incantation' : self.incant_answer,
                            'EndIncant' : self.end_incant_answer,
                            'Forward': self.movement_answer, 'Left': self.movement_answer, 'Right': self.movement_answer,
                            'Take' : self.take_answer, 'Set' : self.set_answer,
                            'Connect_nbr' : self.connect_nbr_answer, 'Fork' : self.fork_answer,
                            'Broadcast': self.do_nothing,
                            'Eject' : self.do_nothing}
        self.sock = sock
        self.sock.start_connection()
        self.team, self.xMax, self.yMax = sock.team, int(sock.maxX), int(sock.maxY)
        self.rem_connects = int(sock.rem_connects)
        self.pos = pos.Position(0, 0, self.xMax, self.yMax, 'NORTH')
        self.pos._init_dir_dict()
        self.map = [[tile.Tile(x, y) for x in range(self.xMax)] for y in range(self.yMax)]
        self.map[0][0].inventory['player'] += 1
コード例 #22
0
 def set_n(self, N):
     self.N = N
     cells = []
     for i in range(self.N):
         for j in range(self.N):
             if i % 2 == 0:
                 if j % 2 == 0:
                     cells.append(tile.Tile(queen=False, color='white'))
                 else:
                     cells.append(tile.Tile(queen=False, color='black'))
             else:
                 if j % 2 == 0:
                     cells.append(tile.Tile(queen=False, color='black'))
                 else:
                     cells.append(tile.Tile(queen=False, color='white'))
     self.grid.cells = cells
     self.pad.width = self.N * 6
     self.height = self.N * 3
コード例 #23
0
 def __init__(self):
     self.map = []
     self.cities = []
     for x in range(0, settings.worldx):
         r = []
         for y in range(0, settings.worldy):
             q = tile.Tile(x, y)
             r.append(q)
         self.map.append(r)
コード例 #24
0
 def create_tiles(self, array, space):
     tiles = []
     height = len(array) - 1
     for y, row in enumerate(array):
         for x, val in enumerate(row):
             if val == 1:
                 tiles.append(tile.Tile(x + self.offset, height - y, space))
     length = len(array[0])
     return tiles, length
コード例 #25
0
ファイル: field.py プロジェクト: malek-d/minesweeper
 def __init__(self, columns, rows, max_bombs):
     self.columns = columns
     self.rows = rows
     self.max_bombs = max_bombs
     self.field = [[tile.Tile() for y in range(self.columns)]
                   for x in range(self.rows)]
     self.gameOver = False
     self.addMines()
     self.addNumbers()
コード例 #26
0
    def __init__(self, width, height, initially_solid):
        self.tiles = list(())
        self.width = width
        self.height = height

        for y in range(height):
            for x in range(width):
                self.tiles.append(
                    tile.Tile(x, y, y * width + x, initially_solid))
コード例 #27
0
    def test_rem_chosen_tile_1(self):
        # 1 tile on hand
        t1 = tile.Tile(
            ['r', 'g', 'g', 'g', 'g', 'b', 'r', 'y', 1, 1, 0, 0, 0, 0, 1, 1])
        self.hand.add_tile(t1)

        self.hand.rem_chosen_tile()
        self.assertEqual(len(self.hand), 0)
        self.assertTrue(self.hand.end)
コード例 #28
0
    def Create_map(self,mapSize,window,tileSize):
        out=[]
        for i in range(mapSize):
            out.append([])
        for i,x in zip(out,range(mapSize)):
            for j in range(mapSize):
                i.append(tile.Tile(window,self._color,(j*tileSize,x*tileSize),(tileSize,tileSize),x,j))

        return out
コード例 #29
0
ファイル: board.py プロジェクト: cheukyin699/py-scrabble
    def place(self, pos, letter):
        '''
        Converts letter to be placed into tile.Tile type.
        '''
        x, y = pos
        if self.tiles[x][y] is not None:
            raise Exception("error: tile exists")

        self.tiles[x][y] = tile.Tile(letter)
コード例 #30
0
ファイル: xboard.py プロジェクト: meganmelau/Tsuro
def generate_tile_dictionary():
    tile_dict = {}
    tiles_list = tiles.splitlines()
    for i in range(len(tiles_list)):
        tile_letter_representation = json.loads(tiles_list[i])[1]
        tile_int_representation = convert_representation(
            tile_letter_representation)
        current_tile = tile.Tile(tile_int_representation)
        tile_dict[i] = current_tile
    return tile_dict