Mohammad Hasnain Ali
Mohammad Hasnain Ali

Reputation: 21

how to create turtles in a specific area on the patch in Ntelogo

I am making and assignment. The assignment is to make a model of Democracy. I have made a parliament house with coordinates (4, 6). I have made 3 political parties. Now, I want to make the people who will vote. I make them randomly using random-xcor and random-ycor in setxy, but they some of them are made on the parliament house. How can I stop this from happening. I want the turtles to be made everywhere except in the parliament house. Here is the code. Please help me.

breed [people p]
breed [party1 p1]
breed [party2 p2]
breed [party3 p3]

party1-own [vote]
party2-own [vote]
party3-own [vote]

to setup
  clear-all
  setup-patches
  setup-people
  setup-parties
  reset-ticks
end

to setup-patches
  ask patches [
    ifelse pxcor >= 4 and pycor >= 6
    [set pcolor white]
    [set pcolor brown]
  ]
end

to setup-people
    set-default-shape people "person"
    create-people 100
    ask people [setxy random-xcor random-ycor]
end

to setup-parties
   set-default-shape party1 "person"
   set-default-shape party2 "person"
   set-default-shape party3 "person"
   create-party1 1
   create-party2 1
   create-party3 1
   ask party1 [setxy 15 -1]
   ask party2 [setxy 15 -3]
   ask party3 [setxy 15 -5]
   ask party1 [set color blue]
   ask party2 [set color green]
   ask party3 [set color yellow]
end

Upvotes: 0

Views: 1526

Answers (1)

Alan
Alan

Reputation: 9620

to setup-people
  set-default-shape people "person"
  ask n-of 100 (patches with [pcolor != white]) [sprout-people 1]
end

Upvotes: 3

Related Questions