@@ -482,28 +482,38 @@ function tick(){
482482 _arena [ layer ] [ long ] [ _settings . arena . size - 1 - short ] . toggleApple ( ) ;
483483 _arena [ layer ] [ _settings . arena . size - 1 - short ] [ _settings . arena . size - 1 - long ] . toggleApple ( ) ;
484484 }
485+ if ( Apple . getPlacedApples ( ) . length < 4 ) {
486+ Apple . getPlacedApples ( ) . forEach ( space => {
487+ space . toggleApple ( ) ;
488+ } ) ;
489+ }
485490 break ;
486491 case 'FourRandom_asymmetric' :
487- while ( 0 < retries && Apple . getPlacedApples ( ) . length < 4 ) {
492+ if ( Apple . getPlacedApples ( ) . length < 4 ) {
488493 Apple . getPlacedApples ( ) . forEach ( space => {
489494 space . toggleApple ( ) ;
490495 } ) ;
491496 while ( Apple . getPlacedApples ( ) . length < 4 ) {
492497 let emptySpaces = getEmptySpaces ( ) ;
493- let randomSpace = Math . floor ( Math . random ( ) * emptySpaces . length ) ;
494- emptySpaces [ randomSpace ] . toggleApple ( ) ;
498+ if ( emptySpaces . length ) {
499+ let randomSpace = Math . floor ( Math . random ( ) * emptySpaces . length ) ;
500+ emptySpaces [ randomSpace ] . toggleApple ( ) ;
501+ } else {
502+ break ;
503+ }
495504 }
496505 }
497506 break ;
498507 case 'Single' :
499508 case 'OneRandomPerWorm_asymmetric' :
500509 while ( Apple . getPlacedApples ( ) . length < ( _settings . rules . apples === 'Single' ? 1 : _worms . length ) ) {
501510 let emptySpaces = getEmptySpaces ( ) ;
502- if ( emptySpaces . length === 0 ) {
511+ if ( emptySpaces . length ) {
512+ let randomSpace = Math . floor ( Math . random ( ) * emptySpaces . length ) ;
513+ emptySpaces [ randomSpace ] . toggleApple ( ) ;
514+ } else {
503515 break ;
504516 }
505- let randomSpace = Math . floor ( Math . random ( ) * emptySpaces . length ) ;
506- emptySpaces [ randomSpace ] . toggleApple ( ) ;
507517 }
508518 break ;
509519 }
0 commit comments