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) }
// 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) } } }