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


Python Board.find_next_move方法代码示例

本文整理汇总了Python中board.Board.find_next_move方法的典型用法代码示例。如果您正苦于以下问题:Python Board.find_next_move方法的具体用法?Python Board.find_next_move怎么用?Python Board.find_next_move使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在board.Board的用法示例。


在下文中一共展示了Board.find_next_move方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_gameplay_first_player_winning_setup

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import find_next_move [as 别名]
    def test_gameplay_first_player_winning_setup(self):
        """
        Test that the first player will have a winning setup if the middle square is left unplayed.
        """
        board = Board()
        board.add_mark(0, "O")
        board.add_mark(1, "X")
        board.add_mark(6, "O")
        board.add_mark(board.find_next_move("X"), "X")
        self.assertIn(board.find_next_move("O"), [4, 8])  # 4 and 8 guarantee the win for O

        board.add_mark(4, "O")
        board.add_mark(board.find_next_move("X"), "X")
        board.add_mark(board.find_next_move("O"), "O")
        self.assertEquals(board.get_winner(), "O")  # Test that O actually wins the game
开发者ID:achernet,项目名称:Tic-Tac-Toe,代码行数:17,代码来源:tests.py

示例2: test_gameplay_identical_opposite_mark

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import find_next_move [as 别名]
    def test_gameplay_identical_opposite_mark(self):
        """
        Test that the gameplay followed in the above test is identical when the symbols are reversed
        """
        board = Board()
        board.add_mark(0, "X")
        board.add_mark(1, "O")
        board.add_mark(6, "X")
        board.add_mark(board.find_next_move("O"), "O")
        self.assertIn(board.find_next_move("X"), [4, 8])  # 4 and 8 guarantee the win for X

        board.add_mark(4, "X")
        board.add_mark(board.find_next_move("O"), "O")
        board.add_mark(board.find_next_move("X"), "X")
        self.assertEquals(board.get_winner(), "X")  # Test that X actually wins the game
开发者ID:achernet,项目名称:Tic-Tac-Toe,代码行数:17,代码来源:tests.py

示例3: test_gameplay_second_player

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import find_next_move [as 别名]
 def test_gameplay_second_player(self):
     """
     Test that the AI picks the middle square as quickly as possible when playing second
     """
     board = Board()
     board.add_mark(0, "O")
     self.assertEquals(4, board.find_next_move("X"))
开发者ID:achernet,项目名称:Tic-Tac-Toe,代码行数:9,代码来源:tests.py

示例4: test_gameplay_first_player_first_move

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import find_next_move [as 别名]
 def test_gameplay_first_player_first_move(self):
     """
     Test initial gameplay logic and/or AI when going first
     """
     board = Board()
     first_move = board.find_next_move('X')
     self.assertIn(first_move, board.CORNERS)
开发者ID:achernet,项目名称:Tic-Tac-Toe,代码行数:9,代码来源:tests.py

示例5: main

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import find_next_move [as 别名]
def main():
    """
    Run the main program!
    """
    game_board = Board()
    while True:
        print "Classic Console Tic-Tac-Toe"
        print ""
        print "Make a selection:"
        print ""
        print "n) new game"
        print "p) print the board"
        print "q) quit"
        print "0-8) make the given move"
        print ""
        print "Enter your selection: "
        selection = raw_input()
        if selection in ("q", "Q"):
            break
        elif selection in ("p", "P"):
            game_board.print_board()
        elif selection in ("n", "N"):
            game_board = Board()
            if not is_user_first():
                game_board.add_mark(game_board.find_next_move("X"), "X")
        elif selection in ('0', '1', '2', '3', '4', '5', '6', '7', '8'):
            position = int(selection)
            take_turn(game_board, position, "O")
开发者ID:achernet,项目名称:Tic-Tac-Toe,代码行数:30,代码来源:ttt.py

示例6: test_gameplay_winning_blocking

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import find_next_move [as 别名]
 def test_gameplay_winning_blocking(self):
     """
     Test that if a player can win in one move, it becomes both the player and opponent's next move
     """
     board = Board()
     board.add_mark(0, "O")
     board.add_mark(3, "O")
     board.add_mark(1, "X")
     self.assertEquals(6, board.find_next_move("O"))  # Test winning move is made by O if left open
     self.assertEquals(6, board.find_next_move("X"))  # Test winning move is blocked by X
开发者ID:achernet,项目名称:Tic-Tac-Toe,代码行数:12,代码来源:tests.py

示例7: test_gameplay_first_player_second_move

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import find_next_move [as 别名]
 def test_gameplay_first_player_second_move(self):
     """
     Test that second play as AI makes sense (assuming AI was the first player)
     """
     board = Board()
     board.add_mark(0, "X")
     pos_move_dict = {1: [2, 6], 8: [2, 6], 2: [8]}
     for pos, expected_moves in pos_move_dict.iteritems():
         board.o_positions.clear()
         board.add_mark(pos, "O")
         second_move = board.find_next_move("X")
         self.assertIn(second_move, expected_moves)
开发者ID:achernet,项目名称:Tic-Tac-Toe,代码行数:14,代码来源:tests.py


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