Ejemplo n.º 1
0
func TestOptimalAttackVectorSort(t *testing.T) {
	rand.Seed(0)
	predator := vpTesterAgent(0.0, 0.0)
	predator.vsr = 1.0
	predator.τ = colour.RGB{Red: 0.71, Green: 0.1, Blue: 0.39}

	prey := []ColourPolymorphicPrey{}

	for i := 1; i <= 10; i++ {
		agentA := cpPreyTesterAgent(calc.RandFloatIn(-1, 1), calc.RandFloatIn(-1, 1))
		agentB := cpPreyTesterAgent(calc.RandFloatIn(-1, 1), calc.RandFloatIn(-1, 1))
		agentA.colouration = colour.RGB{Red: rand.Float64(), Green: rand.Float64(), Blue: rand.Float64()}
		agentB.colouration = colour.RGB{Red: rand.Float64(), Green: rand.Float64(), Blue: rand.Float64()}
		prey = append(prey, agentA)
		prey = append(prey, agentB)
	}

	c := math.Pow(2, 3)
	f := visualSignalStrength(c)
	optimals := []visualRecognition{}
	for i := range prey {
		𝛘 := colour.RGBDistance(predator.τ, prey[i].colouration)
		δ, _ := geometry.VectorDistance(predator.pos, prey[i].pos)
		// fmt.Printf("%v\t%v\t%v\t%p\n", i, 𝛘, δ, &prey[i])
		a := visualRecognition{δ, 𝛘, f, c, &prey[i]}
		optimals = append(optimals, a)
	}
Ejemplo n.º 2
0
// PreySearch – uses Visual Search to try to 'recognise' a nearby prey agent within model Environment to target
func (vp *VisualPredator) PreySearch(prey []ColourPolymorphicPrey) (*ColourPolymorphicPrey, error) {
	c := vp.ετ
	var 𝒇 = visualSignalStrength(c)
	var 𝛘 float64 // colour sorting value - colour distance/difference between vp.imprimt and cpPrey.colouration
	var δ float64 // position sorting value - vector distance between vp.pos and cpPrey.pos
	var err error
	var searchSet []visualRecognition
	for i := range prey { //	exhaustive search 😱
		δ, err = geometry.VectorDistance(vp.pos, prey[i].pos)
		if δ <= vp.vsr { // ∴ only include the prey agent for considertion if within visual range
			𝛘 = colour.RGBDistance(vp.τ, prey[i].colouration)
			if 𝛘 < vp.𝛄 { // i.e. if and only if colour distance falls within predator's current search tolerance
				a := visualRecognition{δ, 𝛘, 𝒇, c, &prey[i]}
				searchSet = append(searchSet, a)
			}
		}
	}
Ejemplo n.º 3
0
func TestCPPComparitorSort(t *testing.T) {
	rand.Seed(0)
	predator := vpTesterAgent(0.0, 0.0)
	predator.vsr = 1.0
	predator.τ = colour.RGB{Red: 0.71, Green: 0.1, Blue: 0.39}

	prey := []ColourPolymorphicPrey{}

	for i := 1; i <= 10; i++ {
		agentA := cpPreyTesterAgent(calc.RandFloatIn(-1, 1), calc.RandFloatIn(-1, 1))
		agentB := cpPreyTesterAgent(calc.RandFloatIn(-1, 1), calc.RandFloatIn(-1, 1))
		agentA.colouration = colour.RGB{Red: rand.Float64(), Green: rand.Float64(), Blue: rand.Float64()}
		agentB.colouration = colour.RGB{Red: rand.Float64(), Green: rand.Float64(), Blue: rand.Float64()}
		prey = append(prey, agentA)
		prey = append(prey, agentB)
	}

	f := func(v geometry.Vector) func(geometry.Vector) float64 {
		return func(u geometry.Vector) float64 {
			dist, _ := geometry.VectorDistance(v, u)
			return dist
		}
	}(predator.pos)

	compers := []compCPP{}

	for i := range prey {
		// fmt.Printf("%v\t%v\t%p\n", i, prey[i].pos, &prey[i])
		a := compCPP{f, &prey[i]}
		compers = append(compers, a)
	}

	sort.Sort(byComparitor(compers))

	// for i := range compers {
	// 	fmt.Printf("%v\t%v\t%p\t%v\n", i, compers[i].pos, compers[i].ColourPolymorphicPrey, f(compers[i].pos))
	// }

	want := fmt.Sprintf("%p", &prey[19])
	got := fmt.Sprintf("%p", &(*compers[0].ColourPolymorphicPrey))

	if want != got {
		t.Errorf("want:\n%q\ngot:\n%q\n", want, got)
	}
}
Ejemplo n.º 4
0
// MateSearch implements Breeder interface method for ColourPolymorphicPrey:
// NEEDS BETTER HANDLING THAN JUST PUSHING THE ERROR UP!
func (c *ColourPolymorphicPrey) MateSearch(pop []ColourPolymorphicPrey, skip int) (mate *ColourPolymorphicPrey, err error) {
	mate = nil
	err = nil
	dist := 0.0
	for i := 0; i < len(pop); i++ {
		if i == skip {
			continue
		}
		dist, err = geometry.VectorDistance(c.pos, pop[i].pos)
		if err != nil {
			return
		}
		if dist <= c.sr {
			mate = &pop[i]
			return
		}
	}
	return
}