本文整理汇总了Python中ai.AI.replay方法的典型用法代码示例。如果您正苦于以下问题:Python AI.replay方法的具体用法?Python AI.replay怎么用?Python AI.replay使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ai.AI
的用法示例。
在下文中一共展示了AI.replay方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Game
# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import replay [as 别名]
class Game():
def __init__(self, game_size=4):
self.game_progress = 0
self.game_steps = list()
self.game_size = game_size
self.player = Player(game_size)
self.ai = AI(game_size)
def play(self):
while True:
self.game_progress += 1
print
print "Step %d" % self.game_progress
print
answer = self.player.play()
if answer['bulls'] == self.game_size:
print("Congratz! You won!")
exit()
else:
print("%db %dc" % (answer['bulls'], answer['cows']))
repeat_question = None
while self.game_progress > len(self.game_steps):
asked_number, answer = self.ai.play(repeat_question)
self.game_steps.append((asked_number, answer))
if answer['bulls'] == self.game_size:
print("Hehe, I won!")
exit()
if len(self.ai.possible_numbers) == 0:
print("You, liar!")
step = raw_input("On which step did you lie: ")
while not re.match(r'^\d+$', step) or not (1 <= int(step) <= len(self.game_steps)):
print("Invalid step.")
step = raw_input("On which step did you lie: ")
step = int(step)-1
repeat_question = self.game_steps[step][0]
self.game_steps = self.game_steps[:step]
self.ai.replay(self.game_steps)
else:
repeat_question = None