Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7568413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:55:11+00:00 2026-05-30T14:55:11+00:00

Imagine i have the same breed of turtle which is positioned like below and

  • 0

Imagine i have the same breed of turtle which is positioned like below and is separated by a empty patch.

1234 56 78 9 <br/>
AAAA AA AA A  

When a random position is generated. Let say position 2 is the target, i want all the agents that are positioned at 1 2 3 4 to die as they are all supposed to be linked together. Similarly 5 and 6 will die if position 5 or 6 is selected.

I tried using links and neighbors but they don’t seem to work. When i tried it, the turtles at position 4 & 3 are the only wants that dies.

Below is the code that i used to link the turtles:

if (any? virus-on neighbors)
[set create-links-with virus-on neighbors [tie]] 

Below is the code that i used to kill the turle:

ask virus-on patch in_xcor in_ycor [
    ask link-neighbors [die]
    die
 ]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:55:13+00:00Added an answer on May 30, 2026 at 2:55 pm

    One thing for sure is that you don’t need to go through the trouble of creating links between the turtles that you are about to kill. Your main problem is to identify which turtles need to die, and this can be accomplished with a recursive procedure: you have a target turtle that needs to die, but you want it to ask its neighbors do the same (and they, in turn, to ask theirs, etc.)

    The process is made slightly more complex by the fact that killing a turtle in the middle of the recursion would mess things up, but you can get around this by using a turtle variable that serves as a flag for marking turtles that need to be killed, and then killing all of those at the end.

    The following code should provide a fully working example:

    turtles-own [ marked-for-death ]
    
    to setup
      clear-all
      ask patch 1 0 [ sprout 1 ]
      ask patch 2 0 [ sprout 1 ]
      ask patch 3 0 [ sprout 1 ]
      ask patch 4 0 [ sprout 1 ]
      ask patch 6 0 [ sprout 1 ]
      ask patch 7 0 [ sprout 1 ]
      ask patch 9 0 [ sprout 1 ]
    end
    
    to go
      ask turtles [ set marked-for-death false ]
      ask turtles-on patch 2 0 [ mark-for-death ]
      ask turtles with [ marked-for-death = true ] [ die ]
    end
    
    to mark-for-death
      set marked-for-death true
      ask (turtles-on neighbors) with [ marked-for-death = false ] [ mark-for-death ]
    end
    

    This example kills the turtle on patch 2 0, and all of those that are linked to it. You will need to adjust it for own purposes but it should be enough to get you going…

    Edit:

    Slightly more elegant version, as it does not require a turtle variable (assuming same setup procedure):

    to go
      let marked [ marked-for-death [] ] of turtles-on patch 2 0
      ask turtle-set marked [ die ]
    end
    
    to-report marked-for-death [ marked ]
      set marked fput self marked 
      ask (turtles-on neighbors) 
        with [ not (member? self marked) ] 
        [ set marked marked-for-death marked ]
      report marked
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

when recoding a set of variables which all have the same format, i'd like
Imagine I have 3 lines of text for example like below: Line 1: This
imagine I have a bunch of C++ related classes (all extending the same base
Can CouchDB handle thousands of separate databases on the same machine? Imagine you have
Imagine I have a table which stores a series of sparse vectors. A sparse
Imagine you have one page app using Javascript MVC, which should switch between sub-apps
I have several hosts from which i want to do the same query. So
Lets imagine I have the same database schema as here: http://www.databaseanswers.org/data_models/driving_school/index.htm If a customer
Let's imagine I have two threads which execute some database-oriented code in thread-specific TransactionScopes
Imagine I have the following 'partial' which is generated through a bunch of views:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.