Esempio n. 1
0
    def testTableSize(self):
        gameEngine = GameEngine(1, 7, 8)
        table = gameEngine.getTable()

        self.assertEqual(table.height, 8)
        self.assertEqual(table.width, 7)
        self.assertEqual(table.emptyCells, table.height * table.width)
        self.assertFalse(table.isFull())
Esempio n. 2
0
    def testPlayerMove(self):
        gameEngine = GameEngine(1, 7, 7)
        table = gameEngine.getTable()

        result = gameEngine.playerMove(1, 1)
        self.assertRaises(EmptyError, gameEngine.playerMove, 0, 0)
        self.assertRaises(EmptyError, gameEngine.playerMove, 0, 1)
        self.assertRaises(EmptyError, gameEngine.playerMove, 0, 2)
        self.assertRaises(EmptyError, gameEngine.playerMove, 2, 0)
        self.assertRaises(EmptyError, gameEngine.playerMove, 1, 1)

        self.assertEqual(table.emptyCells, 40)
        self.assertIsNone(result)
Esempio n. 3
0
    def testComputerMove(self):
        gameEngine = GameEngine(1, 7, 7)
        table = gameEngine.getTable()

        result = gameEngine.computerMove()
        self.assertIsNone(result)
        temp = table.emptyCells
        self.assertLess(temp, 49)
        self.assertGreaterEqual(temp, 40)

        result = gameEngine.computerMove()
        self.assertIsNone(result)
        self.assertLess(table.emptyCells, temp)
        self.assertGreaterEqual(table.emptyCells, temp - 9)
Esempio n. 4
0
    def testMoveToWin4(self):
        """
        the state of the board before the computer move - in this case, the computer cannot move to win
        _|_|_
        _|x|_
        _|_|_
        """
        gameEngine = GameEngine(1, 3, 3)
        table = gameEngine.getTable()

        table.setValue(1, 1, OCCUPIED_SYMBOL)
        result = gameEngine.computerMove()
        self.assertIsNone(result)
        self.assertFalse(table.isFull())
        self.assertLessEqual(table.emptyCells, 5)
Esempio n. 5
0
    def testMoveToWin2(self):
        """
        x|_|_
        _|_|_
        _|_|_
        """
        gameEngine = GameEngine(1, 3, 3)
        table = gameEngine.getTable()

        table.setValue(0, 0, OCCUPIED_SYMBOL)
        result = gameEngine.computerMove()
        self.assertEqual(result, COMPUTER_SYMBOL)
        self.assertTrue(table.isFull())
        self.assertEqual(table.emptyCells, 0)
        self.assertEqual(table.getValue(1, 1), COMPUTER_SYMBOL)
Esempio n. 6
0
    def testMoveToWin1(self):
        """
        the state of the board before the computer move
        _|_|_
        _|_|_
        _|_|_
        """
        gameEngine = GameEngine(1, 3, 3)
        table = gameEngine.getTable()

        result = gameEngine.computerMove()
        self.assertEqual(result, COMPUTER_SYMBOL)
        self.assertTrue(table.isFull())
        self.assertEqual(table.emptyCells, 0)
        self.assertEqual(table.getValue(1, 1), COMPUTER_SYMBOL)
Esempio n. 7
0
    def testGetValue(self):
        gameEngine = GameEngine(1, 7, 8)
        table = gameEngine.getTable()

        self.assertEqual(table.getValue(1, 1), EMPTY_SYMBOL)

        gameEngine.playerMove(1, 1)
        self.assertEqual(table.getValue(1, 1), PLAYER_SYMBOL)
        self.assertEqual(table.getValue(0, 0), OCCUPIED_SYMBOL)
        self.assertEqual(table.getValue(0, 1), OCCUPIED_SYMBOL)
        self.assertEqual(table.getValue(0, 2), OCCUPIED_SYMBOL)
        self.assertEqual(table.getValue(1, 0), OCCUPIED_SYMBOL)
        self.assertEqual(table.getValue(1, 2), OCCUPIED_SYMBOL)
        self.assertEqual(table.getValue(2, 0), OCCUPIED_SYMBOL)
        self.assertEqual(table.getValue(2, 1), OCCUPIED_SYMBOL)
        self.assertEqual(table.getValue(2, 2), OCCUPIED_SYMBOL)

        self.assertEqual(table.getValue(3, 3), EMPTY_SYMBOL)
Esempio n. 8
0
    def testGetAllEmpty(self):
        gameEngine = GameEngine(1, 7, 7)
        table = gameEngine.getTable()

        posList = table.getAllEmpty()
        self.assertEqual(len(posList), 49)
        self.assertEqual(len(posList), table.emptyCells)

        gameEngine.playerMove(3, 3)
        posList = table.getAllEmpty()
        self.assertEqual(len(posList), 40)

        self.assertEqual(posList[0], (0, 0))
        self.assertEqual(posList[1], (0, 1))
        self.assertEqual(posList[2], (0, 2))
        self.assertEqual(posList[3], (0, 3))
        self.assertEqual(posList[4], (0, 4))

        self.assertEqual(posList[35], (6, 2))
        self.assertEqual(posList[36], (6, 3))
        self.assertEqual(posList[37], (6, 4))
        self.assertEqual(posList[38], (6, 5))
        self.assertEqual(posList[39], (6, 6))
Esempio n. 9
0
    def testGetFirstEmpty(self):
        gameEngine = GameEngine(1, 7, 7)
        table = gameEngine.getTable()

        self.assertEqual(table.getFirstEmpty(), (0, 0))
        gameEngine.playerMove(1, 1)
        self.assertEqual(table.getFirstEmpty(), (0, 3))
        gameEngine.playerMove(1, 4)
        self.assertEqual(table.getFirstEmpty(), (0, 6))
        gameEngine.playerMove(1, 6)
        self.assertEqual(table.getFirstEmpty(), (3, 0))
        gameEngine.playerMove(4, 1)
        self.assertEqual(table.getFirstEmpty(), (3, 3))
        gameEngine.playerMove(4, 4)
        self.assertEqual(table.getFirstEmpty(), (3, 6))
        gameEngine.playerMove(4, 6)
        self.assertEqual(table.getFirstEmpty(), (6, 0))
        gameEngine.playerMove(6, 1)
        self.assertEqual(table.getFirstEmpty(), (6, 3))
        gameEngine.playerMove(6, 4)
        self.assertEqual(table.getFirstEmpty(), (6, 6))
        gameEngine.computerMove()
        self.assertTrue(table.isFull())
Esempio n. 10
0
    def testEmptyCells(self):
        gameEngine = GameEngine(1, 7, 7)
        table = gameEngine.getTable()

        self.assertEqual(table.emptyCells, 49)
        gameEngine.playerMove(1, 1)
        self.assertEqual(table.emptyCells, 40)
        gameEngine.playerMove(4, 4)
        self.assertEqual(table.emptyCells, 31)
        gameEngine.playerMove(1, 4)
        self.assertEqual(table.emptyCells, 22)
        gameEngine.playerMove(4, 1)
        self.assertEqual(table.emptyCells, 13)
        gameEngine.playerMove(6, 0)
        self.assertEqual(table.emptyCells, 11)
        gameEngine.playerMove(0, 6)
        self.assertEqual(table.emptyCells, 9)
        gameEngine.playerMove(6, 3)
        self.assertEqual(table.emptyCells, 6)
        gameEngine.playerMove(3, 6)
        self.assertEqual(table.emptyCells, 3)
        gameEngine.computerMove()
        self.assertEqual(table.emptyCells, 0)
        self.assertTrue(table.isFull())