本文整理汇总了Python中Board.move方法的典型用法代码示例。如果您正苦于以下问题:Python Board.move方法的具体用法?Python Board.move怎么用?Python Board.move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Board
的用法示例。
在下文中一共展示了Board.move方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main_loop
# 需要导入模块: import Board [as 别名]
# 或者: from Board import move [as 别名]
def main_loop():
show_positions = [False] # using lists as lists are mutable
print("Is it can be tic-tac-toe tiem nao plz?")
# while we still want to play again...
while 1:
while 1:
x_is_human = True
go_first = input("Do you want to go first and play 'X'? [Y/N] ")
if go_first == "Y":
print("Okay. Playing as X.")
break
elif go_first == "N":
print("Okay. Playing as O.")
x_is_human = False
break
else:
print("Sorry, I didn't understand that input.")
game = Board()
# while the game hasn't yet been won...
turn = 1
while 1:
if x_is_human:
print("Turn " + str(turn) + ":")
if not game.game_over():
# ask player for their move
game.move(get_human_move(game, show_positions), "X")
if not game.game_over():
# ask ai player for their move
game.move(get_ai_move(game, x_is_human), "O")
else:
break # game has been won
else:
break # game has been won
else:
# playing as 'O', so the AI goes first...
if not game.game_over():
game.move(get_ai_move(game, x_is_human), "X")
if not game.game_over():
print("Turn " + str(turn) + ":")
if not game.game_over():
game.move(get_human_move(game, show_positions), "O")
else:
break
else:
break
turn += 1
# game has been won at this point
gameresult = evaluate(game)
if gameresult == -1:
print("Game result: win by O!")
elif gameresult == 0:
print("Game result: cat's game! >^.^< (Or tie, if you're boring.)")
else:
print("Game result: win by X!")
print(game)
while 1:
play_again = input("Play again? [Y/N]")
if play_again == "Y":
break
elif play_again == "N":
return
else:
print("I didn't understand that input.")