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


Python State.put_symbol方法代码示例

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


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

示例1: TestBoard

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

    def setUp(self):
        self.__state = State([State.EMPTY] * 9)

    def test_create_new_empty_board(self):
        self.assertEqual(self.__state.get_side_len(), 3)
        self.assertEqual(self.__state.get_board(), [State.EMPTY]*9)

    def test_add_a_cross_to_board(self):
        board_with_x = [State.EMPTY] * 4 + list(State.X) + [State.EMPTY] * 4
        self.assertEqual(self.__state.put_symbol(State.X, 1, 1).get_board(), board_with_x)

    def test_add_a_noughts_to_board(self):
        board_with_x = [State.EMPTY] * 4 + list(State.O) + [State.EMPTY] * 4
        self.assertEqual(self.__state.put_symbol(State.O, 1, 1).get_board(), board_with_x)
开发者ID:jdvr,项目名称:pythonTicTacToe,代码行数:18,代码来源:test_board.py

示例2: TestGame

# 需要导入模块: from state import State [as 别名]
# 或者: from state.State import put_symbol [as 别名]
class TestGame(unittest.TestCase):

    def setUp(self):
        self.__state = State([State.EMPTY] * 9)
        self.__player_x = Player(State.X)
        self.__player_o = Player(State.O)

    def test_create_a_new_game(self):
        game = Game(self.__state, self.__player_o, self.__player_x, True)
        self.assertEqual(game.get_state(), self.__state)

    def test_adding_a_cross(self):
        game = Game(self.__state, self.__player_o, self.__player_x, True)
        self.assertEqual(game.player_move(1, 1).get_state().to_string(), self.__state.put_symbol(State.O, 1, 1).to_string())

    def test_changing_player_turn(self):
        game = Game(self.__state, self.__player_o, self.__player_x, True)
        game = game.change_turn()
        self.assertEqual(game.get_player_turn(), self.__player_x.get_type())
        game = game.change_turn()
        self.assertEqual(game.get_player_turn(), self.__player_o.get_type())

    def test_cross_win_the_game_horizontal(self):
        game = Game(self.__state, self.__player_x, self.__player_o, True)
        game = game.player_move(0, 0).player_move(0, 1).player_move(0, 2)
        self.assertTrue(game.won_by(State.X))

    def test_cross_win_the_game_vertical(self):
        game = Game(self.__state, self.__player_x, self.__player_o, True)
        game = game.player_move(0, 0).player_move(1, 0).player_move(2, 0)
        self.assertTrue(game.won_by(State.X))
开发者ID:jdvr,项目名称:pythonTicTacToe,代码行数:33,代码来源:test_game.py


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