示例#1
0
def setup_simulation(players,
                     game_mode,
                     movement_rules,
                     exploration_rules,
                     mythical_city=True):
    '''The final part of game setup for Cartolan, this chooses a random play order for the players involved
    
    Arguments:
    List of Cartolan.Player for the Players involved in the game
    Cartolan.Game for the game that these tiles are being laid for
    String giving the movement rules variant that will apply for this game
    String giving the exploration rules variant that will apply for this game
    '''
    game = setup_adventurers(players, game_mode, movement_rules,
                             exploration_rules, mythical_city)

    game.setup_tile_pile("water")
    if game_mode in [GameRegular, GameAdvanced]:
        game.setup_tile_pile("land")
        if mythical_city:
            game.tile_piles["land"].tiles.append(
                game.CITY_TYPE(game, WindDirection(True, True),
                               TileEdges(False, False, False, False), False,
                               True))

    #turn order has been handled by the parent setup
#     game.players = random.shuffle(game.players)
    print("Randomly chose " + str(players[0].colour) + " player to start")
    return game
示例#2
0
 def __init__(self,
              game,
              tile_back="water",
              wind_direction=WindDirection(True, True),
              tile_edges=TileEdges(True, True, True, True)):
     super().__init__(game, wind_direction, tile_edges, True, True)
示例#3
0
 def __init__(self,
              game,
              tile_back="land",
              wind_direction=WindDirection(True, True),
              tile_edges=TileEdges(False, False, False, False)):
     return super().__init__(game, wind_direction, tile_edges, False, False)
示例#4
0
    def setup_tile_pile(self, tile_back):
        '''Part of game setup for Cartolan, this creates a tile of shuffled water-backed tiles ready for play
        
        Arguments:
        tile_back a string designating the type of tile and so its distribution of edge combinations
        '''
        total_distribution = []
        special_distributions = {}  # for wonder/disaster
        for tile_type in self.TILE_TYPE_COLS:
            special_distributions[tile_type] = []

        tile_filename = self.TILE_PREFIX + tile_back + self.TILE_EXT
        with open(tile_filename) as csvfile:
            readCSV = csv.reader(csvfile)
            for row in readCSV:
                total_distribution.append(int(row[0]))
                for tile_type in self.TILE_TYPE_COLS:
                    special_distributions[tile_type].append(
                        int(row[self.TILE_TYPE_COLS[tile_type]]))

        #construct the tile deck
        row_count = 0
        tiles = []
        for uc_water in [True, False]:
            for ua_water in [True, False]:
                for dc_water in [True, False]:
                    for da_water in [True, False]:
                        #for this combination of tile edges create tiles of each special type and plain ones
                        special_tile_num = 0
                        for tile_type in special_distributions:
                            for tile_num in range(
                                    0,
                                    int(special_distributions[tile_type]
                                        [row_count])):
                                wind_direction = WindDirection(north=True,
                                                               east=True)
                                tile_edges = TileEdges(uc_water, ua_water,
                                                       dc_water, da_water)
                                tiles.append(self.TILE_TYPES[tile_type](
                                    self, tile_back, wind_direction,
                                    tile_edges))
                                special_tile_num += 1
                        for tile_num in range(
                                0,
                                int(total_distribution[row_count]) -
                                special_tile_num):
                            wind_direction = WindDirection(north=True,
                                                           east=True)
                            tile_edges = TileEdges(uc_water, ua_water,
                                                   dc_water, da_water)
                            tiles.append(
                                Tile(self, tile_back, wind_direction,
                                     tile_edges, False))
                        row_count += 1

        #draw a suitable number of tiles from the deck for a pile

    #     num_tiles = len(players)*game.WATER_TILES_PER_PLAYER
        num_tiles = self.NUM_TILES[tile_back]
        tile_pile = self.tile_piles[tile_back]
        for tile in random.sample(tiles, num_tiles):
            tile_pile.add_tile(tile)

        tile_pile.shuffle_tiles()

        print("Built a " + tile_back + " tile pile with " +
              str(len(self.tile_piles[tile_back].tiles)) +
              " tiles, and shuffled it")