In recent days, self-assembling swarm robots have been studied by a number of researchers due to their advantages such as high efficiency, stability, and scalability. However, there are still critical issues in applying them to practical problems in the real world. The main objective of this study is to develop a novel self-assembling swarm robot algorithm that overcomes the limitations of existing approaches. To this end, multitree genetic programming is newly designed to efficiently discover a set of patterns necessary to carry out the mission of the self-assembling swarm robots. The obtained patterns are then incorporated into their corresponding robot modules. The computational experiments prove the effectiveness of the proposed approach.