Пример #1
0
	def test_castling_forbidden_rook_moved(self):
		'''Test that castling is forbidden once the rook moved.'''
		board = Board(10, 10)
		king = King(board.white)
		rook_l = Rook(board.white)
		rook_r = Rook(board.white)

		board[0, 7].piece = rook_l
		board[7, 7].piece = rook_r
		board[4, 7].piece = king

		moves = king.get_moves((4, 7), board)
		self.assertTrue(Castling("left",board.white) in moves)
		self.assertTrue(Castling("right",board.white) in moves)

		move = Move((0,7),(1,7))
		self.assertTrue(move in rook_l.get_moves((0,7),board))
		move.perform(board)

		moves = king.get_moves((4, 7), board)
		self.assertFalse(Castling("left",board.white) in moves)
		self.assertTrue(Castling("right",board.white) in moves)

		move = Move((7,7),(6,7))
		self.assertTrue(move in rook_r.get_moves((7,7),board))
		move.perform(board)

		moves = king.get_moves((4, 7), board)
		self.assertFalse(Castling("left",board.white) in moves)
		self.assertFalse(Castling("right",board.white) in moves)
Пример #2
0
	def test_castling_permitted_after_undo(self):
		board = Board(10, 10)
		king = King(board.white)
		rook_l = Rook(board.white)
		rook_r = Rook(board.white)

		board[0, 7].piece = rook_l
		board[7, 7].piece = rook_r
		board[4, 7].piece = king

		moves = king.get_moves((4, 7), board)
		self.assertTrue(Castling("left",board.white) in moves)
		self.assertTrue(Castling("right",board.white) in moves)

		move = Move((0,7),(1,7))
		self.assertTrue(move in rook_l.get_moves((0,7),board))
		move.perform(board)
		move.undo(board)

		moves = king.get_moves((4, 7), board)
		self.assertTrue(Castling("left",board.white) in moves)
		self.assertTrue(Castling("right",board.white) in moves)