Move to the opposite location of a detected turtle - netlogo

I have an agent mouse and an agent cat.
When a mouse detects the presence of a cat around him, I want the mouse to rotate to the opposite positions where it detected the cat.

You can make one agent face another with face. You can then make the agent turn around with rt 180. The result will be that they're facing exactly away from the other agent!

When you have the option of multiple cats there might be a problem when running away from just one of them...
In that case you might want to make some weighted new direction, depending on the cats in the surroundings. But then your definition of the 'empty directions' and possible problems with multiple groups of cats coming in from different directions...
alternatively, you just move-to one-of neighbors with [count cats-here == 0]
(which will probably cause a run-time error if all neighbors harbour a cat.. :-)

Related

Turtle Movement Netlogo

I have a network of turltes that each share two links. At the start of each turn the turtles decide to cooperate or defect, which updates a beta distribution of likelihood of cooperation in the next tick. If the turtles fail to cooperate over n turns they no longer interact. Through this I am able to create clusters in the cooperation network.
Right now, I am trying to figure out how to make the turtles move closer together proportional to the weight of their ties. Is there code to do this? I have only been able to find example code for patches.
I think this model might have something similar to what you want:
http://modelingcommons.org/browse/one_model/3632#model_tabs_browse_procedures

How do I make linked turtles move together in NetLogo?

I'm trying to model fish movement and need them to form schools when there is more than 1 of the breed in a given patch. So far I have managed to get them to form links when they encounter each other with the function below, but then they continue moving independently. I'd also like to re-scale the color of turtles in a linked group so that the more turtles in the group the darker the color is (I'm guessing this is similar to the way you make contour maps according to environmental gradients but I haven't figured it out yet).
Any assistance is always appreciated!
to form_link
if count breed_1-here > 1
[
ask breed_1
[create-links-with other breed_1-here]]
end
If linking isn't the way to get them to move together, I'm fine with another method.

netlogo turtles moving on coordinates

I created turtles called "birds" that shall move on a specific route. The route is made out of links between turtles I called "rasts". As I couldn't find a way to make the turtles move from the first rast to the second, third, fourth and fifth, I changed the rasts an created them as patches.
So, now I have patches in red (rests).
How do I get the birds moving to exactly these patches and, when they are at the patch, how do I make them go to the next one?
I have no code at the moment, because I always hope to find the fault in my first model (see my other questions).
Is there anybody who knows how to solve my problem?
the move-to command moves your turtle to any other turtle or patch you specify. You can also use the face and forward commands to gradually move along a route (see the 'Move Towards Target' code example in the Models Library that comes with NetLogo)

Is this an acceptable algorithm for pedestrian motion that searches and mingles with "buddies" on its path to the goal?

I'll put my pseudocode here first, please advise regarding its validity according to real-world pedestrian motion, and how I can improve it.
Premise: A turtle walk from its spawn point to the goal. On the way, it meets other turtles. Turtles of the same color will be treated as a "buddy" and will go near it, simulating a "friends-walking-down-the-street" scenario. Turtles of the same color with nearer distance has higher priority, e.g. friend A is nearer than friend B so I will approach friend A first.
Upon approaching the goal, the turtle goes back to its spawn point.
Pseudocode:
determine if i am already in the goal
if yes,
determine if there are patches I can walk on
set eyes on nearest patch I can walk on (for the goal path)
if there is a friend nearby, approach friend
if there is no friend nearby, continue walking the goal path
if im already in the goal, respawn.
Advise for improvement please?
The premise doesn't say anything about how returning to spawn point occurs so I will assume it is a one step action (ie you are not interested in those details). I see something more along the lines of
spawn loop:
spawn
goal loop:
determine if turtle already reached goal
if no,
determine if there are patches I can walk on
set eyes on nearest patch I can walk on (for the goal path)
if there is a friend nearby, approach friend
if there is no friend nearby, continue walking the goal path
if yes,
setup so can respawn (return to spawn loc, etc)
goal loop ends

What is the difference between face and towards?

I have used face in NetLogo without any problems, but isn't towards just the same? (in the context of an agent facing towards the direction of a patch/agent)
towards
towards agent
Reports the heading from this agent to the given agent.
If wrapping is allowed by the topology and the wrapped distance (around the edges of the world) is shorter, towards will use the wrapped path.
Note: asking for the heading from an agent to itself, or an agent on the same location, will cause a runtime error.
set heading towards turtle 1
;; same as "face turtle 1"
See also face.
Is there any scenario in which using set towards heading is better than using face?
towards only reports the heading
face is like towards and set heading combined into one.
Are there circumstances in which you would like to know the heading towards something without actually turning to face it? I'm sure you could think of many. One example situation would be choosing between two possible headings according to some criteria.
Let's say you want to face one of two agents, whichever one requires you to turn the least amount:
let first-heading towards first-agent
let second-heading towards second-agent
; compare my current heading to the two calculated headings:
let first-angle subtract-headings heading first-heading
let second-angle subtract-headings heading second-heading
if-else abs first-angle < abs second-angle
[ rt first-angle ]
[ rt second-angle ]
(In real life, you would probably do things a bit differently, but I hope this carries the point across.)