Status channel in Grow()

This commit is contained in:
Ian Gulliver
2021-11-20 20:02:16 -10:00
parent 789e1e7333
commit 68ae25192e
3 changed files with 59 additions and 20 deletions

View File

@@ -6,6 +6,7 @@ import "math/rand"
import "os"
import "time"
import "github.com/firestuff/subcoding/asm"
import "github.com/firestuff/subcoding/grow"
func main() {
@@ -28,8 +29,31 @@ func main() {
log.Fatal(err)
}
_, err = def.Grow()
if err != nil {
log.Fatal(err)
statusChan := make(chan grow.Status)
go func() {
_, err = def.Grow(statusChan)
if err != nil {
log.Fatal(err)
}
}()
for {
status, ok := <-statusChan
if !ok {
break
}
if status.BestProgram == nil {
continue
}
src, err := asm.Disassemble(status.BestProgram)
if err != nil {
log.Fatal(err)
}
log.Printf("New best score %d / %d (after %d attempts):\n%s", status.BestScore, status.TargetScore, status.Attempts, src)
}
}