import unittest
from typing import List

from minimax import find_best_move
from tictactoe import TTTPiece, TTTBoard
from board import Move

class TTTMinimaxTestCase(unittest.TestCase):
    def test_easy_positioin(self):
        # X走一步就赢
        to_win_easy_position: List[TTTPiece] = [TTTPiece.X,TTTPiece.O,TTTPiece.X,
                                                TTTPiece.X,TTTPiece.E,TTTPiece.O,
                                                TTTPiece.E,TTTPiece.E,TTTPiece.O]
        test_board1: TTTBoard = TTTBoard(to_win_easy_position,
                                         TTTPiece.X)
        answer1: Move = find_best_move(test_board1)
        self.assertEqual(answer1,6)

    def test_block_position(self):
        # X走一步能阻止O赢
        to_block_position: List[TTTPiece] = [TTTPiece.X,TTTPiece.E,TTTPiece.E,
                                             TTTPiece.E,TTTPiece.E,TTTPiece.O,
                                             TTTPiece.E,TTTPiece.X,TTTPiece.O]
        test_board2: TTTBoard = TTTBoard(to_block_position,
                                         TTTPiece.X)
        answer2: Move = find_best_move(test_board2)
        self.assertEqual(answer2,2)
    
    def test_hard_position(self):
        # X走一步之后，下一步无论O怎么走都无法阻止X赢
        to_win_hard_position: List[TTTPiece] = [TTTPiece.X,TTTPiece.E,TTTPiece.E,
                                                TTTPiece.E,TTTPiece.E,TTTPiece.O,
                                                TTTPiece.O,TTTPiece.X,TTTPiece.E]
        test_board3: TTTBoard = TTTBoard(to_win_hard_position,
                                         TTTPiece.X)
        answer3: Move = find_best_move(test_board3)
        self.assertEqual(answer3, 1)



if __name__ == '__main__':
    unittest.main()