예제 #1
0
    def testGetAllLegalMoveSets_isSameForWhiteAndForRed(self):
        game = Game()
        a = [
            -2, 0, 0, 0, 0, 5, 0, 3, 0, 0, 0, -5, 5, 0, 0, 0, -3, 0, -5, 0, 0,
            0, 0, 2, 0, 0, 0, 0
        ]
        game.whiteDice1.faceUp = 1
        game.whiteDice2.faceUp = 2

        analyzer = BoardAnalyzer(game)

        aFlip = a.copy()
        aFlip = BoardAnalyzer.flipBoard(aFlip)
        self.assertEqual(aFlip, a)
        aFlip = BoardAnalyzer.flipBoard(aFlip)
        self.assertEqual(a, aFlip)
        # The inital board is s symmetric.
        # Here I don't need the flip() function

        # The initial board is symmetric.
        # red and white should have symmetric moves
        allAMoveSets = analyzer.getAllLegalMoveSets()
        game.currentPlayer = game.red
        game.redDice1.faceUp = game.whiteDice1.faceUp
        game.redDice2.faceUp = game.whiteDice2.faceUp

        allBMoveSets = analyzer.getAllLegalMoveSets()
        allBWhiteMoveSets = self.translateMoveSetsToWhiteCoordinates(
            allBMoveSets)

        #self.humanReadablyPrintMoves(game, allAMoveSets, allBWhiteMoveSets)

        self.assertTrue(((5, 4), (4, 2)) in allAMoveSets)
        self.assertTrue((((7, 6), (6, 4)) in allAMoveSets)
                        or (((7, 5), (5, 4)) in allAMoveSets)
                        or (((5, 4), (7, 5)) in allAMoveSets))

        self.assertEqual(len(allAMoveSets), len(allBMoveSets))
        self.assertEqual(allAMoveSets, allBWhiteMoveSets)

        a = randomPopulatedBoard()
        b = randomPopulatedBoard()
        #print(a)
        #print(b)
        # The assignment of a list as default parameter gives the same object.
        # The assignment of a list within a method creates a new object every time. Wow!
        self.assertNotEqual(a, b)

        a = randomPopulatedBoard()
        b = a.copy()
        b = BoardAnalyzer.flipBoard(b)
        self.assertNotEqual(
            a, b)  # a random board will most likely not be symmetric
        b = BoardAnalyzer.flipBoard(b)
        self.assertEqual(a, b)  # flipping back yields the original
예제 #2
0
    def testFlipBoard(self):

        # initial board
        a = [
            -2, 0, 0, 0, 0, 5, 0, 3, 0, 0, 0, -5, 5, 0, 0, 0, -3, 0, -5, 0, 0,
            0, 0, 2, 0, 0, 0, 0
        ]
        b = BoardAnalyzer.flipBoard(a)
        self.assertEqual(a, b)  # the initial board is symmetric

        a = [
            -15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 15, 0, 0, 0, 0
        ]
        b = BoardAnalyzer.flipBoard(a)
        self.assertEqual(a, b)  # the initial board is symmetric

        #a = [,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,0, 0,0,0,0,0,, 0,0,0,0]

        a = [
            1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1,
            -1, -1, -1, -1, 1, -2, 2, -1
        ]
        b = BoardAnalyzer.flipBoard(a)
        self.assertEqual(a, b)  # the initial board is symmetric

        a = [
            -14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 15, 0, 0, 0, 0
        ]
        b = BoardAnalyzer.flipBoard(a)
        self.assertNotEqual(a, b)  # the initial board is symmetric

        a = [
            -14, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 15, 0, 0, 0, 0
        ]
        b = BoardAnalyzer.flipBoard(a)
        self.assertNotEqual(a, b)  # the initial board is symmetric
예제 #3
0
    def checkMovesForRandomBoard(self, game, randomBoardInitializerFunction,
                                 analyzer):
        game.currentPlayer = Game.white
        game.rollOwnDice()

        a = randomBoardInitializerFunction()
        game.board.tokens = a
        allAMoveSets = analyzer.getAllLegalMoveSets()

        game.currentPlayer = Game.red
        game.redDice1.faceUp = game.whiteDice1.faceUp
        game.redDice2.faceUp = game.whiteDice2.faceUp
        b = a.copy()
        b = BoardAnalyzer.flipBoard(b)
        game.board.tokens = b
        allBMoveSets = self.translateMoveSetsToWhiteCoordinates(
            analyzer.getAllLegalMoveSets())

        game.board.tokens = a  # display the original.
        #self.humanReadablyPrintMoves(game, allAMoveSets, allBMoveSets)
        self.assertEqual(len(allAMoveSets), len(allBMoveSets))
        self.assertEqual(allAMoveSets, allBMoveSets)