def test_aiWinsDepthZero(self): ai = cnai(0) self.board.dropToken("X", 9) self.board.dropToken("O", ai.bestMove("O", self.board).y) self.board.dropToken("X", 9) self.board.dropToken("O", ai.bestMove("O", self.board).y) self.board.dropToken("X", 9) self.board.dropToken("O", ai.bestMove("O", self.board).y) self.assertEqual(self.board.dropAndCheck("O", ai.bestMove("O", self.board).y), True)
def test_aiDeniesPlayer(self): for n in range(3): self.board = Board(10, 15, 4) ai = cnai(1+n) self.board.dropToken("O", 9) self.board.dropToken("O", 9) self.board.dropToken("X", 0+n) self.board.dropToken("X", 1+n) self.board.dropToken("X", 3+n) self.assertEqual(ai.bestMove("O", self.board).y, 2+n)
def test_aiPicksWinning(self): for n in range(4): self.board = Board(10, 15, 4) ai = cnai(0+n) self.board.dropToken("X", 9) self.board.dropToken("X", 9) self.board.dropToken("X", 9) self.board.dropToken("O", 0+n) self.board.dropToken("O", 1+n) self.board.dropToken("O", 3+n) self.assertEqual(ai.bestMove("O", self.board).y, 2+n)
def test_heuristicsCheckCorrect(self): ai = cnai(0) for n in range(10): self.board = Board(10, 15, 4) self.board.dropToken("X", 0+n) self.board.dropToken("X", 0+n) self.board.dropToken("X", 1+n) self.board.dropToken("X", 9-n) self.board.dropToken("X", 9-n) self.board.dropToken("X", 8-n) for i in range(5): a = Move(3, 1+i, "X") b = Move(3, 8-i, "X") self.assertEqual(ai.moveTotalValue(a, self.board), ai.moveTotalValue(b, self.board))