Netlogo: [CODE] Asking patches directly behind you to change colourNETLOGO: Storing and using the value of a variable in the last 3 ticksasking red turtles to avoid other turtles and move to one of its neighbor which is empty and has highest concunable to make non-stationary turtles change their direction if an obstacle a patch aheadNetLogo: avoid to have too many beetles on one patch in one time step?Changing patch colors except one colorHow to ask turtles to avoid a patch with specific color at patch-ahead 1 but turtles move forward by bigger number (not fd 1) in one step in NetLogoHow to check if any turtle ahead “in a same patch” not in a patch aheadNetLogo: How to make a turtle recognise any shade of one color?How to limit number of turtles in a patch in NetLogoNetlogo: Creating a square area of patches in the center of the gridSnake game: How to increase the length of a snake body based on the amount of food eaten?
What should I do with the stock I own if I anticipate there will be a recession?
Have made several mistakes during the course of my PhD. Can't help but feel resentment. Can I get some advice about how to move forward?
Is a suspension needed to do wheelies?
Get the full text of a long request
Is the Microsoft recommendation to use C# properties applicable to game development?
Unconventional examples of mathematical modelling
How should you gracefully leave a company you helped start?
How to train a replacement without them knowing?
Output the list of musical notes
If a person claims to know anything could it be disproven by saying 'prove that we are not in a simulation'?
Units of measurement, especially length, when body parts vary in size among races
Did Michelle Obama have a staff of 23; and Melania have a staff of 4?
Gofer work in exchange for LoR
Why is the battery jumpered to a resistor in this schematic?
Why does "auf der Strecke bleiben" mean "to fall by the wayside"?
Unsolved Problems due to Lack of Computational Power
Trying to understand how Digital Certificates and CA are indeed secure
May the tower use the runway while an emergency aircraft is inbound?
Why do so many people play out of turn on the last lead?
What exactly happened to the 18 crew members who were reported as "missing" in "Q Who"?
Does Medium Armor's Max dex also put a cap on the negative side?
What would be synonyms for "be into something"?
Meaning and structure of headline "Hair it is: A List of ..."
What would cause a nuclear power plant to break down after 2000 years, but not sooner?
Netlogo: [CODE] Asking patches directly behind you to change colour
NETLOGO: Storing and using the value of a variable in the last 3 ticksasking red turtles to avoid other turtles and move to one of its neighbor which is empty and has highest concunable to make non-stationary turtles change their direction if an obstacle a patch aheadNetLogo: avoid to have too many beetles on one patch in one time step?Changing patch colors except one colorHow to ask turtles to avoid a patch with specific color at patch-ahead 1 but turtles move forward by bigger number (not fd 1) in one step in NetLogoHow to check if any turtle ahead “in a same patch” not in a patch aheadNetLogo: How to make a turtle recognise any shade of one color?How to limit number of turtles in a patch in NetLogoNetlogo: Creating a square area of patches in the center of the gridSnake game: How to increase the length of a snake body based on the amount of food eaten?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I am trying to create a game and what I want to do is make the patch behind the turtle to change its color as soon as the turtle eats a fruit. So the turtle moves and eats fruits. Upon eating one fruit, the patch behind the one it is on will change color but this color will move with the turtle so as to create the effect of an increasing length/size of the turtle
Now, I have tried working with the code:
ask turtles
[ if score = 10
[ ask patch-ahead -1
[ set pcolor yellow
]
]
]
The problem with this is that as the turtle keeps on moving, the whole path gets coloured yellow instead of the patch that is right behind its current location. Is there any code to get around this problem? Also, as it eats another fruit, I want the two patches behind it with the colour yellow. So how do I code this?
netlogo agent-based-modeling
add a comment |
I am trying to create a game and what I want to do is make the patch behind the turtle to change its color as soon as the turtle eats a fruit. So the turtle moves and eats fruits. Upon eating one fruit, the patch behind the one it is on will change color but this color will move with the turtle so as to create the effect of an increasing length/size of the turtle
Now, I have tried working with the code:
ask turtles
[ if score = 10
[ ask patch-ahead -1
[ set pcolor yellow
]
]
]
The problem with this is that as the turtle keeps on moving, the whole path gets coloured yellow instead of the patch that is right behind its current location. Is there any code to get around this problem? Also, as it eats another fruit, I want the two patches behind it with the colour yellow. So how do I code this?
netlogo agent-based-modeling
Please provide minimal reproducible code snippet for others to look at so that one can help.
– nircraft
Mar 27 at 14:20
1
So you want the trail to move with the turtle? That is, the patch changes back to its original colour as the turtle moves away rather than showing where the turtle has been?
– JenB
Mar 28 at 0:27
Yes! That's what I want. So if the turtle has eaten one fruit it will have a trail of length 1 which will move with it and that trail will be the patch behind it in colour yellow. Can you please help? Thank you!
– A.Asad
Mar 28 at 6:54
add a comment |
I am trying to create a game and what I want to do is make the patch behind the turtle to change its color as soon as the turtle eats a fruit. So the turtle moves and eats fruits. Upon eating one fruit, the patch behind the one it is on will change color but this color will move with the turtle so as to create the effect of an increasing length/size of the turtle
Now, I have tried working with the code:
ask turtles
[ if score = 10
[ ask patch-ahead -1
[ set pcolor yellow
]
]
]
The problem with this is that as the turtle keeps on moving, the whole path gets coloured yellow instead of the patch that is right behind its current location. Is there any code to get around this problem? Also, as it eats another fruit, I want the two patches behind it with the colour yellow. So how do I code this?
netlogo agent-based-modeling
I am trying to create a game and what I want to do is make the patch behind the turtle to change its color as soon as the turtle eats a fruit. So the turtle moves and eats fruits. Upon eating one fruit, the patch behind the one it is on will change color but this color will move with the turtle so as to create the effect of an increasing length/size of the turtle
Now, I have tried working with the code:
ask turtles
[ if score = 10
[ ask patch-ahead -1
[ set pcolor yellow
]
]
]
The problem with this is that as the turtle keeps on moving, the whole path gets coloured yellow instead of the patch that is right behind its current location. Is there any code to get around this problem? Also, as it eats another fruit, I want the two patches behind it with the colour yellow. So how do I code this?
netlogo agent-based-modeling
netlogo agent-based-modeling
edited Mar 28 at 0:25
JenB
10k1 gold badge11 silver badges37 bronze badges
10k1 gold badge11 silver badges37 bronze badges
asked Mar 27 at 12:58
A.AsadA.Asad
1113 bronze badges
1113 bronze badges
Please provide minimal reproducible code snippet for others to look at so that one can help.
– nircraft
Mar 27 at 14:20
1
So you want the trail to move with the turtle? That is, the patch changes back to its original colour as the turtle moves away rather than showing where the turtle has been?
– JenB
Mar 28 at 0:27
Yes! That's what I want. So if the turtle has eaten one fruit it will have a trail of length 1 which will move with it and that trail will be the patch behind it in colour yellow. Can you please help? Thank you!
– A.Asad
Mar 28 at 6:54
add a comment |
Please provide minimal reproducible code snippet for others to look at so that one can help.
– nircraft
Mar 27 at 14:20
1
So you want the trail to move with the turtle? That is, the patch changes back to its original colour as the turtle moves away rather than showing where the turtle has been?
– JenB
Mar 28 at 0:27
Yes! That's what I want. So if the turtle has eaten one fruit it will have a trail of length 1 which will move with it and that trail will be the patch behind it in colour yellow. Can you please help? Thank you!
– A.Asad
Mar 28 at 6:54
Please provide minimal reproducible code snippet for others to look at so that one can help.
– nircraft
Mar 27 at 14:20
Please provide minimal reproducible code snippet for others to look at so that one can help.
– nircraft
Mar 27 at 14:20
1
1
So you want the trail to move with the turtle? That is, the patch changes back to its original colour as the turtle moves away rather than showing where the turtle has been?
– JenB
Mar 28 at 0:27
So you want the trail to move with the turtle? That is, the patch changes back to its original colour as the turtle moves away rather than showing where the turtle has been?
– JenB
Mar 28 at 0:27
Yes! That's what I want. So if the turtle has eaten one fruit it will have a trail of length 1 which will move with it and that trail will be the patch behind it in colour yellow. Can you please help? Thank you!
– A.Asad
Mar 28 at 6:54
Yes! That's what I want. So if the turtle has eaten one fruit it will have a trail of length 1 which will move with it and that trail will be the patch behind it in colour yellow. Can you please help? Thank you!
– A.Asad
Mar 28 at 6:54
add a comment |
1 Answer
1
active
oldest
votes
So are you after a game like Snake? You could give the patches a memory variable so they can track how long it has been since the turtle passed over them. If this memory value is modified by the current 'size' of the snake body (based on how many fruit it has consumed) you can have the patches stay colored for longer. Below is a simple version (without controls, the snake just has random movement):
patches-own [ mem ]
breed [ snakes snake ]
breed [ fruits fruit ]
snakes-own [ tail-len ]
to setup
ca
create-snakes 1 [
set color white
set tail-len 1
face one-of neighbors4
ask patch-here [
set pcolor [pcolor] of myself
]
]
create-fruits 30 [
move-to one-of patches
set shape "flower"
]
reset-ticks
end
to go
ask snakes [
if random-float 1 < 0.05 [
rt one-of [ 90 -90 ]
]
if [ pcolor ] of patch-ahead 1 = white [
stamp
die
]
move-to patch-ahead 1
ask patch-ahead -1 [
set pcolor [color] of myself
set mem [tail-len] of myself + 1
]
if any? fruits-here [
ask fruits-here [ die ]
set tail-len tail-len + 1
]
]
if not any? snakes [
print "The snake tried to eat itself."
stop
]
ask patches with [ mem > 0 ] [
set mem mem - 1
if mem = 0 [
set pcolor black
]
]
tick
end
Thank you so much!! I figured my way around this :). Can you please please help me with this? stackoverflow.com/q/55652441/11265312 I'd really appreciate it if you could!
– A.Asad
Apr 12 at 13:18
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55377809%2fnetlogo-code-asking-patches-directly-behind-you-to-change-colour%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
So are you after a game like Snake? You could give the patches a memory variable so they can track how long it has been since the turtle passed over them. If this memory value is modified by the current 'size' of the snake body (based on how many fruit it has consumed) you can have the patches stay colored for longer. Below is a simple version (without controls, the snake just has random movement):
patches-own [ mem ]
breed [ snakes snake ]
breed [ fruits fruit ]
snakes-own [ tail-len ]
to setup
ca
create-snakes 1 [
set color white
set tail-len 1
face one-of neighbors4
ask patch-here [
set pcolor [pcolor] of myself
]
]
create-fruits 30 [
move-to one-of patches
set shape "flower"
]
reset-ticks
end
to go
ask snakes [
if random-float 1 < 0.05 [
rt one-of [ 90 -90 ]
]
if [ pcolor ] of patch-ahead 1 = white [
stamp
die
]
move-to patch-ahead 1
ask patch-ahead -1 [
set pcolor [color] of myself
set mem [tail-len] of myself + 1
]
if any? fruits-here [
ask fruits-here [ die ]
set tail-len tail-len + 1
]
]
if not any? snakes [
print "The snake tried to eat itself."
stop
]
ask patches with [ mem > 0 ] [
set mem mem - 1
if mem = 0 [
set pcolor black
]
]
tick
end
Thank you so much!! I figured my way around this :). Can you please please help me with this? stackoverflow.com/q/55652441/11265312 I'd really appreciate it if you could!
– A.Asad
Apr 12 at 13:18
add a comment |
So are you after a game like Snake? You could give the patches a memory variable so they can track how long it has been since the turtle passed over them. If this memory value is modified by the current 'size' of the snake body (based on how many fruit it has consumed) you can have the patches stay colored for longer. Below is a simple version (without controls, the snake just has random movement):
patches-own [ mem ]
breed [ snakes snake ]
breed [ fruits fruit ]
snakes-own [ tail-len ]
to setup
ca
create-snakes 1 [
set color white
set tail-len 1
face one-of neighbors4
ask patch-here [
set pcolor [pcolor] of myself
]
]
create-fruits 30 [
move-to one-of patches
set shape "flower"
]
reset-ticks
end
to go
ask snakes [
if random-float 1 < 0.05 [
rt one-of [ 90 -90 ]
]
if [ pcolor ] of patch-ahead 1 = white [
stamp
die
]
move-to patch-ahead 1
ask patch-ahead -1 [
set pcolor [color] of myself
set mem [tail-len] of myself + 1
]
if any? fruits-here [
ask fruits-here [ die ]
set tail-len tail-len + 1
]
]
if not any? snakes [
print "The snake tried to eat itself."
stop
]
ask patches with [ mem > 0 ] [
set mem mem - 1
if mem = 0 [
set pcolor black
]
]
tick
end
Thank you so much!! I figured my way around this :). Can you please please help me with this? stackoverflow.com/q/55652441/11265312 I'd really appreciate it if you could!
– A.Asad
Apr 12 at 13:18
add a comment |
So are you after a game like Snake? You could give the patches a memory variable so they can track how long it has been since the turtle passed over them. If this memory value is modified by the current 'size' of the snake body (based on how many fruit it has consumed) you can have the patches stay colored for longer. Below is a simple version (without controls, the snake just has random movement):
patches-own [ mem ]
breed [ snakes snake ]
breed [ fruits fruit ]
snakes-own [ tail-len ]
to setup
ca
create-snakes 1 [
set color white
set tail-len 1
face one-of neighbors4
ask patch-here [
set pcolor [pcolor] of myself
]
]
create-fruits 30 [
move-to one-of patches
set shape "flower"
]
reset-ticks
end
to go
ask snakes [
if random-float 1 < 0.05 [
rt one-of [ 90 -90 ]
]
if [ pcolor ] of patch-ahead 1 = white [
stamp
die
]
move-to patch-ahead 1
ask patch-ahead -1 [
set pcolor [color] of myself
set mem [tail-len] of myself + 1
]
if any? fruits-here [
ask fruits-here [ die ]
set tail-len tail-len + 1
]
]
if not any? snakes [
print "The snake tried to eat itself."
stop
]
ask patches with [ mem > 0 ] [
set mem mem - 1
if mem = 0 [
set pcolor black
]
]
tick
end
So are you after a game like Snake? You could give the patches a memory variable so they can track how long it has been since the turtle passed over them. If this memory value is modified by the current 'size' of the snake body (based on how many fruit it has consumed) you can have the patches stay colored for longer. Below is a simple version (without controls, the snake just has random movement):
patches-own [ mem ]
breed [ snakes snake ]
breed [ fruits fruit ]
snakes-own [ tail-len ]
to setup
ca
create-snakes 1 [
set color white
set tail-len 1
face one-of neighbors4
ask patch-here [
set pcolor [pcolor] of myself
]
]
create-fruits 30 [
move-to one-of patches
set shape "flower"
]
reset-ticks
end
to go
ask snakes [
if random-float 1 < 0.05 [
rt one-of [ 90 -90 ]
]
if [ pcolor ] of patch-ahead 1 = white [
stamp
die
]
move-to patch-ahead 1
ask patch-ahead -1 [
set pcolor [color] of myself
set mem [tail-len] of myself + 1
]
if any? fruits-here [
ask fruits-here [ die ]
set tail-len tail-len + 1
]
]
if not any? snakes [
print "The snake tried to eat itself."
stop
]
ask patches with [ mem > 0 ] [
set mem mem - 1
if mem = 0 [
set pcolor black
]
]
tick
end
edited Mar 29 at 19:56
answered Mar 29 at 19:48
Luke CLuke C
8,1371 gold badge9 silver badges15 bronze badges
8,1371 gold badge9 silver badges15 bronze badges
Thank you so much!! I figured my way around this :). Can you please please help me with this? stackoverflow.com/q/55652441/11265312 I'd really appreciate it if you could!
– A.Asad
Apr 12 at 13:18
add a comment |
Thank you so much!! I figured my way around this :). Can you please please help me with this? stackoverflow.com/q/55652441/11265312 I'd really appreciate it if you could!
– A.Asad
Apr 12 at 13:18
Thank you so much!! I figured my way around this :). Can you please please help me with this? stackoverflow.com/q/55652441/11265312 I'd really appreciate it if you could!
– A.Asad
Apr 12 at 13:18
Thank you so much!! I figured my way around this :). Can you please please help me with this? stackoverflow.com/q/55652441/11265312 I'd really appreciate it if you could!
– A.Asad
Apr 12 at 13:18
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55377809%2fnetlogo-code-asking-patches-directly-behind-you-to-change-colour%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please provide minimal reproducible code snippet for others to look at so that one can help.
– nircraft
Mar 27 at 14:20
1
So you want the trail to move with the turtle? That is, the patch changes back to its original colour as the turtle moves away rather than showing where the turtle has been?
– JenB
Mar 28 at 0:27
Yes! That's what I want. So if the turtle has eaten one fruit it will have a trail of length 1 which will move with it and that trail will be the patch behind it in colour yellow. Can you please help? Thank you!
– A.Asad
Mar 28 at 6:54