Esempio n. 1
0
    def test_minmax_d2(self):
        ''' 
        O|-|X
        X|X|O
        O|-|-
        '''
        ai_player = Player("AI_1", Token.A, True)
        game = TicTacToe(p1=ai_player)
        depth = 2
        minmax = Minmax(ai_player, depth)

        game.play(Point(2, 0))
        game.play(Point(0, 0))
        game.play(Point(0, 1))
        game.play(Point(0, 2))
        game.play(Point(1, 1))
        game.play(Point(2, 1))

        game.play(Point(1, 0))
        val, _ = minmax._min(game, depth)
        self.assertEqual(val, Minmax.DRAW_POINT)
        game.undo()

        game.play(Point(1, 2))
        val, _ = minmax._min(game, depth)
        self.assertEqual(val, Minmax.DRAW_POINT)
        game.undo()
Esempio n. 2
0
    def test_minmax_d1(self):
        '''
        XX-
        OO-
        XO-
        Simulate max loop and calling min evaluation
        '''
        ai_player = Player("AI_1", Token.A, True)
        game = TicTacToe(p1=ai_player)
        depth = 1
        minmax = Minmax(ai_player, depth)

        game.play(Point(0, 0))
        game.play(Point(0, 1))
        game.play(Point(1, 0))
        game.play(Point(1, 1))
        game.play(Point(0, 2))
        game.play(Point(1, 2))

        game.play(Point(2, 0))
        val, _ = minmax._min(game, depth)
        self.assertEqual(val, Minmax.WIN_POINT + depth)
        game.undo()

        game.play(Point(2, 1))
        val, _ = minmax._min(game, depth)
        self.assertEqual(val, Minmax.DRAW_POINT)
        game.undo()

        game.play(Point(2, 2))
        val, _ = minmax._min(game, depth)
        self.assertEqual(val, Minmax.LOOSE_POINT)
        game.undo()