The optimization of the spatial layout of the garden is the key to the garden design. This paper draws on the smooth organization of the dynamic line and the reasonable arrangement of the area of the Suzhou Garden and designs an optimization algorithm based on the genetic algorithm for the layout of the garden. The two optimization objectives of “function” and “dynamic line” are proposed, and genetic algorithm optimization of garden layout is carried out by defining spatial connectivity and accessibility fitness function, integer crossover, and gene exchange. Case analysis shows that the optimization time of the genetic algorithm is much lower than that of the stochastic optimization algorithm; the average connection value and depth value are 1.925 and 0.737, respectively, and the investigation score is close to the professional design scheme. It shows that the application of genetic algorithms to optimize the garden layout has the advantages of being less time-consuming, having a reasonable spatial layout, and being highly professional.