设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7274|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。# i  @0 h- h0 D5 C3 D) f# P
$ v8 g+ w5 A7 m! g, W
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
3 s9 n/ z0 S) ]. r# m* L8 D6 z0 o& {& l) s1 n- a2 s1 W
turtles-own [a b c d k f g h
) W. A. O. M, S4 h4 o& f  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 6 d0 x) E  Q# b7 s
], g$ y" g: v* s' \! T* t
to new& s/ R; ~  N1 j% F. G8 `
  ca
+ G% h3 U2 {. C" J: L  R  crt 5 * num_of_building) D/ W! e0 s8 v5 a$ F3 d
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
: S# V2 x4 M4 L5 A0 M  scatter     ;;keep center-turtle random positions . U4 @5 \! L6 w5 n8 g* v
  unit_plan   ;;make up the building plan
7 f% S3 ]' @; o- [3 Y  `2 V2 |end
# g7 @+ [1 i& c9 A! o' mto scatter
0 c3 l, b: u5 R; Z/ Jask turtles with [remainder who 5 = 0]
) ~& U2 l) n2 F7 s; m6 _9 K[
8 f. U4 p7 U0 ]; S- P* h" R3 kset xcor xcor - 6 + random-float 15
% W9 M8 C+ {# p  iset ycor ycor - 6 + random-float 154 v* [2 X+ m1 `' `
]7 W9 ?! Q, Q: \: q- b' v2 N' `
end
% L! x6 T1 o/ l: Lto unit_plan 6 z( K2 \- F6 U8 K. a
ask turtles [
7 t# d" O# U2 q; ?- `1 V7 qif (remainder who 5 = 1) [set a who 7 s, w% f7 m3 J& B7 t- E8 O
                          set x ( 0 - Wid / 2 ) 9 y5 V2 N: O( ?5 N* e5 x
                          set y  Dep / 2 ]9 b, B, A+ W/ k& _+ a
           set b  int (a / 5) * 50 _+ `7 F+ j( M, E5 _4 L* _
    setxy ( xcor-of turtle b + x )1 `2 u0 L2 e' S/ y0 o
          ( ycor-of turtle b + y )7 e& d" {+ Y! }: m8 n' m+ C. ^5 i
if (remainder who 5 = 2) [set c who$ }5 P3 c+ J+ W7 m/ i7 |' l/ M
                          set x ( 0 - Wid / 2 )
" S& A# A( p( R0 I& e2 r: t4 O                          set y (0 - Dep / 2 )  ]" j. d( R) A8 I, `4 r& n
                          set d int (c / 5) * 5# ?1 ?1 z0 q$ ~) m
   setxy   ( xcor-of turtle d + x ); B3 a3 Y  Q+ c" J9 m
           (ycor-of turtle d + y )
! y! C" N; }. T0 D6 l3 n0 s( {1 \          ) D' p) i9 _# A- A! B( [$ X  F
            
2 |' ~; U  N. p1 n+ ]6 Aif (remainder who 5 = 3) [set k who. q1 r8 a  A: Q- K/ j3 p9 t
                          set x( Wid / 2)  
+ i1 w" b% q6 @% q( ~( ]/ u                          set y (0 - Dep / 2 ) ]7 b( k( ?* r$ Y& d, T9 s
                          set f int (k / 5) * 5
7 B% b$ R' c/ ]8 d9 E  setxy   ( xcor-of turtle f + x )9 [$ c- G  Q; R% T
           (ycor-of turtle f + y )
0 T+ f" n# G* J6 L; A           / o3 L( w, r% B3 i% q; e8 W, k
           9 O4 C4 |; X7 ^4 r' O
if (remainder who 5 = 4) [set g who) f5 [4 Y- X% P2 D4 d, ]
                          set x Wid / 2
7 E" r$ j% h. L                          set y  Dep / 2 ]
( d' O% {' z4 L. ^* {                          set h  int (g / 5) * 5
: x6 m3 K. z+ Q* f( \: X0 [  setxy   ( xcor-of turtle h + x )
2 y9 r5 s$ D: Q* L, b. U           (ycor-of turtle h + y )
( {2 h8 f4 h+ y                          
0 r' p2 u3 Y- e& p                          
+ |  N/ [! A, g: @0 i                          ]
. u! K% f& j7 w1 u0 T. Wend
: C' \+ G; e" {8 P1 p% r% x4 V* z4 p/ W5 h7 V' y- g& M* Z0 z
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,4 l6 s- S+ R4 |( i  K4 A' _6 a
应该是
* p& O: @" \( \4 Z& a5 Zask turtles [. q7 m# ?/ C# O% V  V6 @( P
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
! M9 v6 s) I* u0 K                          set y  Dep / 2 3 y, ?; D) Y- G" N( n
           set b  int (who / 5) * 5
9 r4 ^; u! Z& {7 E! G    setxy ( xcor-of turtle b + x )
4 N) h! z( F  y" X1 o& a0 ?& D+ e          ( ycor-of turtle b + y )]]
) I0 U/ X/ x; N9 E: P# J' `3 vend
8 y* L4 D9 K. ~之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-24 02:00 , Processed in 0.021743 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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