code: def add(self, piece_uid, index):
          
          # Square already occupied by another piece.
          if self.occupancy[index]:
              raise OccupiedPosition
  
          # Square reachable by another piece.
          if self.exposed_territory[index]:
              raise VulnerablePosition
  
          # Create a new instance of the piece.
          klass = PIECE_CLASSES[piece_uid]
          piece = klass(self, index)
  
          # Check if a piece can attack another one from its position.
          territory = piece.territory
          for i in self.indexes:
              if self.occupancy[i] and territory[i]:
                  raise AttackablePiece
  
          # Mark the territory covered by the piece as exposed and secure its
          # position on the board.
          self.pieces.add(piece)
          self.occupancy[index] = True
          self.exposed_territory = list(
              map(or_, self.exposed_territory, territory))
docs: Add a piece to the board at the provided linear position.