neco

mail@pastecode.io avatar
unknown
plain_text
2 years ago
3.0 kB
4
Indexable
Never
breed [people person]
breed [exits exit]

people-own [pace headx heady]
exits-own [doorx doory]
globals [escaped-people burned-people crushed-people]




to setup-people
  create-people persons
  ask people [
    
    setxy random-pxcor random-pycor
    set size 2
    set pace random-normal 1 0.2
    
    let min-dist 1000000
    let min-exit 0
    ask exits [
      if distance myself < min-dist [
        set min-dist distance myself
        set min-exit self
      ]
    ]
    set headx [doorx] of min-exit
    set heady [doory] of min-exit
  ]
end


to setup
  clear-all
  RESET-TICKS
  setup-exits

  setup-room
  setup-people
  blow-up
end

to setup-exits
  create-exits 2
  ask exit 0 [
    set doorx 1
    set doory 1
  ]
  ask exit 1 [
    set doorx 63
    set doory 63
  ]
  ask exits [
    setxy doorx doory
    hide-turtle
  ]
end


to blow-up
  let firex random-xcor
  let firey random-ycor
  ask patches [

    if ((firex - pxcor) ^ 2 + (firey - pycor) ^ 2 <= 10) [
      set pcolor red
    ]
  ]
end

to setup-room
  ask patches [
    set pcolor brown + 4
    let x pxcor
    let y pycor
    ask exits [
      if (x > (doorx - 2)) and (x < (doorx + 2)) and (y < (doory + 2))
      and (y > (doory - 2)) [
        ask myself [
          set pcolor green
        ]
      ]
    ]
  ]
end

to go
  make-step
  escape
  crush
  fire-spread
  burn
  tick
end


to burn
  ask people [
    ask patch-here [
      if pcolor = red [
        ask myself [
          set burned-people burned-people + 1
          die
        ]
      ]
    ]
  ]

end

to fire-spread
  ask patches [
    if pcolor = red [
      if random 100 < 2 [
        set pcolor black
      ]
    ]
    if pcolor = brown + 4 and any? neighbors with [pcolor = red] [
      if random 100 < 5 [
        set pcolor red
      ]
    ]
  ]
end


to crush
  ask people [
    ask patch-here [
      if count turtles-on neighbors >= 6 and random 100 < 5 [
        ask myself [
          set crushed-people crushed-people + 1
          die
        ]
      ]
    ]
  ]
end


to escape
  ask people [
    ask patch-here [
      if (pcolor = green) [
        ask myself [
          set escaped-people escaped-people + 1
          die
        ]
      ]
    ]
  ]
end

to make-step
  ask people [
    facexy headx heady
    ifelse (patch-ahead pace != nobody) and ((not any? turtles-on patch-ahead pace) or
      ((count turtles-on patch-ahead pace = 1) and
        (one-of turtles-on patch-ahead pace = self))) [
      jump pace
    ] [
      ifelse (patch-right-and-ahead 45 pace != nobody) and (not any? turtles-on patch-right-and-ahead 45 pace) [
        right 45
        jump pace
      ] [
        if (patch-left-and-ahead 45 pace != nobody) and (not any? turtles-on patch-left-and-ahead 45 pace) [
          left 45
          jump pace
        ]
      ]
    ]
  ]

end