设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7478|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。4 c$ ]; L! ?* A3 P  n5 c( [
* U6 ~( Q+ o! ?$ O
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。0 C! z( Z" B* _3 |9 P$ D( G

& d2 G! U. ^: z' o. k6 tturtles-own [a b c d k f g h
! S: ?; R- A; ?- J+ T  x y     ;; these are the leaf-turtle's offsets relative to center-turtle " G$ B/ o0 P+ f5 L/ N% n+ ^7 i. y! H
]
; e1 W4 z2 ~' g! Qto new
' s, \/ Y/ @, v0 B# b' ^# l  ca9 s2 i- H5 F1 O6 ^* r. l4 t9 I
  crt 5 * num_of_building
# O  T% V+ [3 @6 I6 n2 I# c4 ^  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
; A, L2 u* E6 o) X8 N  scatter     ;;keep center-turtle random positions
& a1 _8 _$ h6 q) W1 O7 G  {  unit_plan   ;;make up the building plan
  q+ O" {: P1 o  _1 u. c9 wend1 b) g- d% q' }; t& d
to scatter9 q8 ]! T3 t( @5 S/ S
ask turtles with [remainder who 5 = 0]
" h- q% l4 H. w9 {1 s/ k[
# {; z% K% W, nset xcor xcor - 6 + random-float 15& @& M( k9 Q& M0 x" {& F3 o
set ycor ycor - 6 + random-float 153 u) T+ `4 C7 U5 H4 V6 H6 a
]
7 f0 [) D& b/ |' oend
4 U, a( K. x* d; |- k0 _3 ato unit_plan % x1 j8 T  A! p' B1 Z! M
ask turtles [7 c  x) f6 D  T
if (remainder who 5 = 1) [set a who , K6 t5 Z5 f; n7 f$ J
                          set x ( 0 - Wid / 2 ) & S6 E# l( G- k& ~; I5 f
                          set y  Dep / 2 ]" g+ v0 n, g" E! |! k, J1 r2 l
           set b  int (a / 5) * 5. [2 K/ E) L9 H6 T* ]) o: g
    setxy ( xcor-of turtle b + x )9 \, s4 ]  s+ B3 S4 E* x& f) O
          ( ycor-of turtle b + y )! O& A0 h5 n0 e8 |
if (remainder who 5 = 2) [set c who
6 l( z6 x, t1 B/ n, S' e$ m% L                          set x ( 0 - Wid / 2 ) , W+ R, r1 z* ?4 Q, I- U- }
                          set y (0 - Dep / 2 )  ]; d2 P: ^/ U' V5 a6 G
                          set d int (c / 5) * 55 V5 n7 K! V, y% K) ?
   setxy   ( xcor-of turtle d + x )
8 @: x% Q9 s1 p8 w% V% z           (ycor-of turtle d + y ) + u- P9 Z+ h9 `- M* [
         
' b( f8 V; r* U- p# K) X            1 w, R, K6 _% k5 J
if (remainder who 5 = 3) [set k who. G( f8 P$ @4 p: I3 g
                          set x( Wid / 2)  0 |0 i8 Q# b, Q0 v
                          set y (0 - Dep / 2 ) ]
) a) m  O; J# M$ y( v  j' b5 h7 |                          set f int (k / 5) * 5
& V* F& E. E7 E+ P  setxy   ( xcor-of turtle f + x )" [0 X# Z4 F8 d
           (ycor-of turtle f + y )
  y" m* m/ U  A0 ?" p           , `% K0 G3 s+ y  C
           
0 |' R; k" t/ oif (remainder who 5 = 4) [set g who, r2 H3 R# s  ~
                          set x Wid / 2
- T7 w* e" ]0 ]" d" s$ j9 o                          set y  Dep / 2 ]7 t& h$ o# z( p* k' y
                          set h  int (g / 5) * 5- h3 R7 N. J* |4 j% W. X
  setxy   ( xcor-of turtle h + x )
7 G7 D; C  Q- x9 \           (ycor-of turtle h + y ) 4 O- `' g0 G5 b" q' b; ]& {1 A5 _5 s
                          0 y, i0 _, N4 x; F6 j1 U9 W8 w
                          
# W  Z* f1 w6 H: |1 m                          ]
6 R0 U5 ]" V! |/ B. n, ~$ xend
. A* @. q  y# v6 P% t/ @* C3 h0 W* ]0 h) S/ u9 d0 r: E
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
3 D* g% [! t7 b8 E5 s, Q) P- z* ?应该是
7 Q, s! t8 M  ~6 l8 wask turtles [/ c) n* E4 o, F3 j
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
) M; h, X  a- E1 K: Q+ C                          set y  Dep / 2 ( E) }( ?; {: u
           set b  int (who / 5) * 5% n" N1 K2 O/ h. N3 l1 s3 ~; r
    setxy ( xcor-of turtle b + x )4 K7 U& d( d1 D( e- o* u
          ( ycor-of turtle b + y )]]
! y4 `. q+ h; x% }7 Zend$ |7 ~  K" Q7 w2 s- Y
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-15 19:57 , Processed in 0.017955 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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