设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6779|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
' S5 a/ E, _& \4 M) k" h+ r3 A4 A
1 t/ H( {& P: p" o) T3 o; G3 a但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。* s  t. a3 L& ^+ H; _

9 `% q7 x6 j8 ?' pturtles-own [a b c d k f g h% a" n4 V( K* o* {1 U( k1 j
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle   I# o  a  ^+ A% F
]
2 ?, F  s% u, L# A! Gto new
4 ^- y% g# \. v% [$ \/ |  ca
9 B5 H2 f% }1 v  crt 5 * num_of_building* D8 x. h; U% B+ A  ^/ F% d
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]: R9 V4 E+ ~; M) ?8 D  O( ~
  scatter     ;;keep center-turtle random positions 4 C9 ^) L$ O8 @) d
  unit_plan   ;;make up the building plan- L: B7 C; p2 r1 r" f; ?& F
end
# v4 e- r$ D6 r8 B2 G; Xto scatter% b% B" _$ y' |- s$ B0 n9 d( w
ask turtles with [remainder who 5 = 0]$ f, u' s+ r9 z; m! {: B( y# `
[
6 W2 s7 K5 k/ Pset xcor xcor - 6 + random-float 15
, C- u" o$ I( K. z' S- R! bset ycor ycor - 6 + random-float 15$ ~- E9 }: S8 q4 p( {: ~
]
' J+ U! F  B/ x0 V, x/ h# P3 F, [, Mend) i$ Y/ m) |7 p4 w. N6 \6 h7 [4 C1 p
to unit_plan 7 }, Q7 X" L6 ]4 ]
ask turtles [
! L2 O0 v* z  V" c2 o% T9 d, Z8 m# ~: `if (remainder who 5 = 1) [set a who " Z1 I1 u7 C1 M4 R8 N! K: L
                          set x ( 0 - Wid / 2 )
. H! R$ _7 j/ p  Q! R/ }                          set y  Dep / 2 ]2 r9 ~6 y$ _$ x4 h
           set b  int (a / 5) * 5* H" c1 R+ F: g$ p' u
    setxy ( xcor-of turtle b + x )5 _; x* q1 c7 _. x* W! U# f% I
          ( ycor-of turtle b + y )# [5 I' H7 W7 e6 r; e* e
if (remainder who 5 = 2) [set c who
2 q+ i0 K1 J- I; p( q                          set x ( 0 - Wid / 2 ) + T% J! k8 k! Y
                          set y (0 - Dep / 2 )  ]: i! \0 S* T$ w+ g( h8 Y
                          set d int (c / 5) * 5
+ H, w5 w5 K( a# J+ i# G" n' \. @   setxy   ( xcor-of turtle d + x )6 \+ ]7 U2 |) K$ M; v7 l/ e
           (ycor-of turtle d + y )
) H* f9 F7 _6 m' Q$ ]# B& ?4 @          ; ~, E" k7 G& d: p
            
; E1 Y/ f7 z; s' }if (remainder who 5 = 3) [set k who
8 O# v0 F7 c- ~5 m1 T1 ?  r                          set x( Wid / 2)  
0 a7 |0 ?6 U: {3 c- m) D                          set y (0 - Dep / 2 ) ]/ O8 H! q4 s1 F% ?# H; ?
                          set f int (k / 5) * 58 Q4 J9 [  `; P& k, o
  setxy   ( xcor-of turtle f + x )
& o7 h) ]( H5 b           (ycor-of turtle f + y ) $ J$ v/ Z. Z: D4 l, I: g# p2 N
           , @4 q! ~% u1 y) |5 O) P% z" w0 T
           - E* `4 q& j9 ]0 c* {* }! m
if (remainder who 5 = 4) [set g who1 m' \% m6 E; l' _
                          set x Wid / 2 $ T( P# z3 u. c$ c7 O) h2 u
                          set y  Dep / 2 ]
1 q5 `3 f8 z! v+ q$ a                          set h  int (g / 5) * 5
1 C; j) ?- r4 r  setxy   ( xcor-of turtle h + x )
) F$ n3 m) V  ]5 ?" r7 z) ~1 i. ^           (ycor-of turtle h + y ) / W# q2 v4 m/ n. ]* o: \3 p
                          
0 g0 Y: m0 |) n' M                          7 S3 V5 N9 F! a4 T& ~1 y
                          ]/ h" ?/ r' J0 ~. i
end
5 N* z- I$ Y# ~/ @5 t1 X0 q5 c- f
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
5 T6 n/ E' L* v9 C+ V9 ]4 _' ^应该是
3 l/ A  |0 R$ R6 h3 a4 ^- }5 Hask turtles [/ o- k7 e. ~* m, Z0 L
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
  ~( z& t: Y: n                          set y  Dep / 2
4 C% p3 O: i0 H% x8 x* w' d           set b  int (who / 5) * 5
+ ?5 f3 h- _; K4 [0 I    setxy ( xcor-of turtle b + x )
+ a/ B/ z7 j4 `0 ]6 k5 y          ( ycor-of turtle b + y )]]4 b, F; y* R6 U7 W' V, j) ~
end. @! b& N- ]* H& y8 @7 ~9 _
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-22 22:40 , Processed in 0.021137 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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