Minify program after hitting score

This commit is contained in:
Ian Gulliver
2021-11-22 21:34:55 -08:00
parent 677561938f
commit 44c6a26f9d
3 changed files with 62 additions and 10 deletions

View File

@@ -1,6 +1,5 @@
package grow
import "math"
import "math/rand"
import "github.com/firestuff/subcoding/gen"
@@ -10,7 +9,7 @@ const instructionsPerFunctionMean = 15
const instrucitonsPerFunctionStdDev = 10
func Mutate(prog *vm.Program) {
target := int(math.Max(2, rand.NormFloat64()*instrucitonsPerFunctionStdDev+instructionsPerFunctionMean))
target := int(rand.NormFloat64()*instrucitonsPerFunctionStdDev+instructionsPerFunctionMean)
if len(prog.Functions[0].Instructions) < target {
addInstruction(prog, prog.Functions[0])