设为首页收藏本站

最大的系统仿真与系统优化公益交流社区

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7507|回复: 1

[交流] 看看这段代码的问题

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
* m4 ?6 z6 J3 D1 C
. w* i, _4 i/ o( E' @但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
. B% w' R( K* z# O3 o
6 R( Q( ~$ B% x7 e7 o3 @turtles-own [a b c d k f g h
: A) C5 x) D# G& t  ]/ ^  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ; d5 y% ], V" }' o3 Y$ `( n; G
]
; C1 L0 s- m; j1 t2 k; Z4 B* N5 Ato new
9 K. P8 O( U4 H$ f4 g$ i2 V  ca
3 F8 b$ v: y1 A  @  crt 5 * num_of_building" a( T: X. z4 ^" ]5 F7 c
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
8 [  U, z: Y$ x- J  scatter     ;;keep center-turtle random positions " f/ \  ~1 n$ M* u# L% r+ q
  unit_plan   ;;make up the building plan- v3 K2 G9 [, W* _, H' j; O
end2 U/ M) F5 g- H5 Y1 Q8 s6 _( z
to scatter1 j* y# N( L& z) ]0 l! b) Z4 X
ask turtles with [remainder who 5 = 0]8 L! t- f4 Y" s) [8 [! b0 i
[) l. P5 F3 }+ c9 [2 g- n# R
set xcor xcor - 6 + random-float 15( F+ N  d6 ~) M5 s2 }1 |- L
set ycor ycor - 6 + random-float 15
, v+ J/ {, B' C# z9 Q9 R; u9 a]% A! z7 G% ?% j& n
end& F: l! C1 _8 a" U! R9 C6 d* R
to unit_plan 4 f0 c% `" @% D7 o
ask turtles [
0 [7 |5 T1 z" y# h# L3 O) d) Zif (remainder who 5 = 1) [set a who
9 e* m# Q: Q8 m! @8 }  d9 K) e                          set x ( 0 - Wid / 2 )
# h1 e0 m6 E& A4 U                          set y  Dep / 2 ]. ^, y, d. m; t% ?. ?# F
           set b  int (a / 5) * 5
. i/ J2 Z# n- D# h    setxy ( xcor-of turtle b + x )
4 R  r+ R8 Y! F- R) n& @& S; f; F          ( ycor-of turtle b + y )5 E& n. P5 \* L: t
if (remainder who 5 = 2) [set c who, p0 n0 O8 l2 y7 k1 ?' M, d: n
                          set x ( 0 - Wid / 2 ) , O2 U+ y3 Z- |3 h; p( e
                          set y (0 - Dep / 2 )  ]% m. S1 Z/ f2 b) Z/ q
                          set d int (c / 5) * 5
! p! K  m  F! C8 H4 c5 b   setxy   ( xcor-of turtle d + x )2 x( }, n4 q# V! E
           (ycor-of turtle d + y )
! s2 e  _& d$ X- V         
. @. Z, G, }* G" V            
% M7 L1 R; ~: k) d4 T. Y4 ^, ^if (remainder who 5 = 3) [set k who5 e! o- E& U; K# V8 s- d4 U
                          set x( Wid / 2)  
. M) ^9 b: h& k, G                          set y (0 - Dep / 2 ) ]
8 o! q& v! i, U, ?7 q* @                          set f int (k / 5) * 5
) C# o3 e8 A- ?7 Y  setxy   ( xcor-of turtle f + x )
6 r7 z9 Y* z$ m           (ycor-of turtle f + y ) " r* K. i+ ]& y3 Y- l6 M, {
           
; d& O+ G. F' w; L5 v. [# h9 ~           
/ r# `. x/ s% i4 A) N$ R5 t* w& \if (remainder who 5 = 4) [set g who' z2 q, b$ A# e3 Z- ^6 R
                          set x Wid / 2 6 C' \8 ?. k$ T' o3 n7 y0 @
                          set y  Dep / 2 ]- R' \0 a! X/ `' Q
                          set h  int (g / 5) * 5
; F; ~0 I8 d/ o% z! t  setxy   ( xcor-of turtle h + x )
: c* f( ^! R( _9 A7 @4 C' |: ~           (ycor-of turtle h + y )
. |0 F* j. \" a8 d" H                          3 O5 U: o/ X# R2 s& X
                          " B! c2 T. o4 U: N9 @' r
                          ]
2 Y  J, p: J0 r: w  M; F7 C9 Vend7 W/ K. C$ t# r. j/ V5 n

7 D$ T: D" m- Q/ k' o! o+ t[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
) U& c- I$ B& s3 ~4 c+ q应该是% n  x, ?3 n& b' l/ i
ask turtles [& {# Q5 {# Z5 r3 n) _
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
( c, p% X$ ]! k. D                          set y  Dep / 2 4 s9 E: |) E: R3 F: a% m
           set b  int (who / 5) * 53 R+ y7 ?. S: S. |
    setxy ( xcor-of turtle b + x )8 D. C9 Y" M9 C! c
          ( ycor-of turtle b + y )]]
2 \8 M. P: `; O3 {* h8 Eend
3 ^4 {6 W+ f, B/ J之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|Archiver|手机版|SimulWay 道于仿真   

GMT+8, 2026-2-19 21:34 , Processed in 0.020078 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表