本文整理匯總了Python中species.Species.convertSpecies方法的典型用法代碼示例。如果您正苦於以下問題:Python Species.convertSpecies方法的具體用法?Python Species.convertSpecies怎麽用?Python Species.convertSpecies使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類species.Species
的用法示例。
在下文中一共展示了Species.convertSpecies方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: parse_choice
# 需要導入模塊: from species import Species [as 別名]
# 或者: from species.Species import convertSpecies [as 別名]
def parse_choice(choice):
"""
Parse a choice into a [PlayerState, listOf(Species), listOf(Species]
:param choice: json list representing [playerstate, listof species, listof species]
:return: [PlayerState, listOf(Species), listOf(Species)]
"""
ps = PlayerState.convertPlayerState(choice[0])
prev_species = [Species.convertSpecies(species) for species in [prev for prev in choice[1]]]
later_species = [Species.convertSpecies(species) for species in [late for late in choice[2]]]
return [ps, prev_species, later_species]
示例2: parse_cj_dj
# 需要導入模塊: from species import Species [as 別名]
# 或者: from species.Species import convertSpecies [as 別名]
def parse_cj_dj(json_cj_dj):
"""
Parse a json cj_dj into a [listOf(listOf(Species)), listOf(listOf(Species))]
:param json_cj_dj: json list representing [listof species, listof species]
- First list of species is each specieslist of all players acting before this player
- Second list of species is each specieslist of all players who's turns come after this player
:return: (listOf(Species), listOf(Species))
"""
prev_species, later_species = [], []
for prev in json_cj_dj[0]:
prev_species.append([Species.convertSpecies(species) for species in prev])
for later in json_cj_dj[1]:
later_species.append([Species.convertSpecies(species) for species in later])
return prev_species, later_species
示例3: from_json_state
# 需要導入模塊: from species import Species [as 別名]
# 或者: from species.Species import convertSpecies [as 別名]
def from_json_state(json_state):
"""
Takes in a json 'state' of a Player, converting it into a new PlayerState object
:param json_state: JSON List - [Natural, [Species+, ..., Species+], Cards]
:return: PlayerState - the new PlayerState object created from the json representation
"""
food_bag = json_state[0]
species_list = [Species.convertSpecies(species) for species in json_state[1]]
trait_cards = [TraitCard.from_json(trait) for trait in json_state[2]]
return PlayerState(bag=food_bag, speciesList=species_list, trait_cards=trait_cards)
示例4: from_json_gamestate
# 需要導入模塊: from species import Species [as 別名]
# 或者: from species.Species import convertSpecies [as 別名]
def from_json_gamestate(json_state):
"""
Takes in a json game state, converting it into a list that contains the PlayerState, WateringHole, and other species
:param json_state: JSON List - [Natural, [Species+, ..., Species+], Cards, Natural+, LOB]
:return: [PlayerState, Nat, List of Species]
"""
ps = PlayerState.from_json_state(json_state[:3])
watering_hole = json_state[3]
all_species = []
for species_list in json_state[4]:
all_species.append([Species.convertSpecies(species) for species in species_list])
return [ps, watering_hole, all_species]
示例5: convertPlayerState
# 需要導入模塊: from species import Species [as 別名]
# 或者: from species.Species import convertSpecies [as 別名]
def convertPlayerState(state):
"""
Creates a PlayerState from from the given JSON representation
:param state: JSON list - represents the playerState
:return: PlayerState - with attributes contained in 'state'
"""
playerTraitCards = []
if state[0][0] == ID_LABEL and state[1][0] == SPECIES_LABEL and state[2][0] == BAG_LABEL:
id = state[0][1]
speciesList = [Species.convertSpecies(species) for species in state[1][1]]
bag = state[2][1]
if len(state) == 4 and state[3][0] == CARDS_LABEL:
playerTraitCards = [TraitCard.from_json(card) for card in state[3][1]]
if id < 1 or bag < 0:
raise Exception("Bad JSON PlayerState Data")
return PlayerState(id, bag, speciesList, playerTraitCards)
else:
raise Exception("Bad JSON PlayerState input")