设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6753|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。, ^% u  }$ w$ d& y1 x
  M, c  O/ \6 }" Y
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
7 B& ~: R3 i% S) p/ @' \4 a/ M3 ^& b8 H" B  {
turtles-own [a b c d k f g h
. ]2 @; a( g" a! [* A+ _; ~  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
4 d# [+ h) P  F0 L  b]* y  u: P5 X  f" w
to new9 w  Y6 S" F' P) a7 A' v
  ca3 o2 n7 o. E& i& z
  crt 5 * num_of_building$ B' e/ u& W; P! c. [. n
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
& c9 T7 \. C- Y9 w, G2 ^  scatter     ;;keep center-turtle random positions
7 s1 P7 B3 [7 w" y2 r  unit_plan   ;;make up the building plan+ A" X4 I0 h8 m
end8 s- d3 E9 q2 g( R0 f. a
to scatter
& k$ f2 w( c$ O3 Uask turtles with [remainder who 5 = 0]
7 m; m* l. A, V# t' _[
2 m0 |5 ^2 }) Q( Jset xcor xcor - 6 + random-float 152 f7 N/ C4 m- w' Y; k& I
set ycor ycor - 6 + random-float 15* y  {; t/ u2 `. ], W
]. e) T6 v& i: g6 o* U, k
end
  B0 g6 P: t! C) ^' Sto unit_plan
+ m$ h  c9 P% V2 g' fask turtles [
) n' _+ X$ y: w2 zif (remainder who 5 = 1) [set a who ' F# ]3 ?  B/ S* e2 l& h3 m
                          set x ( 0 - Wid / 2 )
0 ~' y& H; ^+ I9 z! N9 j' b                          set y  Dep / 2 ]% _3 p& J# k6 S+ j% K: M
           set b  int (a / 5) * 5
# V0 p3 E' s0 t" }8 k    setxy ( xcor-of turtle b + x )' E: R) c3 U" R, Y
          ( ycor-of turtle b + y )
* c! q! N  p% C' t3 U* V) kif (remainder who 5 = 2) [set c who2 J5 t+ U0 u6 ?# }4 F1 H' o, ]- t
                          set x ( 0 - Wid / 2 )
2 i* ^! N* [! v! u                          set y (0 - Dep / 2 )  ]; s+ i! y& G7 y& W3 p- e9 W: Y8 D
                          set d int (c / 5) * 58 E2 R! q/ h. y8 U- ~
   setxy   ( xcor-of turtle d + x ), T5 ]* T$ S% Q
           (ycor-of turtle d + y ) % o9 H. H) n2 G$ d8 D4 J+ I- V" U9 L
         
5 [% r) I# v; D6 u  M            
1 n( M1 y* p8 a: S) _if (remainder who 5 = 3) [set k who) O  }# v$ `9 d& a* s+ ?
                          set x( Wid / 2)  & g" D1 l) Z/ R& W7 }* ^
                          set y (0 - Dep / 2 ) ]
  `7 n1 u4 Q% \0 ]: L                          set f int (k / 5) * 5
8 _% o* i8 H) l6 o" Q6 X1 O! w% Q  setxy   ( xcor-of turtle f + x )% g5 v7 s: o# X5 d* F2 n
           (ycor-of turtle f + y )
" A3 N8 z4 h$ c5 X3 m- G% z           & Z% Z- j/ [$ o; a% L7 i9 C2 R
           ! Q& b! Z' b6 R( c% E
if (remainder who 5 = 4) [set g who
+ \0 M+ D  e& d                          set x Wid / 2
) L" G  T  P7 S- o7 g! N, f                          set y  Dep / 2 ]* k, c2 N* C' }8 n9 o- W' T
                          set h  int (g / 5) * 5  ^9 g  X' I- B& H# x6 H
  setxy   ( xcor-of turtle h + x )
5 ^3 S5 |' B" R+ y" Q           (ycor-of turtle h + y )
8 Q# ]' d1 `5 B9 \4 u                          - m) R" M% S7 l
                          $ }) x% A' ^6 F
                          ]0 i- `. u% X/ A. o; T: u0 _
end
6 y3 {7 N! x# I: z7 ~9 a6 R
0 U/ l; r/ J0 E& ^! y[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,8 V! Y- C4 V0 r
应该是
4 b; i& u4 I7 g! Z* Vask turtles [9 }# e) I9 [2 u0 L9 ^9 u5 a- i- y
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
$ z% G- P, Z+ z& P# M                          set y  Dep / 2 " `! x6 d1 I* x- X7 I  @1 Q
           set b  int (who / 5) * 5$ P9 E: K4 y3 X/ d
    setxy ( xcor-of turtle b + x )
7 Y& Y9 X1 o$ h9 S          ( ycor-of turtle b + y )]]
" ^5 O1 Z6 f. Q2 M$ Eend7 K6 B* ^+ o3 V& ~
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-21 00:10 , Processed in 0.023497 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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