设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6768|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。1 k1 P1 N0 n3 J* w3 P" i" ~4 z7 o

& |5 y5 r, n; ~! p8 x7 O! S: N& i' Q" r但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。5 Y+ C, G( l$ g8 ]8 m4 E
3 U& W; e# h( [  J
turtles-own [a b c d k f g h
& y& h+ U1 g% g( u8 w4 h7 G1 Q  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ( N9 @7 i) q9 c8 d6 w& Z& C3 D
]( l2 h% u( N# u
to new$ b# d1 r  \$ y0 F
  ca" r6 P! F6 Y  |' R
  crt 5 * num_of_building0 {9 f! v. V8 R2 u7 V# j( t$ ^1 V
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
) I3 B3 y* V6 _3 ]0 ~+ r0 y  scatter     ;;keep center-turtle random positions % v1 B4 Y- r3 p0 |, b. _
  unit_plan   ;;make up the building plan2 u; `+ w" N2 J4 Q& M# Q' m, W
end2 [2 H7 C& w1 f& A
to scatter4 H; {' @/ w' ~; j
ask turtles with [remainder who 5 = 0]
. _) Z& @1 P0 r" q( T3 c7 h5 B5 k) b! A- \[7 k# u  ~2 A  e; H8 R0 v6 g
set xcor xcor - 6 + random-float 15- P) Z+ }" ?6 ]4 I# s! b
set ycor ycor - 6 + random-float 15
- s- ~* e0 \. h]
4 a2 S' B- k( C! w9 jend" F. G# }8 P& G% e/ w) W( t
to unit_plan
! c# {7 n8 Q, m6 @ask turtles [! \3 z5 {1 E9 N+ E4 I  p
if (remainder who 5 = 1) [set a who
+ I3 A4 o1 k8 I/ N9 U5 h, H                          set x ( 0 - Wid / 2 )
6 I: z$ q( Z7 I) P, R6 @2 g* t7 m                          set y  Dep / 2 ]
  h. G) `8 v" P, Z, R           set b  int (a / 5) * 5
: N6 }% A3 W: F5 F. N/ v! d    setxy ( xcor-of turtle b + x ): J" P/ e8 U% V0 K9 s" W5 l
          ( ycor-of turtle b + y )) h+ @" \4 u2 ~! S  S' Z
if (remainder who 5 = 2) [set c who. E# {9 @" Q0 A9 {
                          set x ( 0 - Wid / 2 )
# A# W5 o* V1 M* x* k                          set y (0 - Dep / 2 )  ]
% W' d0 a6 J9 K2 ?                          set d int (c / 5) * 5* o5 H7 c- ~, s5 w9 u1 Q
   setxy   ( xcor-of turtle d + x )% Q. o6 f8 m: p* ^9 m% R& f
           (ycor-of turtle d + y )
6 t# V6 y% T  c4 R  h/ J5 N          7 W( e% k6 A- ?7 E+ \0 B; \
            
, k9 K7 E9 J) N/ p( hif (remainder who 5 = 3) [set k who
  [! i: k# K9 [9 d( l                          set x( Wid / 2)  9 b6 `2 x. m2 Q/ B% ~8 J
                          set y (0 - Dep / 2 ) ]
5 ^/ l, r0 m) ?. a5 s: ^: T                          set f int (k / 5) * 50 g9 p% {' t; d0 i1 `8 H9 j' N
  setxy   ( xcor-of turtle f + x )
$ w5 [9 r2 x# R: I! H           (ycor-of turtle f + y ) 5 r4 H8 }5 }, G" Z% q; v$ v' v3 f
           
; R! D+ x6 v. h! U! ~           
7 T* D. U4 z: `5 k/ V3 Z! h0 S1 lif (remainder who 5 = 4) [set g who# B( D: H6 o3 W7 X0 A/ `  c% I, q
                          set x Wid / 2 * q3 P+ V( r8 s6 j- ~) ~
                          set y  Dep / 2 ]8 x# M6 H1 T6 q0 R  [' \; G8 v
                          set h  int (g / 5) * 5
$ q  G$ x& V& {  setxy   ( xcor-of turtle h + x ): O' \( A5 b. a1 n" o: J' e
           (ycor-of turtle h + y )
2 j9 M: ]$ P& O4 d; q5 |8 X- |                          7 R: t* U, o. @4 i
                          
, i5 x8 M( n3 g7 d2 O                          ]$ u, ~6 R! z, j/ l+ F  @2 {
end
, G2 a8 ^5 v1 `6 Y5 C. J: q1 z; K+ a
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,% x& ?0 h; j* b0 h# K
应该是3 A0 [. V  W' w3 y! N6 c: s+ t/ K
ask turtles [. H% `2 y% ?6 J$ z
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
: I! r1 |8 ~, a/ }  W, p  T2 x                          set y  Dep / 2
4 R, ?0 x* m$ v' f; d4 D& h/ L+ P           set b  int (who / 5) * 5$ Y* D' i0 g; r# p. Q) t( F
    setxy ( xcor-of turtle b + x )
" q% U$ G9 x, t- y4 b          ( ycor-of turtle b + y )]]
. I; i3 A& K( V& y  Aend
! g3 P$ p7 A$ ?# I之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-21 21:07 , Processed in 0.023754 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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