backspaces / agentscript

An Agent Based Modeling system (ABM)
http://backspaces.github.io/agentscript/
GNU General Public License v3.0
107 stars 14 forks source link

World wrap "edge cases" #43

Closed bennlich closed 3 years ago

bennlich commented 3 years ago

As I was working on an agentscript model based on netlogo's slime, I noticed that the patchAhead functions do not wrap, so you have to write code like:

if (!patchRight) {
    turtle.left(90)
} else if (!patchLeft) {
    turtle.right(90)
}

Or, from AntsModel:

if (p.isOnEdge()) {
    t.rotate(180)
}

I think it would make life easier for new modelers if they didn't have to think about that.

I also noticed that patches.diffuse() does not wrap either. I think it would be more correct if it did (if the world wraps sometimes, it should wrap all the time).

My 6th sense tells me this is a conversation that happened long ago and I am arriving late... I hope it's not a can o' worms :-P

Model pebble:

TutorialModel 2021-04-26T23_41_19 102Z

backspaces commented 3 years ago

This is due to our deciding early on not to have a torus geometry.

NetLogo sez:

patch-at-heading-and-distance reports the single patch that is the given distance from this turtle or patch, along the given absolute heading. (In contrast to patch-left-and-ahead and patch-right-and-ahead, this turtle's current heading is not taken into account.) Reports nobody if the patch does not exist because it is outside the world.

And:

patch-left-and-ahead angle distance patch-right-and-ahead angle distance Reports the single patch that is the given distance from this turtle, in the direction turned left or right the given angle (in degrees) from the turtle's current heading. Reports nobody if the patch does not exist because it is outside the world.

For turtles, there is an edge handler which will wrap, bounce, clamp or simply take a modeler provided function.

Maybe we could somehow use the same approach for patches? It would be non-trivial tho.

backspaces commented 3 years ago

I'm closing this, the api seems reasonable if netlogo feels that wrapping etc is not the right solution. Turtles have that behavior, however, and could be used instead.