def setUp(self): self.white_pawn = Pawn(color.white, Location(1, 0)) self.black_pawn = Pawn(color.black, Location(1, 0)) self.white_pawn_move = Move(Location(2, 0), piece=self.white_pawn, status=notation_const.MOVEMENT, start_loc=Location(1, 0)) self.start_specified = Move(Location(2, 0), piece=self.white_pawn, status=notation_const.MOVEMENT, start_loc=Location(3, 5))
def test_init_default(self): white = color.white black = color.black test = Board([ # First rank [ Rook(white, Location(0, 0)), Knight(white, Location(0, 1)), Bishop(white, Location(0, 2)), Queen(white, Location(0, 3)), King(white, Location(0, 4)), Bishop(white, Location(0, 5)), Knight(white, Location(0, 6)), Rook(white, Location(0, 7)) ], # Second rank [Pawn(white, Location(1, file)) for file in range(8)], # Third rank [None for _ in range(8)], # Fourth rank [None for _ in range(8)], # Fifth rank [None for _ in range(8)], # Sixth rank [None for _ in range(8)], # Seventh rank [Pawn(black, Location(6, file)) for file in range(8)], # Eighth rank [ Rook(black, Location(7, 0)), Knight(black, Location(7, 1)), Bishop(black, Location(7, 2)), Queen(black, Location(7, 3)), King(black, Location(7, 4)), Bishop(black, Location(7, 5)), Knight(black, Location(7, 6)), Rook(black, Location(7, 7)) ] ]) self.assertEqual(self.board, test)
def test_piece_at_square(self): self.assertEqual(self.board.piece_at_square(Location(0, 0)), Rook(color.white, Location(0, 0))) self.assertEqual(self.board.piece_at_square(Location(1, 0)), Pawn(color.white, Location(1, 0))) self.assertEqual(self.board.piece_at_square(Location(0, 1)), Knight(color.white, Location(0, 1)))
def test_place_piece_at_square(self): test = Board.init_default() pawn = Pawn(color.white, Location.from_string("e3")) test.position[2][4] = pawn self.board.place_piece_at_square(pawn, Location.from_string("e3")) self.assertEqual(self.board, test)
def test_incomplete_alg_pawn_movement(self): self.assertEqual( converter.incomplete_alg("e4", color.white, self.test_board), Move( end_loc=Location.from_string("e4"), piece=Pawn(color.white, Location.from_string("e4")), status=notation_const.MOVEMENT, start_loc=Location.from_string("e2") ) )
def test_incomplete_alg_pawn_capture(self): self.test_board.update(converter.short_alg("e4", color.white, self.test_board)) self.test_board.update(converter.short_alg("d5", color.black, self.test_board)) self.assertEqual( converter.incomplete_alg("exd5", color.white, self.test_board), Move( end_loc=Location.from_string("d5"), piece=Pawn(color.white, Location.from_string("e4")), status=notation_const.CAPTURE, start_loc=Location.from_string("e4") ) )
def test_incomplete_alg_pawn_promotion_with_capture(self): self.test_board.move_piece(Location.from_string("a2"), Location.from_string("a7")) self.assertEqual( converter.incomplete_alg("axb8=R", color.white, self.test_board), Move( end_loc=Location.from_string("b8"), piece=Pawn(color.white, Location.from_string("a7")), status=notation_const.CAPTURE_AND_PROMOTE, promoted_to_piece=Rook, start_loc=Location.from_string("a7") ) )
def test_incomplete_alg_pawn_promotion(self): self.test_board.move_piece(Location.from_string("a2"), Location.from_string("a7")) self.test_board.remove_piece_at_square(Location.from_string("a8")) self.assertEqual( converter.incomplete_alg("a8=Q", color.white, self.test_board), Move( end_loc=Location.from_string("a8"), piece=Pawn(color.white, Location.from_string("e7")), status=notation_const.PROMOTE, promoted_to_piece=Queen, start_loc=Location.from_string("a7") ) )
def test_find_piece(self): self.assertEqual( self.board.find_piece(Rook(color.white, Location(0, 0))), Location(0, 0)) self.assertEqual( self.board.find_piece(Rook(color.black, Location(7, 0))), Location(7, 0)) self.assertNotEqual( self.board.find_piece(Rook(color.black, Location(7, 0))), Location(3, 0)) self.assertEqual( self.board.find_piece(Pawn(color.white, Location(0, 0))), Location.from_string("a2")) self.assertEqual( self.board.find_piece(Knight(color.white, Location(0, 0))), Location.from_string("b1"))
def setUp(self): self.test_board = Board.init_default() self.e_four_move = Move(end_loc=Location.from_string("e4"), piece=Pawn(color.white, Location.from_string("e4")), status=notation_const.MOVEMENT, start_loc=Location.from_string("e2"))