netlogo代码

更新时间:2023-07-01 10:00:23 阅读: 评论:0

breed [persons person]
breed [bugs bug]
persons-own[                    ;设置人的个人属性:情感
  emotion
]
bugs-own[                        ;设置物的个人属性:情感
  emotion
]
to do-plot                        ;用于计算物的数量和情感的值
  t-current-plot "num"
  t-current-plot-pen "plot-1"
  plot count bugsdimm
  t-current-plot "emotion"
  t-current-plot-pen "emotion-1"
  ask bugs[
      plot emotion
    ]
比利艾略特end
to direction-decision                          ;为距离门远的逃跑对象设置“邻居”,根据人的心理尽可
                                            ;能模拟逃跑现场
ask bugs with [xcor < 26][
  let x bugs-on neighbors
  let temp-direction heading
  let temp-emotion emotion
  let sum-heading 0
  let ne-num count x
  if (ne-num >= 1 )[
    ask x[t shape "circle"
      t sum-heading sum-heading + heading
      ]
    t sum-heading sum-heading  / ne-num
    t temp-direction sum-heading
    ]
 
    t heading temp-direction
 
  ifel(xcor <= 4 and heading >= 180 and heading < 360)        ;之后的ifel代码是为了防止当逃跑对象
                                                        ;撞到墙后采取合理的转向
  [
    ; show "11111111111111111111"
    t heading random 90 + 45
  ][
  ifel (ycor >= 26 and( ( heading >= 270 and heading <= 360 ) or (heading > 0 and heading <= 90)) )[
    ; show "222222222222222222222"
    t heading random 90 + 45
    ][
    if (ycor <= 4 and heading >= 90 and heading < 270)[
    ;  show "3333333333333333
    t heading random 90 + 45
    ]]]
    fd 0.2
  ]
signs
end
to init                                              ;init是为了模拟现场环境声明的必要变量和属性
  clear-all
  create-persons 5
  [
    t xcor random 25 + 3
    t ycor random 25 + 3
    t shape "person"
    t size 1.5
    t color white
    t emotion random-float 0.2
  ]
  create-bugs ss
  [
    t xcor random 25 + 3
    t ycor random 25 + 3
    t shape "bug"
    t size 1.0
    t emotion random-float 0.2
不良情侣主题曲
  ]
    ask patches
    [
        t pcolor black
    ] 
    ask patches
    [
        if( pxcor = 2  and pycor >= 2  and pycor <= 28 );zuo
draconian        [
          t pcolor yellow 
        ]
        if( pycor = 28  and pxcor >= 2 and pxcor <= 28 );shang
        [
          t pcolor yellow 
        ]
        if( pycor = 2  and pxcor >= 2 and pxcor <= 28 );xia
        [
          t pcolor yellow 
        ]
        if( pxcor = 28  and pycor >= 8 and pycor <= 22);youzhong
        [
          t pcolor yellow 
        ]
       
    ]
 
end
to go                            ;go是让所有逃跑对象按照确定的方向逃跑
  let xt 0;
  let yt 0;
  ask turtles
  [
英语演讲比赛    fd 1
   
    if (direction = "up" )
    [ facexy ( xcor ) ( ycor + 1 ) ]
很快英文
    if (direction = "45" )
    [ facexy ( xcor + 1 ) ( ycor + 1 ) ]
    if (direction = "down" )
    [facexy ( xcor ) ( ycor - 1 )]
    if (direction = "right" )
    [facexy ( xcor + 1 ) ( ycor )]
    if (direction = "random" )
the pirate bay    [facexy ( random 32 ) ( random 32 )]
   
  ]
end
to escape                            ;此函数是为了模拟现场逃跑而设计的函数
  ask bugs
中俄在线翻译  [
    if(xcor >= 26 )
    [
      let dis1 0
      let dis2 0
      t dis1 (ycor - 4)*(ycor - 4)+(28 - xcor)*(28 - xcor)
      t dis2 (ycor - 24)*(ycor - 24)+(28 - xcor)*(28 - xcor)
      ifel (dis1 < dis2)
      [
        facexy 28 4 
      ] 
      [
        facexy 28 24 
      ]
    ]
  if(xcor >= 28 )
    [
      die 
    ]
   
  ]
  direction-decision
  ask bugs[
    fd 0.2 + 0.1 * emotion
  ]
  do-plot
end
to handle                                    ;handle是为了模拟现场的合理性,使墙上的人下来
  ask turtles with[pxcor = 2  and pycor >= 2  and pycor <= 28];zuo
  [
    t heading 90
    fd 1 
  ]
  ask turtles with[ pycor = 28  and pxcor >= 2 and pxcor <= 28 ];shang
  [
    t heading 180
    fd 1 
  ]
  ask turtles with[ pycor = 2  and pxcor >= 2 and pxcor <= 28 ];xia
  [
    t heading 0
    fd 1 
  ]
suicide  ask turtles with[ pxcor = 28  and pycor >= 2 and pycor <= 28 ];you
  [
    t heading 270
    fd 1 
  ]
 
end

本文发布于:2023-07-01 10:00:23,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/90/163508.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:逃跑   现场   模拟   对象   属性
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图