Over the course of mantis shrimp evolution, strategies for protecting ones cavity evolved through natural selection. Sometime in the evolutionary past, N. bredini did not have such sophisticated cavity defense strategies. However, some individuals happened to carry genes that generated behaviors that helped them protect their cavities and survive to reproduce. These individuals had more offspring than those without the handy genetic variation, and the good cavity defenders passed their genes for cavity defense on to their offspring. In this way, genes for good cavity defense spread through the population. After that, any small genetic variants that arose through mutation and happened to help with cavity defense spread in the same way. Hence, natural selection acted on the behavior of mantis shrimp, leading to a variety of behavioral strategies for avoiding injury and defending one’s cavity.
Mantis shrimp with genes for cavity defense are more likely to survive and reproduce. Over generations, the genes for cavity defense spread through the population.
Of course, as defensive strategies evolved, so did offensive strategies — behaviors or other adaptations that would help an intruder take over a cavity. Any offensive strategies good enough to overcome the defense strategies would also be favored by natural selection and would likewise spread through the population. But these offensive strategies would have to be sophisticated: simply ignoring threats from cavity defenders is dangerous because if the defender is not bluffing, the intruder may be killed. Over the course of the lineage’s evolution, offensive and defensive strategies continued to escalate as mantis shrimp struggled to hold on to and acquire safe homes.