示例#1
0
    def test__moves__pawn(self):
        b = BtchBoard()

        moves = sorted(sq for sq in b.pawnMoves('white', 8, 6))

        expected = [(6, 6), (7, 6)]

        self.assertListEqual(moves, expected)
示例#2
0
    def test__rookMoves__startBoard(self):

        b = BtchBoard()

        moves = sorted(sq for sq in b.rookMoves('black', 2, 2))

        expected = []

        self.assertListEqual(moves, expected)
示例#3
0
    def test__rookMoves__emptyBoard(self):

        b = BtchBoard()
        b.empty()

        moves = sorted(sq for sq in b.rookMoves('white', 2, 2))

        print('moves\n{}'.format(self.squares2ascii(moves)))

        expected = sorted([(i, 2)
                           for i in range(3, 10)] + [(2, j)
                                                     for j in range(3, 10)])

        print('expected\n{}'.format(self.squares2ascii(expected)))

        self.assertListEqual(moves, expected)
示例#4
0
    def test__isEnemy(self):

        result = BtchBoard.isEnemy('white', None)

        self.assertFalse(result)

        result = BtchBoard.isEnemy('white', 'p')

        self.assertFalse(result)

        result = BtchBoard.isEnemy('white', 'P')

        self.assertTrue(result)

        result = BtchBoard.isEnemy('white', '_')

        self.assertFalse(result)
示例#5
0
    def test__bishopMoves__emptyBoard(self):

        b = BtchBoard()
        b.empty()

        moves = sorted(sq for sq in b.bishopMoves('white', 6, 6))

        print('moves\n{}'.format(self.squares2ascii(moves)))

        expected = sorted([(i, i)
                           for i in range(2, 10)] + [(3 + i, 9 - i)
                                                     for i in range(0, 7)])
        expected.remove((6, 6))
        expected.remove((6, 6))

        print('expected\n {}'.format(self.squares2ascii(expected)))

        self.assertListEqual(moves, expected)
示例#6
0
    def test__moves__fog(self):
        boardStr = ('________'
                    '________'
                    '________'
                    '________'
                    '________'
                    '________'
                    'ppppppp_'
                    'rnbqkbnr')

        b = BtchBoard.factory(boardStr)

        print('fog {} '.format(b.toElements()))

        moves = b.possibleMoves('white', 9, 9)

        expectedMoves = sorted([(i, 9) for i in range(2, 9)])

        self.assertListEqual(moves, expectedMoves)
示例#7
0
    def test__filter__startPosition(self):
        color = 'white'
        b = BtchBoard()
        b.filter(color)

        expectedBoardStr = ('________'
                            '________'
                            '________'
                            '________'
                            '________'
                            '________'
                            'pppppppp'
                            'rnbqkbnr')

        expected = BtchBoard.factory(expectedBoardStr)
        expected.castleable = 'lsk'

        self.assertDictEqual(b.toElements(), expected.toElements())
示例#8
0
    def test__factory(self):
        btchBoard = BtchBoard.factory(self.startboardStr())

        self.assertEqual(btchBoard.toElements(), self.fakeElements())
示例#9
0
 def toBtchBoard(self) -> BtchBoard:
     enpassantColumn = self.enpassantColumn()
     enpassant = enpassantColumn + 2 if enpassantColumn is not None else None
     return BtchBoard.factoryFromElements(self.board, self.taken,
                                          self.castleable, enpassant)