设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8750|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。" x, a( @2 r: z- @* u
6 ?+ e! S4 x! d- H
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
7 [& Q# C8 Z: e# K
! d. z) L# ?: [, j/ dturtles-own [a b c d k f g h) j2 R% d- ?; y  g( p! f
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 4 N! e( N" P$ d
]' I  b+ l4 }8 z3 e  Y
to new8 O  u% T: N; q# |4 A; _* j4 Z
  ca
' i4 c5 j( u  N0 ^% s& K  crt 5 * num_of_building
) L  T6 ^! c5 A3 U* b* w/ m  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]2 _/ D: q  ~- _. F0 `
  scatter     ;;keep center-turtle random positions
* w- |+ J. K" u: s9 p$ y: x/ I  unit_plan   ;;make up the building plan4 \  b  a. @! B- W
end* u8 l$ ~: z6 ?
to scatter
1 L8 T9 n: x: b2 task turtles with [remainder who 5 = 0]
" Y; t; v) j8 q& j4 M. H0 A( L[  x( D( o9 `( ^2 B! v2 [2 m+ q
set xcor xcor - 6 + random-float 15
- {" y& m5 W: eset ycor ycor - 6 + random-float 15# H3 z9 p$ \' e3 x1 c$ Q0 K
]' v3 P& ^: O7 Q9 d$ T
end
, {' k4 }& g# c. V2 n* [to unit_plan 0 S8 B7 N5 `' l- j, m' [! `/ C
ask turtles [" }% p$ y* L4 I% g5 y: m
if (remainder who 5 = 1) [set a who 1 o- Y+ M6 I9 B8 n
                          set x ( 0 - Wid / 2 ) 4 e2 j# f% O, B! r( f* L1 f2 {5 @: i4 F
                          set y  Dep / 2 ]9 H% ^' e) y0 s4 j
           set b  int (a / 5) * 5
. @4 Y8 H7 t, `5 A9 K! z, h' m    setxy ( xcor-of turtle b + x )
" @3 ~  v9 R& H* O# Q: o/ }& j          ( ycor-of turtle b + y )
( {; b9 t5 R3 `. O2 }1 [if (remainder who 5 = 2) [set c who- O) l( s' W) f& t9 h! F3 n
                          set x ( 0 - Wid / 2 ) $ V  N6 \, j; Q( N6 H6 e5 e6 L
                          set y (0 - Dep / 2 )  ]9 e9 B! k% s/ {: {" R
                          set d int (c / 5) * 5
/ k1 _$ s- x3 J/ ~* ]* \  h' Z+ S: t   setxy   ( xcor-of turtle d + x )$ f' g% ~1 G: {& x( |0 B
           (ycor-of turtle d + y )
) O1 `; V% b0 a2 Y4 g         
& b/ A4 a+ |) v  H$ w# R4 T            " S* G: O/ y1 d' A* U4 A
if (remainder who 5 = 3) [set k who
8 w/ \3 f/ h( ?7 `                          set x( Wid / 2)  
! o6 N7 }+ f! N* c                          set y (0 - Dep / 2 ) ]
* L2 i3 x/ R: j                          set f int (k / 5) * 5. U' M5 h% n4 X
  setxy   ( xcor-of turtle f + x )9 c% k% _4 @: O$ ~+ {! H
           (ycor-of turtle f + y ) : s# W5 M1 z& d5 r. M/ d7 h1 g+ Q5 N7 J
           
' u- R+ O% Z4 l8 I4 T           
+ n; d8 W, S- ~if (remainder who 5 = 4) [set g who+ y9 F1 h  ]3 q/ y3 c9 l
                          set x Wid / 2
' {% X/ }. z2 |  P                          set y  Dep / 2 ]
! u8 J$ G8 n2 A$ ]# x  T- |                          set h  int (g / 5) * 5
  q# h7 c$ j5 E" U* R- Y  setxy   ( xcor-of turtle h + x )
! A. A6 a8 r5 i/ R           (ycor-of turtle h + y )
1 s3 n4 b+ M( s- {, l& ^, E                          
4 r2 |& q. |* O6 M8 ^. B6 P; j                          ! q$ n4 Y: E! ]+ w3 }5 R
                          ]
, q5 W0 H/ T. m3 lend
2 m' S7 s, Z! f0 i, o9 ~
0 e2 l, a5 _( S9 ][ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,. W8 F* D$ Q( t  Q4 h. f
应该是
2 a( V% F6 C, `# e: Vask turtles [
6 C$ m* U& ~2 _& ?if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
4 W7 ~2 r+ B6 L7 k: C, w                          set y  Dep / 2 % g& h! @) Z" z. V+ a2 e  U' M0 k
           set b  int (who / 5) * 5
: k4 Q: f, {; O* J+ x    setxy ( xcor-of turtle b + x )$ `/ I( m1 w/ R. _
          ( ycor-of turtle b + y )]]
! C+ I  I7 m& Hend, W' h0 o7 C0 Z, q, Z( g, W' K
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-1 05:44 , Processed in 0.014746 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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