add an ability to change goids amount
This commit is contained in:
parent
d73f02f0c2
commit
cbed5b9e71
13
config.yaml
13
config.yaml
@ -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
|
||||
|
||||
|
29
main.go
29
main.go
@ -18,28 +18,30 @@ 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
|
||||
|
||||
type steps struct {
|
||||
Step int `yaml:"step"`
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,7 +50,7 @@ func main() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
conf, err := ioutil.ReadFile("config.yaml")
|
||||
conf, err := ioutil.ReadFile("config.yaml")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
@ -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),
|
||||
|
Loading…
Reference in New Issue
Block a user