コード例 #1
0
    def test_diagonal2(self):
        t3 = TTT(3)
        s3 = np.array([1, 0, -1, 1, -1, 0, -1, 1, 0])
        self.assertEqual(t3.check_winner(s3), {
            'winner': -1,
            'lines': [[2, 4, 6]]
        })
        self.assertTrue(t3.is_terminated(s3))

        t4 = TTT(4)
        s4 = np.array([-1, 0, 0, 1, -1, 0, 1, 0, -1, 1, 0, 0, 1, 0, 0, 0])
        self.assertTrue(t4.is_terminated(s4))
        self.assertEqual(t4.check_winner(s4), {
            'winner': 1,
            'lines': [[3, 6, 9, 12]]
        })
コード例 #2
0
    def test_diagonal1(self):
        t3 = TTT(3)
        s3 = np.array([1, 0, -1, 0, 1, -1, 0, 0, 1])
        self.assertTrue(t3.is_terminated(s3))
        self.assertEqual(t3.check_winner(s3), {
            'winner': 1,
            'lines': [[0, 4, 8]]
        })

        t4 = TTT(4)
        s4 = np.array([-1, 0, 0, 1, 0, -1, 0, 1, 0, 1, -1, 0, 1, 0, 0, -1])
        self.assertTrue(t4.is_terminated(s4))
        self.assertEqual(t4.check_winner(s4), {
            'winner': -1,
            'lines': [[0, 5, 10, 15]]
        })
コード例 #3
0
 def test_row(self):
     t3 = TTT(3)
     s3 = np.array([0, 0, 0, -1, -1, 0, 1, 1, 1])
     self.assertEqual(t3.check_winner(s3), {
         'winner': 1,
         'lines': [[6, 7, 8]]
     })
     self.assertTrue(t3.is_terminated(s3))
コード例 #4
0
 def test_column(self):
     t4 = TTT(4)
     s4 = np.array([1, 0, 0, -1, 0, 1, 0, -1, 1, 0, 0, -1, 0, 1, 0, -1])
     self.assertEqual(t4.check_winner(s4), {
         'winner': -1,
         'lines': [[3, 7, 11, 15]]
     })
     self.assertTrue(t4.is_terminated(s4))
コード例 #5
0
    def test_minimax_vs_minimax(self):

        size = 3
        t = TTT(size)
        filepath = 'results/minimax.pk'
        minimax_loaded = minimax_load(filepath)
        moves = 0
        while True:
            [_, best_move] = minimax_loaded(t.get_state())
            t.put(best_move)
            moves += 1
            if t.is_terminated():
                break
            pass

        self.assertEqual(t.check_winner()['winner'], 0)
        pass
コード例 #6
0
    def test_alphabeta_vs_alphabeta(self):

        t = TTT(3)
        player = ABPruning(3)
        moves = 0
        print('Moves : 0 ', end='')
        while True:
            [_, best_move] = player.get(t.get_state(), t.get_mover())
            t.put(best_move)
            moves += 1
            print(f'{moves} ', end='')
            if t.is_terminated():
                break
            pass

        print('final state')
        print(t)
        self.assertEqual(t.check_winner()['winner'], 0)
コード例 #7
0
    def test_alphabeta_vs_minimax(self):

        t = TTT(3)
        minimax_player = minimax_load('results/minimax.pk')
        alphabeta_player = ABPruning(3)

        moves = 0
        print('Moves : 0 ', end='')
        while True:
            if t.get_mover() == 1:
                [_, best_move] = alphabeta_player.get(t.get_state(),
                                                      t.get_mover())
            elif t.get_mover() == -1:
                [_, best_move] = minimax_player(t.get_state())
            t.put(best_move)
            moves += 1
            print(f'{moves} ', end='')
            if t.is_terminated():
                break
            pass

        print('final state')
        print(t)
        self.assertEqual(t.check_winner()['winner'], 0)