Netlo go - отражающие и преображающие черепахи - PullRequest
0 голосов
/ 11 января 2020

Я работаю над моделью в Netlo go. В настоящее время я пытаюсь создать модель, в которой черепахи в форме лучей поглощаются пятнами в определенных точках и трансформируются в точки. Эти точки должны затем быть в состоянии преобразоваться обратно в лучи и оставить пятна в определенной области, точно так же, как в модели изменения климата из библиотеки моделей: https://ccl.northwestern.edu/netlogo/models/ClimateChange

Однако это преобразование должно происходить не в определенном xcor, а в исправлениях в области, которую я определил. Кроме того, я пытаюсь установить альбедо для различных патчей в этой области. Я действительно рад любой помощи, так как я застрял в этой проблеме.

Вот мой код:

extensions [ gis ]

globals [
  wien-grenzen
  temperature
]

patches-own [
  random-n
  centroid
  ID
  patch-type
]

breed [rays ray]
breed [IRs IR]
breed [heats heat]
breed [CO2s CO2]
breed [trees tree]
breed [industries industry]

to setup
  clear-all
  set-default-shape rays "ray"
  set-default-shape IRs "ray"
  set-default-shape heats "dot"
  set-default-shape CO2s "CO2-molecule"
  set-default-shape trees "tree"
  set-default-shape industries "industry"
  setup-map
  set-surface
  set temperature 0
  reset-ticks
  plot temperature
end

to setup-map
  clear-all
  set wien-grenzen gis:load-dataset "Bezirksgrenzen.shp"
  gis:set-world-envelope (gis:envelope-of wien-grenzen)
  let i 1
  foreach gis:feature-list-of wien-grenzen [ feature ->
    ask patches gis:intersecting feature [
;      set centroid gis:location-of gis:centroid-of feature
;      ask patch item 0 centroid item 1 centroid [
;        set ID i
;      ]
      set ID i
    ]
    set i i + 1
  ]
  gis:set-drawing-color white
  gis:draw wien-grenzen 1.5
end

to set-surface
  ask patches with [ID > 0] [
    set random-n random-float 20
    if random-n < 5
    [
      gis:set-drawing-color gray + 1
      set pcolor gray + 1
    ]
     if random-n > 5 and random-n < 10
    [
      gis:set-drawing-color gray + 2.5
      set pcolor gray + 2.5
    ]
    if random-n > 10 and random-n < 15
     [
      gis:set-drawing-color green + 1
      set pcolor green + 1
    ]
     if random-n > 15 and random-n < 20
    [
      gis:set-drawing-color green + 2.5
      set pcolor green + 2.5
    ]
  ]
  gis:set-drawing-color white
  gis:draw wien-grenzen 1.5
end

to go
  run-sunshine
  run-CO2
  run-heat
  tick
  plot temperature
  ask trees [
    catch-CO2s
  ]
  ask industries [
    emmit-CO2s
  ]
end

to radiate
   if 10 * sun-brightness > random 50 [
     hatch-rays 1 [
     set color yellow
     set heading 150 + random 60
     set size 1]
   ]
end

to run-sunshine
  ask rays [
    if not can-move? 0.3 [ die ]
    fd 0.3
  ]
  create-sunshine
  encounter-earth
end

to create-sunshine
  if 10 * sun-brightness > random 50 [
    create-rays 1 [
      set heading 370
      set color yellow
      setxy (random 60) + min-pxcor max-pycor
;      setxy (min-pxcor + 2) 22.6
    ]
  ]
end

to encounter-earth
  ask rays [
    if [ pcolor ] of patch-here = gray + 1 [
       ifelse (100 * ((pcolor / 10) mod 1)) > random 100
      [ set heading 180 - heading  ]
      [ rt random 45 - random 45
        set color red + random 4
        set breed heats ]
  ]
    if [ pcolor ] of patch-here = gray + 2.5 [
       ifelse (100 * ((pcolor / 10) mod 1)) > random 100
      [ set heading 180 - heading  ]
      [ rt random 45 - random 45
        set color red + random 4
        set breed heats ]
  ]
  ]
end

to run-heat
  set temperature 0.99 * temperature + 0.01 * (12 + 0.1 * count heats)
  ask heats
  [
    let dist 0.5 * random-float 1
    ifelse can-move? dist
      [ fd dist ]
      [ set heading 180 - heading ]
  ]
end

to add-tree
  let created false
  while [ not created ] [
    create-trees 50 [
      set color green
      set size 1.1
      setxy random-xcor random-ycor
      ifelse ID > 0 [
        set created true
      ] [
        die
      ]
    ]
  ]
end

to remove-tree
  repeat 10 [
    if any? trees [
      ask one-of trees [ die ]
    ]
  ]
end

to add-industry
  let created false
  while [ not created ] [
    create-industries 10 [
      set size 2.1
      setxy random-xcor random-ycor
      ifelse ID > 0 [
        set created true
      ] [
        die
      ]
    ]
  ]
end

to remove-industry
  repeat 10 [
    if any? industries [
      ask one-of industries [ die ]
    ]
  ]
end

to add-CO2
  let i 1
  create-CO2s 25 [
    setxy random-xcor random-ycor
  ]
end

to remove-CO2
  repeat 25 [
    if any? CO2s [
      ask one-of CO2s [ die ]
    ]
  ]
end

to run-CO2
  ask CO2s [
    rt random 51 - 25
    let dist 0.05 + random-float 0.1
    if [pycor <= 0.5] of patch-ahead dist
      [ set heading 180 - heading ]
    fd dist
    ;setxy xcor 0.996 * ycor
     setxy random-xcor random-ycor
  ]
end

to catch-CO2s
  let prey one-of CO2s-here
  if prey != nobody
    [ ask prey [ die ]
    ]
end

to emmit-CO2s
  if random 100 > 95 [
  hatch-CO2s 1 [
    set size 1
    set color green
  ]
  ]
end

Вот скриншот интерфейса: enter image description here

...