Bob the Sheepherder

Bob the Sheepherder preview image

1 collaborator

Default-person Tanya Harris (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.3.1 • Viewed 301 times • Downloaded 22 times • Run 0 times
Download the 'Bob the Sheepherder' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

breed [sheep a-sheep]
breed [shepherds shepherd]

globals
[
  sheepless-neighborhoods       ;; how many patches have no sheep in any neighboring patches?
  herding-efficiency            ;; measures how well-herded the sheep are
  ones
  tens
  hundreds
]
patches-own
[
  sheep-nearby                  ;; how many sheep in neighboring patches?
]
shepherds-own
[

]

to setup
  clear-all
  set-default-shape sheep "sheep"
  set-default-shape shepherds "person"
  ask patches
    [ set pcolor green  + (random-float 0.8) - 0.4
      if pxcor > 40
      [ set pcolor (pcolor + 1) + (random-float 0.8) - 0.4 ]
      if pxcor > 20
      [ set pcolor (pcolor + 1)  + (random-float 0.8) - 0.4]
      ]  ;; varying the green just makes it look nicer

  create-sheep num-sheep
    [ set color white
      set size 2  ;; easier to see
      setxy (random 20) + 40  random-ycor ]
  create-shepherds 1
    [ set color brown
      set size 3  ;; easier to see

      setxy (random 20) + 40 random-ycor ]
     create-shepherds 1
    [ set color black
      set size 3  ;; easier to see

      setxy (random 20) + 20 random-ycor ]
  reset-ticks
end 

to go

  ask sheep with [not hidden?]
  [ if can-move? 1 = False ;; is the turtle blocked from moving foward 1 unit?
      [rt 180 ] ;; rotate 180 degree

      if xcor > 40 and size = 2 ;; is the sheep xcor greater than 40
      [ ;; sheep are in the ones column
        facexy  40 (ycor + random 3 - random 3)

        fd 1
      ]
     if xcor > 20 and xcor <= 40 and size = 5  ;; is the sheep xcor greater than 20
      [ ;; sheep are in the ones column
        facexy  20 (ycor + random 4 - random 4)

        fd 1
      ]
     if xcor >= 0 and xcor < 20 and size = 10 ;; is the sheep xcor greater than 0
      [ ;; sheep are in the ones column
        wiggle

         ifelse can-move? 1 = False ;; is the turtle blocked from moving foward 1 unit?
      [rt 180 ] ;; rotate 180 degree
      [ fd 1 ]
      ]

  ]
tick
set ones 0
ask sheep
[
  if  xcor < 41 and xcor > 39 and size = 2
  [
    set ones ones + 1
    die
  ]
  if  xcor < 21 and xcor > 19 and size = 5
  [
    set tens tens + 1
    die
  ]
]
print ones
print tens
tick
ask one-of sheep
[
   if ones >= 10
   [

      hatch int ( ones / 10 ) [
        setxy (random 15) + 20 random-ycor
        set size 5
      ]
      set ones ones mod 10

   ]
   hatch int ( ones mod 10 ) [
     setxy 40  random-ycor
     set size 2
   ]


   if tens >= 10
   [

      hatch int ( tens / 10 ) [
        setxy (random 15) random-ycor
        set size 10

      ]
      set tens tens mod 10

   ]

   hatch int ( tens mod 10 ) [
     setxy 20  random-ycor
     set size 5

   ]



set ones 0
set tens 0

]

ask sheep
[
 ifelse size = 10
 [ set color black]
 [ ifelse size = 5

   [set color blue]
   [set color white]
 ]
]
end 

to wiggle        ;; turtle procedure
  rt random 50 - random 50
end 

There is only one version of this model, created over 7 years ago by Tanya Harris.

Attached files

File Type Description Last updated
Bob the Sheepherder.png preview Preview for 'Bob the Sheepherder' over 7 years ago, by Tanya Harris Download

This model does not have any ancestors.

This model does not have any descendants.