本文整理汇总了Python中convert.Convert.json_to_player_state方法的典型用法代码示例。如果您正苦于以下问题:Python Convert.json_to_player_state方法的具体用法?Python Convert.json_to_player_state怎么用?Python Convert.json_to_player_state使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类convert.Convert
的用法示例。
在下文中一共展示了Convert.json_to_player_state方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decode
# 需要导入模块: from convert import Convert [as 别名]
# 或者: from convert.Convert import json_to_player_state [as 别名]
def decode(self, msg):
"""
Decides which type of message the server has sent and verifies that the
timing of the message is valid and communicates to the player if the
message is valid.
:param msg: the message from the server to decode.
:return: the message to send to the Dealer, if any.
"""
if msg == "ok":
return
if "feeding" in possible_next_states[self.state] and len(msg) == 5:
player = Convert.json_to_player_state(msg[0:3])
opponents = Convert.json_to_listof_listof_species(msg[4])
feeding = self.player.next_feeding(player, msg[3], opponents)
self.state = "feeding"
return Convert.feeding_to_json(feeding)
(player, wh) = self.decode_start(msg)
if player and "start" in possible_next_states[self.state]:
print("Got start message")
self.player.start(player, wh)
self.state = "start"
return
decode_choose = self.decode_choose(msg)
if decode_choose and "choose" in possible_next_states[self.state]:
print("Choosing action")
choice = self.player.choose(decode_choose)
self.state = "choose"
return Convert.action_to_json(choice)
raise Exception
示例2: decode_start
# 需要导入模块: from convert import Convert [as 别名]
# 或者: from convert.Convert import json_to_player_state [as 别名]
def decode_start(self, msg):
"""
Attempts to decode the given msg into a tuple (player, watering_hole)
:param msg: The JSON message to decode.
:return: The tuple (PlayerState, Int) representing the player and the
food in the watering hole, or (False, False) if the conversion fails.
"""
try:
assert(isinstance(msg[0], int))
return (Convert.json_to_player_state(msg[1:]), msg[0])
except Exception:
return (False, False)