// Move implements agent Mover interface method for ColourPolymorphicPrey: // updates the agent's position according to its direction (heading) and // velocity (speed*acceleration) if it doesn't encounter any errors. func (c *ColourPolymorphicPrey) Move() error { var posOffset, newPos geometry.Vector var err error posOffset, err = geometry.VecScalarMultiply(c.dir, c.movS*c.movA) if err != nil { return errors.New("agent move failed: " + err.Error()) } newPos, err = geometry.VecAddition(c.pos, posOffset) if err != nil { return errors.New("agent move failed: " + err.Error()) } newPos[x] = calc.WrapFloatIn(newPos[x], -1.0, 1.0) newPos[y] = calc.WrapFloatIn(newPos[y], -1.0, 1.0) c.pos = newPos return nil }
// Move updates the agent's position if it doesn't encounter any errors. func (vp *VisualPredator) Move() error { var posOffset, newPos geometry.Vector var err error posOffset, err = geometry.VecScalarMultiply(vp.dir, vp.movS*vp.movA) if err != nil { return errors.New("agent move failed: " + err.Error()) } newPos, err = geometry.VecAddition(vp.pos, posOffset) if err != nil { return errors.New("agent move failed: " + err.Error()) } newPos[x] = calc.WrapFloatIn(newPos[x], -1.0, 1.0) newPos[y] = calc.WrapFloatIn(newPos[y], -1.0, 1.0) vp.pos = newPos return nil }