设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9076|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
2 W+ U# {  w# f- j1 C3 u4 ?6 B. k3 ]: y3 T5 S6 X1 P( S
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
& `5 V& K& F, v4 `: }5 t3 X$ n3 W( t
turtles-own [a b c d k f g h
0 \% H7 J  v! z4 @! J" M# M8 k  x y     ;; these are the leaf-turtle's offsets relative to center-turtle * A- b; j+ X1 o# A" S
]
) v7 ^5 a6 L0 W- e' Cto new
' }( [1 ]4 \' h% m& Y3 b  ca  C  p& }2 }( n' ~" e
  crt 5 * num_of_building0 l8 I2 n: g' \$ ]7 P
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]1 z& @7 e) v6 \  L6 F7 r
  scatter     ;;keep center-turtle random positions
$ U) t! [6 d( ]  G4 k3 Q  unit_plan   ;;make up the building plan
( }/ F0 i8 z0 B7 ^4 bend$ q4 H0 ]1 e; T, j0 ]$ a
to scatter
8 z/ i9 F- ^& g/ p/ H/ y2 task turtles with [remainder who 5 = 0]. h/ M0 t* a% w5 H: E+ B$ w8 ?5 {
[4 c* W, D' b4 T* B+ K3 w
set xcor xcor - 6 + random-float 15
3 _2 R  U4 |3 {set ycor ycor - 6 + random-float 15
6 e, Y6 B' j" R3 {8 x) A# T]
! m5 h( G$ ?+ W$ u* k. rend, H  ^2 x& r- h. ]
to unit_plan
+ K4 j# Y  P2 `& N. }ask turtles [( O* ?+ |( w5 L1 Y0 P, v
if (remainder who 5 = 1) [set a who
7 i& b# l$ [3 l6 n& l! Q& B                          set x ( 0 - Wid / 2 ) + C' S$ v7 E$ E9 J3 a% d4 W2 u
                          set y  Dep / 2 ]% P' R3 t+ I' H1 x
           set b  int (a / 5) * 5
  _# U, P$ R4 C3 r4 F% z! V# E    setxy ( xcor-of turtle b + x )
0 `' `; `# [" W: I) a( @          ( ycor-of turtle b + y )$ c4 W- B' }! M7 K
if (remainder who 5 = 2) [set c who
2 ~$ e; l& _" g! F                          set x ( 0 - Wid / 2 )
" r. b, f. v  I3 U0 p3 Q5 d                          set y (0 - Dep / 2 )  ]
: b2 R) y  Y9 p# _' d                          set d int (c / 5) * 5( x+ r3 _1 j9 P, L
   setxy   ( xcor-of turtle d + x )
. h( C6 m0 X7 n           (ycor-of turtle d + y ) ) @2 m$ ~6 s0 g  |' ^! a7 C
         
: z) d. l1 h" h% g: e/ N* B) D            
) Q2 b: t0 `# c* D9 p$ b- S. Kif (remainder who 5 = 3) [set k who
; B7 ~$ f, j5 [1 z5 h                          set x( Wid / 2)  ) g! D  c1 T3 H3 ~0 @7 J/ K
                          set y (0 - Dep / 2 ) ]
/ ~1 w* \8 A3 ~1 @: K                          set f int (k / 5) * 5
4 C$ J6 H$ I! n0 A  setxy   ( xcor-of turtle f + x )
# J- e- }3 d% X2 v           (ycor-of turtle f + y )
' w% ]: w- q; h/ h1 V           ( y# N8 P7 R0 a+ {% b6 V! m
           
8 \9 }5 e  r% f& qif (remainder who 5 = 4) [set g who
& b1 k3 K" X; s. G# ^                          set x Wid / 2
0 ?* J4 L+ |4 X- ?  ?( e                          set y  Dep / 2 ]( C2 _2 d8 Y0 p* _# b( C
                          set h  int (g / 5) * 5, o- _# l1 \/ N( x* A6 D% Z- ^
  setxy   ( xcor-of turtle h + x )
0 K9 r4 G$ v; Y           (ycor-of turtle h + y )
, x5 ]$ m) V; l: T                          
/ N5 }# D# w4 K+ \                            g3 I( q" m3 @+ n
                          ]
9 y9 {* I1 j- }end# E& q2 \, @  a6 [

$ P2 P6 ^& F5 r+ S[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,3 A1 e/ d2 u8 G) ~1 N7 e
应该是9 Z( _4 y, I9 z
ask turtles [$ ~% H8 f8 G0 D% u9 w3 z1 r' ~6 u
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) , p5 Y. j. p' ]  ?7 b
                          set y  Dep / 2
7 A  U8 T; Y5 L6 C9 A1 u           set b  int (who / 5) * 5, G$ P; @$ \0 v( d
    setxy ( xcor-of turtle b + x )# n" l1 y7 U9 v4 W/ A
          ( ycor-of turtle b + y )]]
$ m) W2 `1 k! g* i; Tend- K. m! R% S5 ]; ~# N/ E
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-14 17:08 , Processed in 0.015994 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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