OPTION BASE 1 RANDOMIZE TIMER chrompos% = 41 genepos% = 100 DIM malea%(41, 100), maleb%(41, 100), femalea%(41, 100), femaleb%(41, 100) pairgoal% = 2000 DIM birds%(2000) 'What are the most kids needed to pass 100% of genes? mostkids% = 0 'run the simulation on this many pairings FOR paircnt% = 1 TO pairgoal% 'PRINT "paircnt = "; paircnt% 'Mark every gene position before every pairing FOR chrom% = 1 TO chrompos% FOR gene% = 1 TO genepos% malea%(chrom%, gene%) = 1 maleb%(chrom%, gene%) = 1 femalea%(chrom%, gene%) = 1 femaleb%(chrom%, gene%) = 1 NEXT gene% NEXT chrom% 'count number of offspring produced before last gene is passed childcnt% = 0 'unpassedcnt% counts all the unpassed genes unpassedcnt% = 1 'Now, make a child, and watch the genes pass WHILE unpassedcnt% > 0 childcnt% = childcnt% + 1 'PRINT "childcnt = "; childcnt% 'this loop similates one offspring (half the genes) 'loop once per chromosome 'PRINT "chrompos = "; chrompos% FOR chrom% = 1 TO chrompos% 'choose a random crossover point and direction 'first the male, then the female mcrosspoint% = INT(RND * genepos%) + 1 fcrosspoint% = INT(RND * genepos%) + 1 mup% = INT(RND * 2) fup% = INT(RND * 2) 'mark off the male genes selected FOR gene% = 1 TO genepos% IF mup% = 1 THEN IF gene% >= mcrosspoint% THEN malea%(chrom%, gene%) = 0 ELSE maleb%(chrom%, gene%) = 0 END IF ELSE IF gene% >= mcrosspoint% THEN maleb%(chrom%, gene%) = 0 ELSE malea%(chrom%, gene%) = 0 END IF END IF NEXT gene% 'mark off the female genes selected FOR gene% = 1 TO genepos% IF fup% = 1 THEN IF gene% >= fcrosspoint% THEN femalea%(chrom%, gene%) = 0 ELSE femaleb%(chrom%, gene%) = 0 END IF ELSE IF gene% >= fcrosspoint% THEN femaleb%(chrom%, gene%) = 0 ELSE femalea%(chrom%, gene%) = 0 END IF END IF NEXT gene% NEXT chrom% 'count number of units still not selected unpassedcnt% = 0 FOR chrom% = 1 TO chrompos% FOR gene% = 1 TO genepos% unpassedcnt% = unpassedcnt% + malea%(chrom%, gene%) + maleb%(chrom%, gene%) + femalea%(chrom%, gene%) + femaleb%(chrom%, gene%) 'PRINT "unpassedcnt = "; unpassedcnt% NEXT gene% NEXT chrom% 'PRINT "unpassedcnt = "; unpassedcnt% 'FOR chrom% = 1 TO chrompos% 'FOR gene% = 1 TO genepos% 'PRINT RIGHT$(STR$(malea%(chrom%, gene%)), 1); 'NEXT gene% 'PRINT 'NEXT chrom% 'FOR a = 1 TO 500000 'NEXT a WEND 'PRINT 'PRINT "childcnt = "; childcnt% IF mostkids% < childcnt% THEN mostkids% = childcnt% birds%(paircnt%) = childcnt% NEXT paircnt% PRINT "Percents" FOR childcnt% = 5 TO mostkids% percent = 0 FOR paircnt% = 1 TO pairgoal% IF birds%(paircnt%) > childcnt% THEN percent = percent + 1 NEXT paircnt% PRINT childcnt%; " = "; 100 - (percent * (100 / pairgoal%)); CHR$(13); NEXT childcnt% PRINT "max = "; mostkids%