Esempio n. 1
0
    def test_minimax(self):
        """
        Tests that computer can block human. 
        """
        board = Board()
        computer = Player(board,
                          'C',
                          'computer',
                          is_human=False,
                          ai_strat=Minimax(board))
        human = Player(board, 'H', 'human')
        # set up human about to win
        board.spaces[0] = human
        board.spaces[1] = human
        # set up computer to not have win cond
        board.spaces[4] = computer
        board.spaces[8] = computer
        """
        |H|H|2|
        |3|C|5|
        |6|7|C|
        """
        board.CURRENT_PLAYER = computer
        board.WAITING_PLAYER = human

        self.assertEqual(2, computer.make_play())
Esempio n. 2
0
 def test_minimax_failing_block(self):
     """
     |H|1|H|
     |3|C|5|
     |6|7|8|
     """
     board = Board()
     computer = Player(board,
                       'C',
                       'computer',
                       is_human=False,
                       ai_strat=Minimax(board))
     computer.ai_strat.MINIMAX_DEPTH = 1
     human = Player(board, 'H', 'human')
     board.spaces[0] = human
     board.spaces[2] = human
     board.spaces[4] = computer
     board.CURRENT_PLAYER = computer
     board.WAITING_PLAYER = human
     self.assertEqual(1, computer.make_play())