本文整理汇总了Python中convert.Convert.feeding_to_json方法的典型用法代码示例。如果您正苦于以下问题:Python Convert.feeding_to_json方法的具体用法?Python Convert.feeding_to_json怎么用?Python Convert.feeding_to_json使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类convert.Convert
的用法示例。
在下文中一共展示了Convert.feeding_to_json方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: decode
# 需要导入模块: from convert import Convert [as 别名]
# 或者: from convert.Convert import feeding_to_json [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: test_feeding_to_json
# 需要导入模块: from convert import Convert [as 别名]
# 或者: from convert.Convert import feeding_to_json [as 别名]
def test_feeding_to_json(self):
self.assertEqual(Convert.feeding_to_json(self.feed_1), self.json_feed_1)
self.assertEqual(Convert.feeding_to_json(self.feed_2), self.json_feed_2)
self.assertEqual(Convert.feeding_to_json(self.feed_3), self.json_feed_3)
self.assertEqual(Convert.feeding_to_json(self.feed_4), self.json_feed_4)