예제 #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 testGetAllLegalMoveSets(self):
        game = Game()
        #[-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)

        allMoveSets = analyzer.getAllLegalMoveSets()
        self.assertEqual(len(allMoveSets), 15)

        game.board.tokens = [
            -2, 0, 0, 0, 0, 5, 0, 3, 0, 0, 0, -5, 3, 0, 0, 0, -3, 0, -5, 0, 0,
            0, 0, 2, 2, 0, 0, 0
        ]
        allMoveSets = analyzer.getAllLegalMoveSets()
        self.assertEqual(len(allMoveSets), 1)

        game.board.tokens = [
            -2, 0, 0, 0, 0, 5, 0, 3, 0, 0, 0, -5, 3, 0, 0, 0, -3, 0, -5, 0, 0,
            0, 0, 1, 3, 0, 0, 0
        ]
        game.whiteDice1.faceUp = 1
        game.whiteDice2.faceUp = 1
        allMoveSets = analyzer.getAllLegalMoveSets()
        self.assertEqual(len(allMoveSets), 3)

        game.board.tokens = [
            -2, 0, 0, 0, 0, 5, 0, 3, 0, 0, 0, -5, 3, 0, 0, 0, -3, 0, -5, 0, 0,
            0, 0, 2, 2, 0, 0, 0
        ]
        game.whiteDice1.faceUp = 1
        game.whiteDice2.faceUp = 1
        allMoveSets = analyzer.getAllLegalMoveSets()
        self.assertEqual(len(allMoveSets), 9)

        # Test red player
        game.currentPlayer = Game.red
        #[-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.redDice1.faceUp = 1
        game.redDice2.faceUp = 2

        analyzer = BoardAnalyzer(game)

        allMoveSets = analyzer.getAllLegalMoveSets()
        self.assertEqual(len(allMoveSets), 15)

        game.board.tokens = [
            -2, 0, 0, 0, 0, 5, 0, 3, 0, 0, 0, -5, 3, 0, 0, 0, -3, 0, -5, 0, 0,
            0, 0, 4, 0, 0, 0, -2
        ]
        allMoveSets = analyzer.getAllLegalMoveSets()
        self.assertEqual(len(allMoveSets), 1)

        game.board.tokens = [
            -2, 0, 0, 0, 0, 5, 0, 3, 0, 0, 0, -5, 3, 0, 0, 0, -3, 0, -5, 0, 0,
            0, 0, 4, 0, 0, 0, -3
        ]
        game.redDice1.faceUp = 1
        game.redDice2.faceUp = 1
        allMoveSets = analyzer.getAllLegalMoveSets()
        self.assertEqual(len(allMoveSets), 3)

        game.board.tokens = [
            -2, 0, 0, 0, 0, 5, 0, 3, 0, 0, 0, -5, 3, 0, 0, 0, -3, 0, -5, 0, 0,
            0, 0, 4, 0, 0, 0, -2
        ]
        game.redDice1.faceUp = 1
        game.redDice2.faceUp = 1
        allMoveSets = analyzer.getAllLegalMoveSets()
        self.assertEqual(len(allMoveSets), 9)