当前位置: 首页>>代码示例>>Python>>正文


Python Board.move方法代码示例

本文整理汇总了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.")
开发者ID:segfaultvicta,项目名称:Tic-Tac-Toe,代码行数:68,代码来源:Tic-Tac-Toe.py


注:本文中的Board.move方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。