设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8248|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
1 A3 [* c9 |. h9 i
( F5 w0 v* W, W, ^4 w4 H$ k) q但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。4 t6 {5 w" {/ u+ Z) y

# g4 P+ P  Y$ J5 T5 vturtles-own [a b c d k f g h" Z0 p! t. u, _' w
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
% H% L, x) \% Q. e6 n1 S]" ^2 P. i; Y7 x7 T0 p8 I8 w
to new
0 D- H) U; u$ X% R) t# x  ca
! S. H# ~- f( |) B& ?  crt 5 * num_of_building: S; a: c6 u2 D, s- J: K5 k
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
/ t2 X6 j, V7 ~( ?) J2 J& {  scatter     ;;keep center-turtle random positions 0 w" z0 E- M, y. [1 H( @* \
  unit_plan   ;;make up the building plan( W% ~8 U  ^5 L5 O0 X6 K
end
( z2 l" K+ Z( d& t, K& g7 }+ R8 zto scatter
" z2 v" f2 `3 V1 S0 l  W$ [ask turtles with [remainder who 5 = 0]
# t; U4 Q: _3 y' a7 P[
  |' ^8 Z0 d$ v* m5 s( y: cset xcor xcor - 6 + random-float 15% l0 W% q" F  [6 W: F: z. A
set ycor ycor - 6 + random-float 15
2 N7 ~: l1 @2 e" u8 Y: O3 c. x3 F]
8 M$ L. R$ N& F, Mend3 [- \) n9 L( D- s6 v
to unit_plan
( Y& n; s6 h2 f4 T, @' C* Kask turtles [
+ C1 o$ ~1 j. o& P1 l6 x3 \if (remainder who 5 = 1) [set a who & v0 ]: C8 P/ B( n
                          set x ( 0 - Wid / 2 ) 4 y/ i4 E. L( B; [1 [
                          set y  Dep / 2 ]9 q4 s9 c9 _5 S7 }+ D: m
           set b  int (a / 5) * 5
, K5 o/ J5 R* U4 A    setxy ( xcor-of turtle b + x )9 x# |8 l0 m- d( X
          ( ycor-of turtle b + y )) i) U* H+ w+ }) C; O
if (remainder who 5 = 2) [set c who7 V% o$ v  k: M
                          set x ( 0 - Wid / 2 ) 5 T; Z( p6 J( t$ W' ^8 x; {4 }, @
                          set y (0 - Dep / 2 )  ]6 d4 P: H' V. P+ J* U- ?. V
                          set d int (c / 5) * 5, ~7 L# M0 \$ B% W' f& K2 S
   setxy   ( xcor-of turtle d + x )
1 h9 @& ?" k0 P- ~2 p           (ycor-of turtle d + y ) 4 b- ?# [9 T1 N9 |: Y
         
% G# c- p/ t7 [9 n7 H1 ~- L            5 D0 H/ z9 D) T! Z5 Y, v) [5 F  n' ~
if (remainder who 5 = 3) [set k who
6 w6 |* i9 o, L( a% T/ _' I8 n                          set x( Wid / 2)  ) u1 P( w" F4 y/ Q+ A
                          set y (0 - Dep / 2 ) ]
9 N  h0 v2 q. @+ j( ?                          set f int (k / 5) * 50 @) u7 L( V2 u4 q
  setxy   ( xcor-of turtle f + x )2 l$ u5 r' U, L  q/ _/ z: C
           (ycor-of turtle f + y )
" m8 B. o; E: U5 e) W; P& S* d             r% a  Q; q( S* W, i
           $ d, E7 `  E6 Z$ e; M. U8 b& _
if (remainder who 5 = 4) [set g who( q$ W  w6 g3 P2 H) o
                          set x Wid / 2
& K, a1 d8 R4 N7 r$ |% A4 w. ^                          set y  Dep / 2 ]
4 L# A% \( q4 A8 r* O/ d                          set h  int (g / 5) * 51 L2 X* D& t  K4 Q0 r5 L
  setxy   ( xcor-of turtle h + x )
( C4 F3 Y) c9 f* |/ I+ _4 ^* e( A1 n5 F           (ycor-of turtle h + y ) ( ]( `0 a+ t0 R- _- L/ X+ n* h9 t
                          
. A; q) M$ e+ v! r                          
& b$ r9 F6 j& ^0 G                          ]: X( ?8 y; ]- W) `! v4 U
end
9 m- K# }8 I$ t) S9 E
& w7 j( m/ E0 C9 Y3 Y[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,: G3 s8 }" n& V  o0 m) o% u
应该是2 B/ C- j& [: n- ^+ @  K$ n8 F) Z2 E
ask turtles [
5 V. p) P* u2 S6 K  Yif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
/ _/ f" M+ F' P9 _                          set y  Dep / 2
, F6 I4 _) Z" E           set b  int (who / 5) * 57 n( D* }) e& _, H  w
    setxy ( xcor-of turtle b + x )  Z( c4 c4 M- |7 s7 o" N
          ( ycor-of turtle b + y )]], k7 B; _; V1 M% U8 p/ R
end
6 e8 g9 y4 a8 n2 L之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-24 15:41 , Processed in 0.019349 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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