예제 #1
0
    def test_state_10(self):
        bs = [['x', 'o', 'x'],
              ['o', 'x', 'o'],
              ['o', ' ', ' ']]

        g = TicTacToeAI(bs, 'x')
        self.assertEqual(g.get_next_move(), (2, 2))
예제 #2
0
class TicTacToeAITest(TestCase):

    def setUp(self):
        board_state = [['o', ' ', 'x'],
                       ['x', ' ', ' '],
                       ['x', 'o', 'o']]

        self.g = TicTacToeAI(board_state)

    def test_possible_moves(self):
        self.assertEqual(self.g.possible_moves(), [(0, 1), (1, 1), (1, 2)])

    def test_winner_o(self):
        self.assertEqual(self.g.board_status(), None)
        self.g.move('o', 1, 1)
        self.assertEqual(self.g.board_status(), 'o')

    def test_winner_x(self):
        self.assertEqual(self.g.board_status(), None)
        self.g.move('x', 1, 1)
        self.assertEqual(self.g.board_status(), 'x')

    def test_draw_board_status(self):
        draw_board_state = [['o', 'o', 'x'],
                            ['x', 'x', 'o'],
                            ['o', 'x', 'o']]
        g = TicTacToeAI(draw_board_state)
        self.assertEqual(g.board_status(), 'draw')

    def test_score_possible_moves(self):
        self.assertEqual(self.g.score_possible_moves(), [None, 1, None])
예제 #3
0
    def test_state_4(self):
        bs = [['x', ' ', ' '], [' ', ' ', ' '], [' ', ' ', ' ']]

        g = TicTacToeAI(bs, 'o')
        self.assertIn(g.get_next_move(),
                      [(0, 1), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0),
                       (2, 1), (2, 2)])
예제 #4
0
    def test_state_4(self):
        bs = [['x', ' ', ' '],
              [' ', ' ', ' '],
              [' ', ' ', ' ']]

        g = TicTacToeAI(bs, 'o')
        self.assertIn(g.get_next_move(), [(0, 1), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)])
예제 #5
0
class TicTacToeAITest(TestCase):
    def setUp(self):
        board_state = [['o', ' ', 'x'], ['x', ' ', ' '], ['x', 'o', 'o']]

        self.g = TicTacToeAI(board_state)

    def test_possible_moves(self):
        self.assertEqual(self.g.possible_moves(), [(0, 1), (1, 1), (1, 2)])

    def test_winner_o(self):
        self.assertEqual(self.g.board_status(), None)
        self.g.move('o', 1, 1)
        self.assertEqual(self.g.board_status(), 'o')

    def test_winner_x(self):
        self.assertEqual(self.g.board_status(), None)
        self.g.move('x', 1, 1)
        self.assertEqual(self.g.board_status(), 'x')

    def test_draw_board_status(self):
        draw_board_state = [['o', 'o', 'x'], ['x', 'x', 'o'], ['o', 'x', 'o']]
        g = TicTacToeAI(draw_board_state)
        self.assertEqual(g.board_status(), 'draw')

    def test_score_possible_moves(self):
        self.assertEqual(self.g.score_possible_moves(), [None, 1, None])
예제 #6
0
    def test_state_6(self):
        bs = [['x', ' ', ' '],
              [' ', 'o', ' '],
              [' ', ' ', 'x']]

        g = TicTacToeAI(bs, 'o')
        for _ in range(10):
            self.assertIn(g.get_next_move(), [(0, 1), (1, 0), (1, 2), (2, 1)])
예제 #7
0
    def test_state_8(self):
        # draw state
        bs = [[' ', ' ', ' '],
              [' ', 'o', ' '],
              ['x', 'o', 'x']]

        g = TicTacToeAI(bs, 'x')
        self.assertEqual(g.get_next_move(), (0, 1))
예제 #8
0
    def test_state_9(self):
        bs = [['x', 'o', 'x'],
              [' ', 'x', 'o'],
              ['o', ' ', ' ']]

        g = TicTacToeAI(bs, 'x')
        for _ in range(10):
            self.assertEqual(g.get_next_move(), (2, 2))
예제 #9
0
    def test_state_5(self):
        # loose position
        bs = [['x', ' ', 'x'],
              [' ', 'o', 'x'],
              ['o', ' ', ' ']]

        g = TicTacToeAI(bs, 'o')
        self.assertIn(g.get_next_move(), [(0, 1), (1, 0), (2, 1), (2, 2)])
예제 #10
0
    def test_state_7(self):
        # draw state
        bs = [['x', 'x', 'o'],
              ['o', 'o', 'x'],
              ['x', ' ', ' ']]

        g = TicTacToeAI(bs, 'o')
        self.assertIn(g.get_next_move(), [(2, 1), (2, 2)])
예제 #11
0
    def test_state_3(self):
        bs = [['o', 'x', 'x'], ['x', ' ', ' '], ['x', 'o', 'o']]

        g = TicTacToeAI(bs, 'x')
        self.assertEqual(g.get_next_move(), (1, 1))
        g = TicTacToeAI(bs, 'o')
        self.assertEqual(g.get_next_move(), (1, 1))
예제 #12
0
    def test_state_9(self):
        bs = [['x', 'o', 'x'], [' ', 'x', 'o'], ['o', ' ', ' ']]

        g = TicTacToeAI(bs, 'x')
        for _ in range(10):
            self.assertEqual(g.get_next_move(), (2, 2))
예제 #13
0
    def setUp(self):
        board_state = [['o', ' ', 'x'],
                       ['x', ' ', ' '],
                       ['x', 'o', 'o']]

        self.g = TicTacToeAI(board_state)
예제 #14
0
    def setUp(self):
        board_state = [['o', ' ', 'x'], ['x', ' ', ' '], ['x', 'o', 'o']]

        self.g = TicTacToeAI(board_state)
예제 #15
0
 def test_draw_board_status(self):
     draw_board_state = [['o', 'o', 'x'],
                         ['x', 'x', 'o'],
                         ['o', 'x', 'o']]
     g = TicTacToeAI(draw_board_state)
     self.assertEqual(g.board_status(), 'draw')
예제 #16
0
    def test_state_5(self):
        # loose position
        bs = [['x', ' ', 'x'], [' ', 'o', 'x'], ['o', ' ', ' ']]

        g = TicTacToeAI(bs, 'o')
        self.assertIn(g.get_next_move(), [(0, 1), (1, 0), (2, 1), (2, 2)])
예제 #17
0
    def test_state_6(self):
        bs = [['x', ' ', ' '], [' ', 'o', ' '], [' ', ' ', 'x']]

        g = TicTacToeAI(bs, 'o')
        for _ in range(10):
            self.assertIn(g.get_next_move(), [(0, 1), (1, 0), (1, 2), (2, 1)])
예제 #18
0
    def test_state_8(self):
        # draw state
        bs = [[' ', ' ', ' '], [' ', 'o', ' '], ['x', 'o', 'x']]

        g = TicTacToeAI(bs, 'x')
        self.assertEqual(g.get_next_move(), (0, 1))
예제 #19
0
    def test_state_7(self):
        # draw state
        bs = [['x', 'x', 'o'], ['o', 'o', 'x'], ['x', ' ', ' ']]

        g = TicTacToeAI(bs, 'o')
        self.assertIn(g.get_next_move(), [(2, 1), (2, 2)])
예제 #20
0
 def get_next_minimax_move(self):
     from game.ai import TicTacToeAI
     board, _ = self.get_board_2d_and_moves()
     ai_player = 'x' if self.get_ai_player() == 'p1' else 'o'
     g = TicTacToeAI(board, ai_player)
     return g.get_next_move()
예제 #21
0
 def test_draw_board_status(self):
     draw_board_state = [['o', 'o', 'x'], ['x', 'x', 'o'], ['o', 'x', 'o']]
     g = TicTacToeAI(draw_board_state)
     self.assertEqual(g.board_status(), 'draw')