// genesis -- tutorial 8 -- batch.g // batch.g: run the 8 queens problem in batch mode to get // as many solutions as possible automatically. // Count the number of active cells at the end of the simulation. float thresh = -0.065 // threshold for considering a cell "active" function count_active_cells int i, count = 0 for (i = 0; i < 64; i = i + 1) if ({getfield /avg/RC[{i}] state} > {thresh}) count = count + 1 end end return {count} end function print_solution int i for (i = 0; i < 64; i = i + 1) echo {{getfield /avg/RC[{i}] state} > {thresh}} -n if (((i + 1) % 8) == 0) echo // this prints a blank line end end end function save_solution(filename, seed) str filename int seed, i openfile {filename} w writefile {filename} Seed: {seed} for (i = 0; i < 64; i = i + 1) writefile {filename} {{getfield /avg/RC[{i}] state} > {thresh}} " " -n if (((i + 1) % 8) == 0) writefile {filename} // this writes a blank line to the file end end closefile {filename} end function save_counts(filename, seed, count) str filename int seed, count openfile {filename} a writefile {filename} Seed: {seed} " " count: {count} closefile {filename} end function run_batch int solutioncount = 0 int count str filename int seed = 0 while (solutioncount < 100) randseed {seed} echo seed: {seed} reset step 0.5 -t int count = {count_active_cells} echo count = {count} save_counts "results.counts" {seed} {count} if (count == 8) str filename = "solution." @ {solutioncount} print_solution save_solution {filename} {seed} solutioncount = solutioncount + 1 end seed = seed + 1 end end