No Friends on a Powder Day?

No preview image

1 collaborator

Default-person Spencer Murphy (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.1.1 • Viewed 74 times • Downloaded 9 times • Run 0 times
Download the 'No Friends on a Powder Day?' modelDownload this modelEmbed this model

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


Info tab cannot be displayed because of an encoding error

Comments and Questions

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

Click to Run Model

globals
[
  max-snow    ; maximum amount any patch can hold
  gini-index-reserve
  lorenz-points
  ;; create wealth by ability globals to use in histogram
  wealth-ability-1
  wealth-ability-2
  wealth-ability-3
]

patches-own
[
  snow-here      ; the current amount of snow on this patch
  max-snow-here  ; the maximum amount of snow this patch can hold
]

turtles-own
[
  soreness         ; how sore a turtle (skier) is, proportional to how long a skier has been skiing
  wealth           ; the amount of fresh snow a skiier has skied
  energy           ; maximum ticks a turtle can ski before they're tired and go home
  ability          ; how fast a skier goes, and proportional to how much snow they destroy
  vision           ; how many patches ahead a skier can see
]

;;;
;;; SETUP AND HELPERS
;;;

to setup
  clear-all
  ;; set global variables to appropriate values
  set max-snow 100
  ;; call other procedures to set up various parts of the world
  setup-patches
  setup-turtles
  update-lorenz-and-gini
  reset-ticks
end 

;; set up the initial amounts of snow each patch has

to setup-patches
  ;; give some patches the highest amount of snow possible --
  ;; these patches are the "best terrain"
  ask patches
    [ set max-snow-here 0
      if (random-float 100.0) <= percent-best-land
        [ set max-snow-here max-snow
          set snow-here max-snow-here ] ]
  ;; spread that snow around the window a little and put a little back
  ;; into the patches that are the "best land" found above
  repeat 5
    [ ask patches with [max-snow-here != 0]
        [ set snow-here max-snow-here ]
      diffuse snow-here 0.25 ]
  repeat 10
    [ diffuse snow-here 0.25 ]          ;; spread the snow around some more
  ask patches
    [ set snow-here floor snow-here    ;; round snow levels to whole numbers
      set max-snow-here snow-here      ;; initial snow level is also maximum
      recolor-patch ]
end 

to recolor-patch  ;; patch procedure -- use color to indicate snow level
  set pcolor scale-color white snow-here 0 max-snow
end 

;; set up the initial values for the turtle variables

to setup-turtles
  set-default-shape turtles "person"
  create-turtles num-skiers
    [ move-to one-of patches  ;; put turtles on patch centers
      set size 1.5  ;; easier to see
      set-initial-turtle-vars
      set soreness random energy ]
  recolor-turtles
end 

to set-initial-turtle-vars
  set soreness 0
  ;;face one-of neighbors4
  set energy energy-min +
                        random (energy-max - energy-min + 1)
  set ability 1 + random 3
    ;;round ability
  set wealth 0.1  ;; everyone starts the day having skied 0 snow (0.1 to avoid division by zero)
  set vision 1 + random max-vision
  set label ability
end 

;; Set the class of the turtles -- if a turtle has less than a third
;; the wealth of the richest turtle, color it red.  If between one
;; and two thirds, color it green.  If over two thirds, color it blue.

to recolor-turtles
  let max-wealth max [wealth] of turtles
  ask turtles
    [ ifelse (wealth <= max-wealth / 3)
        [ set color red ]
        [ ifelse (wealth <= (max-wealth * 2 / 3))
            [ set color green ]
            [ set color blue ] ] ]
end 

;;;
;;; GO AND HELPERS
;;;

to go
  ask turtles
    [ turn-towards-snow ]  ;; choose direction holding most snow within the turtle's vision and downhill
  ski-forward
  ask turtles
    [ move-eat-soreness-die ]
  recolor-turtles
  ;; grow snow every snow-fall-interval clock ticks
  if ticks mod snow-fall-interval = 0
    [ ask patches [ grow-snow ] ]
  update-lorenz-and-gini
  ask turtles
    [ update-wealth-ability ] ;; tracks the wealth for each ability level
  tick
end 

;; determine the direction which is most profitable for each turtle in
;; the surrounding patches within the turtles' vision
;; re-worked to make them only go across, diagonal, or straight down the hill

to turn-towards-snow  ;; turtle procedure
  set heading one-of (range 90 270)
  let best-direction 180
  let best-amount snow-ahead
  set heading 90
  if (snow-ahead > best-amount)
    [ set best-direction 90
      set best-amount snow-ahead ]
  set heading 135
  if (snow-ahead > best-amount)
    [ set best-direction 135
      set best-amount snow-ahead ]
  set heading 180
  if (snow-ahead > best-amount)
    [ set best-direction 180
      set best-amount snow-ahead ]
  set heading 225
  if (snow-ahead > best-amount)
    [ set best-direction 225
      set best-amount snow-ahead ]
  set heading 270
  if (snow-ahead > best-amount)
    [ set best-direction 270
      set best-amount snow-ahead ]
  set heading best-direction
end 

to-report snow-ahead  ;; turtle procedure
  let total 0
  let how-far 1
  repeat vision
    [ set total total + [snow-here] of patch-ahead how-far
      set how-far how-far + 1 ]
  report total
end 

to grow-snow  ;; patch procedure
  ;; if a patch does not have it's maximum amount of snow, add
  ;; num-snow-fall to its snow amount
  if (snow-here < max-snow-here)
    [ set snow-here snow-here + num-snow-fall
      ;; if the new amount of snow on a patch is over its maximum
      ;; capacity, set it to its maximum
      if (snow-here > max-snow-here)
        [ set snow-here max-snow-here ]
      recolor-patch ]
end 

;; each turtle skis foward to the snow on its patch.  if there are multiple
;; turtles on a patch, divide the snow evenly among the turtles

to ski-forward
  ; have turtles ski the snow based on ability
  ask turtles
    [ set wealth floor (wealth + ((snow-here * ability ^ ability-advantage) / (count turtles-here))) ]
  ;; now that the snow has been skied, have the turtles make the
  ;; patches which they are on have less snow
  ask turtles
    ;; each skier removes some of the fresh snow
    ;; the amount removed increases based on ability and ability-advantage
    [ set snow-here (snow-here - (ability ^ ability-advantage) * 10)
      recolor-patch ]
end 

to move-eat-soreness-die  ;; turtle procedure
  ;; each skier moves
  fd ability
  ;; skiers tire faster and faster over time
  set wealth (wealth - soreness)
  ;; grow more tired
  set soreness (soreness + 1)
  ;; check for "death" conditions: if you have no more wealth or
  ;; you're more tired than you have energy to continue,
  ;; then you "die" and are "reborn" (in fact, your variables
  ;; are just reset to new random values)
  if (wealth < 0) or (soreness >= energy)
    [ set-initial-turtle-vars ]
end 

;; this procedure recomputes the value of gini-index-reserve
;; and the points in lorenz-points for the Lorenz and Gini-Index plots

to update-lorenz-and-gini
  let sorted-wealths sort [wealth] of turtles
  let total-wealth sum sorted-wealths
  let wealth-sum-so-far 0
  let index 0
  set gini-index-reserve 0
  set lorenz-points []

  ;; now actually plot the Lorenz curve -- along the way, we also
  ;; calculate the Gini index.
  ;; (see the Info tab for a description of the curve and measure)
  repeat num-skiers [
    set wealth-sum-so-far (wealth-sum-so-far + item index sorted-wealths)
    set lorenz-points lput ((wealth-sum-so-far / total-wealth) * 100) lorenz-points
    set index (index + 1)
    set gini-index-reserve
      gini-index-reserve +
      (index / num-skiers) -
      (wealth-sum-so-far / total-wealth)
  ]
end 

to update-wealth-ability
  if (ability = 1)
    [set wealth-ability-1 (wealth-ability-1 + wealth)]
  if (ability = 2)
    [set wealth-ability-2 (wealth-ability-2 + wealth)]
  if (ability = 3)
    [set wealth-ability-3 (wealth-ability-3 + wealth)]
end 

; Copyright 1998 Uri Wilensky.
; See Info tab for full copyright and license.

There is only one version of this model, created about 3 years ago by Spencer Murphy.

Attached files

File Type Description Last updated
pow-day.png png screen grab about 3 years ago, by Spencer Murphy Download

This model does not have any ancestors.

This model does not have any descendants.