设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7494|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。; q% q" h) w/ i- W# w
  u# O, j. G4 Z
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。: N1 I4 Z! F/ y- V9 ~
, e  N0 R0 P1 Q% u; l8 w0 V
turtles-own [a b c d k f g h) @% H* P0 E7 ^6 \7 [) K
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
% }, V- E' |& v# ~% R; M]
, H9 g+ b& P9 X4 Lto new
0 v/ J+ W; s, O. g# ~, X# E  ca
; [- w# f/ V. V% ]- G, t0 L  crt 5 * num_of_building
4 ]) l& @' E6 i$ p6 f  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
  t6 r# K7 h( {# f% P0 W1 u  scatter     ;;keep center-turtle random positions ! C- h2 E. c5 j5 U; Q
  unit_plan   ;;make up the building plan+ h7 q: _9 X, A2 X3 [
end. G; K9 o. }- Y/ g$ [( p) O: O
to scatter
/ d8 U/ ~% L# \0 h6 Nask turtles with [remainder who 5 = 0]
( f9 x* @) r6 Q[
8 z+ |" j  o& l: m) oset xcor xcor - 6 + random-float 15! N  c- N8 j' I) ?* b' o1 J$ q
set ycor ycor - 6 + random-float 154 T, a3 n/ \  ~8 \6 M- h
]
( k8 Q, a! h2 N( r( ^( z1 T- zend5 d( F( R! U* g8 ^7 Q: q
to unit_plan 2 w- g) a/ s7 M$ A
ask turtles [
1 m6 P! n$ y. [: A. O2 U3 D- l  dif (remainder who 5 = 1) [set a who " X5 F) C+ Z2 ^* o( |8 y
                          set x ( 0 - Wid / 2 ) & m7 i& s* Y8 A# E6 i6 c
                          set y  Dep / 2 ]! c1 H* I/ F8 `. F
           set b  int (a / 5) * 53 n* v. O) e2 B' B) i2 {
    setxy ( xcor-of turtle b + x )
. j& P3 F9 X9 h- \. m0 a9 q          ( ycor-of turtle b + y )
5 W$ Y7 A% I$ V0 pif (remainder who 5 = 2) [set c who6 l, U) G/ E/ n7 f. i
                          set x ( 0 - Wid / 2 ) : `3 P$ h; b& p  E- w- S
                          set y (0 - Dep / 2 )  ]
! G5 R5 {& ?8 M! N/ q6 }                          set d int (c / 5) * 5
& _/ t! G2 b1 L2 G   setxy   ( xcor-of turtle d + x )8 Y) T0 p7 ~* U
           (ycor-of turtle d + y ) ( e( _- C1 q$ ?4 a* n$ S, E
          / a- b" _# Y( G2 d9 M8 J- ?: f5 f
            ) `5 X* k' c. g& ~
if (remainder who 5 = 3) [set k who
3 R" z5 G$ _, A& I                          set x( Wid / 2)  1 h; n7 p3 Y2 S5 ]
                          set y (0 - Dep / 2 ) ]2 ^9 o, c" w/ c. D' l5 q! {2 ~
                          set f int (k / 5) * 5
; K  B+ X. q9 T  setxy   ( xcor-of turtle f + x ), x$ @5 s4 y4 q( q# |
           (ycor-of turtle f + y )
, {  n/ t" p+ d* l$ k1 [: ~- |           ( Q  T& r" A* L+ _8 ~! D) W2 z
           
% R. e: m) q1 {, A) Yif (remainder who 5 = 4) [set g who
+ ?2 @% _$ \$ G* Z! e  y                          set x Wid / 2
5 G' O+ t* B7 S/ F                          set y  Dep / 2 ]
  ]  `4 l, O7 V                          set h  int (g / 5) * 5
8 h/ J! Q, e5 U* T9 w+ e  setxy   ( xcor-of turtle h + x )3 ~' Z, h' W' U) |$ G
           (ycor-of turtle h + y ) * U" t- H! d% ]
                          
, u* W4 b% x/ r                          ! ]) d3 m. G! A: `; S* V, e
                          ]
  {8 i" O$ ~  M$ R0 C. wend
6 q, T5 c) i8 D' H& U
$ U% G* ]5 U: u7 ~# f1 G/ W[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
8 j6 _6 S- g$ x应该是+ C# [* W) k. w" Y" w3 ^
ask turtles [# C! k5 G4 J4 H( o
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
) u! C  @' l2 a                          set y  Dep / 2 % p" H) M  T8 V; w
           set b  int (who / 5) * 5
( E( S& Z* ^$ D    setxy ( xcor-of turtle b + x )+ Z' G. W+ a# X2 S
          ( ycor-of turtle b + y )]]
0 t% r3 M6 ^9 F& `: R+ a! N# S( O) Mend" u9 x) u, ?/ Q( r) Q
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-18 06:29 , Processed in 0.017228 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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