add an ability to change goids amount

This commit is contained in:
Nikolai Rodionov 2022-11-11 22:57:17 +01:00
parent d73f02f0c2
commit cbed5b9e71
2 changed files with 27 additions and 15 deletions

View File

@ -1,6 +1,19 @@
- step: 10
amount: 100
neighbours: 10
- step: 100
amount: 100
neighbours: 50
- step: 200
amount: 150
neighbours: 20
- step: 300
amount: 40
neighbours: 10
- step: 400
amount: 10
neighbours: 5
- step: 500
amount: 1
neighbours: 1

25
main.go
View File

@ -18,11 +18,11 @@ import (
)
// parameters
var windowWidth, windowHeight = 800, 600
var windowWidth, windowHeight = 1000, 700
var goidSize = 3
var goidColor = color.RGBA{200, 200, 100, 255} // gray, 50% transparency
var populationSize = 10
var loops = 10000
var populationSize = 20
var loops = 500
var numNeighbours = 10
var separationFactor = float64(goidSize * 5)
var coherenceFactor = 8
@ -30,16 +30,18 @@ var coherenceFactor = 8
type steps struct {
Step int `yaml:"step"`
Amount int `yaml:"amount"`
NumNeighbours int `yaml:"neighbours"`
}
func fixGoids(goids &[]*Goid, actual int, wished int) {
func fixGoids(gs []*Goid, actual int, wished int) ([]*Goid, int) {
if actual < wished {
g := createRandomGoid()
goids = append(&goids, &g)
gs = append(gs, &g)
return gs, actual + 1
} else if wished < actual {
fmt.Println("it's not supported yet")
return gs[:len(gs)-1], actual -1
} else {
return
return gs, actual
}
}
@ -71,11 +73,9 @@ func main() {
current_stage := 0
for i := 0; i < loops; i++ {
if i < td[current_stage].Step {
fmt.Printf("%d -- %d -- %d", i, current_stage, td[current_stage].Amount )
populationSize = td[current_stage].Amount
} else {
fixGoids(goids, populationSize, td[current_stage].Amount)
goids, populationSize = fixGoids(goids, populationSize, td[current_stage].Amount)
numNeighbours = td[current_stage].NumNeighbours
if i > td[current_stage].Step {
current_stage += 1
}
move(goids, fo)
@ -95,7 +95,6 @@ type Goid struct {
Color color.Color
}
func createRandomGoid() (g Goid) {
g = Goid{
X: rand.Intn(windowWidth),