📄 ---dirdie3.nlogo
字号:
globals [adjacent runaway east-t neast-t north-t nwest-t west-t swest-t south-t seast-t east-c neast-c north-c nwest-c west-c swest-c south-c seast-c high dir]breeds [cops assassins targets]assassins-own [head]cops-own [age]to setup ca create-custom-targets initpop [ set shape "target" set color white] create-custom-assassins initkill [ set head random 360 set shape "killer" set color red] create-custom-cops initcop [ set shape "cop" set age 0 set color blue] ask targets[ rt random 360 fd random 100 ;(screen-size-x * screen-size-y) ] ask assassins[ set color red rt random 360 fd random 100 ] set high random 360 set runaway random 100 ask cops[ set heading high fd runaway ] ask cops[ rt random 360 fd 1 ] plot-popendto change-assassins ask cops[ set high 2 ;; adjustment to odds set runaway 2 ;; distance to search if count cops in-radius 2 > 1[ set runaway (count cops in-radius 2) + 1 ;; the more cops around us, the farther we can look set high (count cops in-radius 2) + 1] ;; the more cops, the less likely it will die set adjacent count assassins in-radius runaway if adjacent > 1[ if random-float 1 < (convert / high)[die] ] if adjacent > 0[ ask assassins in-radius 2[ ifelse random-float 1 < convert [ifelse random-float 1 < convert [set breed cops set shape "newcop" set color violet] [set breed targets set shape "newtarget" set color yellow]] [die] ] ] rt random 360 fd 1 ]endto kill-adjacents ask assassins [ ask targets in-radius 2 with [shape = "newtarget"][ if random-float 1 < convert[ set breed assassins set shape "newkiller" set color orange ] ] ask targets at-points [[0 0]] [die] ;; kill anybody in our cell set adjacent count targets in-radius 2 ;; count general population set runaway count cops in-radius 2 ;; count cops set east-t count targets at-points [[1 0]] set high east-t set dir 90 set neast-t count targets at-points [[1 1]] if neast-t > high [ set high neast-t set dir 45] set north-t count targets at-points [[0 1]] if north-t > high [ set high north-t set dir 0] set nwest-t count targets at-points [[-1 1]] if nwest-t > high [ set high nwest-t set dir 315] set west-t count targets at-points [[-1 0]] if west-t > high [ set high west-t set dir 270] set swest-t count targets at-points [[-1 -1]] if swest-t > high [ set high swest-t set dir 225] set south-t count targets at-points [[0 -1]] if south-t > high [ set high south-t set dir 180] set seast-t count targets at-points [[1 -1]] if seast-t > high [ set high seast-t set dir 135] ifelse adjacent > 0 [ if seast-t = high and dir = 135 [ ask targets at-points [[1 -1]] [die]] if south-t = high and dir = 180 [ ask targets at-points [[0 -1]] [die]] if swest-t = high and dir = 225 [ ask targets at-points [[-1 -1]] [die]] if west-t = high and dir = 270 [ ask targets at-points [[0 -1]] [die]] if nwest-t = high and dir = 315 [ ask targets at-points [[-1 1]] [die]] if north-t = high and dir = 0 [ ask targets at-points [[0 -1]] [die]] if east-t = high and dir = 90 [ ask targets at-points [[0 -1]] [die]] if neast-t = high and dir = 45 [ ask targets at-points [[1 1]] [die]] set heading dir ] [set heading random 360] fd 1 ]endto go ask targets[ rt random 360 fd 1 ] if count assassins = 0[ print "cops won" stop] if count targets = 0 or count cops = 0[ print "assassins won" stop] kill-adjacents change-assassins plot-popendto plot-pop set-current-plot "population" set-current-plot-pen "target" plot count targets set-current-plot "cops and killers" set-current-plot-pen "killer" plot count assassins set-current-plot-pen "cop" plot count copsend@#$#@#$#@GRAPHICS-WINDOW40610946571262610.006111CC-WINDOW310404129Command CenterBUTTON413370182NILsetupNIL1TOBSERVERTBUTTON137133200182NILgoT1TOBSERVERTBUTTON72133135182stepgoNIL1TOBSERVERTPLOT4184200635populationtimepopulation0.015.00.015.0truefalsePENS"target" 1.0 0 -16777216 true"assassin" 1.0 0 -65536 true"cop" 1.0 0 -16776961 trueSLIDER706574804607initkillinitkill11005011NILMONITOR313133404182targetscount targets01SLIDER506574604607initcopinitcop1251011NILMONITOR261133311182killerscount assassins01SLIDER606574704607initpopinitpop10025000121001001NILPLOT202184404635cops and killerstimequantity0.010.00.010.0truefalsePENS"killer" 1.0 0 -65536 true"cop" 1.0 0 -16776961 trueSLIDER406574504607convertconvert010.50.011NILMONITOR202133259182copscount cops31@#$#@#$#@WHAT IS IT?-----------This model simulates assassins (red) trying to kill the general population (white), and being hunted by cops (blue). At the end of the simulation, it displays a short message indicating which side won (cops or assassins).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -