add an ability to change goids amount
This commit is contained in:
		
							
								
								
									
										13
									
								
								config.yaml
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								config.yaml
									
									
									
									
									
								
							@@ -1,6 +1,19 @@
 | 
				
			|||||||
 | 
					- step: 10
 | 
				
			||||||
 | 
					  amount: 100
 | 
				
			||||||
 | 
					  neighbours: 10
 | 
				
			||||||
- step: 100
 | 
					- step: 100
 | 
				
			||||||
  amount: 100
 | 
					  amount: 100
 | 
				
			||||||
 | 
					  neighbours: 50
 | 
				
			||||||
- step: 200
 | 
					- step: 200
 | 
				
			||||||
  amount: 150
 | 
					  amount: 150
 | 
				
			||||||
 | 
					  neighbours: 20
 | 
				
			||||||
- step: 300
 | 
					- step: 300
 | 
				
			||||||
  amount: 40
 | 
					  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
 | 
					// parameters
 | 
				
			||||||
var windowWidth, windowHeight = 800, 600
 | 
					var windowWidth, windowHeight = 1000, 700
 | 
				
			||||||
var goidSize = 3
 | 
					var goidSize = 3
 | 
				
			||||||
var goidColor = color.RGBA{200, 200, 100, 255} // gray, 50% transparency
 | 
					var goidColor = color.RGBA{200, 200, 100, 255} // gray, 50% transparency
 | 
				
			||||||
var populationSize = 10
 | 
					var populationSize = 20
 | 
				
			||||||
var loops = 10000
 | 
					var loops = 500
 | 
				
			||||||
var numNeighbours = 10
 | 
					var numNeighbours = 10
 | 
				
			||||||
var separationFactor = float64(goidSize * 5)
 | 
					var separationFactor = float64(goidSize * 5)
 | 
				
			||||||
var coherenceFactor = 8
 | 
					var coherenceFactor = 8
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type steps struct {
 | 
					type steps struct {
 | 
				
			||||||
	Step int `yaml:"step"` 
 | 
						Step   int `yaml:"step"`
 | 
				
			||||||
	Amount int `yaml:"amount"`
 | 
						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 {
 | 
						if actual < wished {
 | 
				
			||||||
		g := createRandomGoid()
 | 
							g := createRandomGoid()
 | 
				
			||||||
		goids = append(&goids, &g)
 | 
							gs = append(gs, &g)
 | 
				
			||||||
 | 
							return gs, actual + 1
 | 
				
			||||||
	} else if wished < actual {
 | 
						} else if wished < actual {
 | 
				
			||||||
    fmt.Println("it's not supported yet")
 | 
							return gs[:len(gs)-1], actual -1
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
		return
 | 
							return gs, actual
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -48,7 +50,7 @@ func main() {
 | 
				
			|||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		panic(err)
 | 
							panic(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
  conf, err := ioutil.ReadFile("config.yaml")
 | 
						conf, err := ioutil.ReadFile("config.yaml")
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		panic(err)
 | 
							panic(err)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@@ -71,11 +73,9 @@ func main() {
 | 
				
			|||||||
	current_stage := 0
 | 
						current_stage := 0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for i := 0; i < loops; i++ {
 | 
						for i := 0; i < loops; i++ {
 | 
				
			||||||
		if i < td[current_stage].Step {
 | 
							goids, populationSize = fixGoids(goids, populationSize, td[current_stage].Amount)
 | 
				
			||||||
			fmt.Printf("%d -- %d -- %d", i, current_stage, td[current_stage].Amount )
 | 
							numNeighbours = td[current_stage].NumNeighbours
 | 
				
			||||||
			populationSize = td[current_stage].Amount
 | 
							if i > td[current_stage].Step {
 | 
				
			||||||
		} else {
 | 
					 | 
				
			||||||
			fixGoids(goids, populationSize, td[current_stage].Amount)
 | 
					 | 
				
			||||||
			current_stage += 1
 | 
								current_stage += 1
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		move(goids, fo)
 | 
							move(goids, fo)
 | 
				
			||||||
@@ -95,7 +95,6 @@ type Goid struct {
 | 
				
			|||||||
	Color color.Color
 | 
						Color color.Color
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
func createRandomGoid() (g Goid) {
 | 
					func createRandomGoid() (g Goid) {
 | 
				
			||||||
	g = Goid{
 | 
						g = Goid{
 | 
				
			||||||
		X:     rand.Intn(windowWidth),
 | 
							X:     rand.Intn(windowWidth),
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user