How biologically active matters survive adaptively in complex and changeable environments is a common concern of scientists. Genetics, evolution and natural selection are vital factors in the process of biological evolution and are also the key to survival in harsh environments. However, it is challenging to intuitively and accurately reproduce such long-term adaptive survival processes in the laboratory. Although simulation experiments are intuitive and efficient, they lack fidelity. Therefore, we propose to use swarm robots to study the adaptive process of active matter swarms to complex and changeable environments. Based on a self-built virtual environmental platform and a robot swarm that can interact with the environment, we introduce the concept of genes into the robot system, giving each robot unique digital genes, and design robot breeding methods and rules for gene mutations. Our previous work[1] has demonstrated the effectiveness of this system. In this work, by analyzing the relationship between the genetic traits of the population and the characteristics of environmental resources, and comparing different experimental conditions, we verified in both robot experiments and corresponding simulation experiments that agents with genetic inheritance can survive for a long time under the action of natural selection in periodically changing environments. We also confirmed that in the robot system, both breeding and mutation are essential factors. These findings can help answer the practical scientific question of how individuals and swarms can successfully adapt to complex, dynamic, and unpredictable actual environments.