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


Python Board.add_mark方法代码示例

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


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

示例1: test_gameplay_second_player

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add_mark [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

示例2: test_add_mark_already_selected

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add_mark [as 别名]
 def test_add_mark_already_selected(self):
     """
     Test adding a mark to an already-selected position results in an error
     """
     board = Board()
     board.add_mark(0, "X")
     self.assertRaises(TicTacToeError, board.add_mark, 0, "O")
开发者ID:achernet,项目名称:Tic-Tac-Toe,代码行数:9,代码来源:tests.py

示例3: main

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add_mark [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

示例4: test_gameplay_winning_blocking

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add_mark [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

示例5: test_gameplay_first_player_second_move

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add_mark [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

示例6: test_print_board_in_play

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add_mark [as 别名]
 def test_print_board_in_play(self, mock_stdout):
     """
     Test printing the game board when in play
     """
     board = Board()
     board.add_mark(0, "X")
     board.add_mark(6, "O")
     board.add_mark(1, "X")
     board.add_mark(7, "O")
     board.print_board()
     printed_text = self.get_printed_boards(mock_stdout)[0]
     self.assertNotIn("Winner", printed_text)
     self.assertEquals(printed_text.count("X"), 2)
     self.assertEquals(printed_text.count("O"), 2)
开发者ID:achernet,项目名称:Tic-Tac-Toe,代码行数:16,代码来源:tests.py

示例7: test_gameplay_identical_opposite_mark

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add_mark [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

示例8: test_gameplay_first_player_winning_setup

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add_mark [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

示例9: test_operating_completed_game

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add_mark [as 别名]
 def test_operating_completed_game(self):
     """
     Test that finding a move or adding a mark on a completed board results in an error
     """
     board = Board()
     board.add_mark(0, "X")
     board.add_mark(1, "O")
     board.add_mark(4, "X")
     board.add_mark(7, "O")
     board.add_mark(8, "X")  # X has Tic-Tac-Toe on the diagonal
     self.assertRaises(TicTacToeError, board.find_next_move, "O")
     self.assertRaises(TicTacToeError, board.add_mark, 2, "O")
开发者ID:achernet,项目名称:Tic-Tac-Toe,代码行数:14,代码来源:tests.py

示例10: test_print_board_with_winner

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add_mark [as 别名]
 def test_print_board_with_winner(self, mock_stdout):
     """
     Test printing the game board after a winner has been determined.
     """
     board = Board()
     board.add_mark(0, "X")
     board.add_mark(6, "O")
     board.add_mark(1, "X")
     board.add_mark(7, "O")
     board.add_mark(2, "X")
     board.print_board()
     printed_text = self.get_printed_boards(mock_stdout)[0]
     self.assertIn("Winner", printed_text)
     self.assertEquals(printed_text.count("X"), 4)
     self.assertEquals(printed_text.count("O"), 2)
开发者ID:achernet,项目名称:Tic-Tac-Toe,代码行数:17,代码来源:tests.py

示例11: TestBoard

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import add_mark [as 别名]
class TestBoard(unittest.TestCase):

    """
    1 | 2 | 3
    ----------
    4 | 5 | 6  
    ----------
    7 | 8 | 9

    """

    def setUp(self):
        self.board = Board()

    def test_add_mark(self):
        #position must be a dict
        position = None
        self.assertRaises(TypeError, self.board.add_mark, 'X', position)

        #fail if passed a value that's not X or O
        position = 5
        self.assertRaises(ValueError, self.board.add_mark, 'M', position)

        #fail if x, y passed position greater than 2
        position = 10
        self.assertRaises(ValueError, self.board.add_mark, 'X', position)

        position = 5
        self.board.add_mark('X', position)
        #assert self.board.get_value

    def test_valid_position(self):
        position1 = 5
        position2 = 5
        position3 = 4

        self.board.add_mark('X', position1)
        valid = self.board._is_valid_position(position2)
        self.assertEqual(valid, False)

        valid = self.board._is_valid_position(position3)
        self.assertEqual(valid, True)

    def test_reset_board(self):
        position1 = 5
        position2 = 5

        self.board.add_mark('X', position1)
        valid = self.board._is_valid_position(position2)
        self.assertEqual(valid, False)

        self.board.reset_board()
        valid = self.board._is_valid_position(position2)
        self.assertEqual(valid, True)

    def test_get_horizontal(self):
        position1 = 1
        position2 = 2
        position3 = 3

        """
        
        X | X | X
        ----------
        4 | 5 | 6  
        ----------
        7 | 8 | 9

        """

        self.board.reset_board()
        self.board.add_mark('X', position1)
        self.board.add_mark('X', position2)
        self.board.add_mark('X', position3)

        self.assertEqual(self.board.get_horizontal(0), ['X', 'X', 'X'])

    def test_get_vertical(self):
        position4 = 3
        position5 = 6
        position6 = 9

        """

        1 | 2 | X
        ----------
        4 | 5 | X  
        ----------
        7 | 8 | X
        
        """

        self.board.reset_board()
        self.board.add_mark('X', position4)
        self.board.add_mark('X', position5)
        self.board.add_mark('X', position6)

        #check if other combinations match expected
        self.assertEqual(self.board.get_vertical(2), ['X', 'X', 'X'])
        self.assertEqual(self.board.get_forward_diagonal(), ['X', '5', '7'])
#.........这里部分代码省略.........
开发者ID:rayvace,项目名称:tictactoe,代码行数:103,代码来源:test.py


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