设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8832|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
& \/ I! k1 ^: a& P+ O7 {" m+ S% e+ ?% J0 R( a
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。8 c7 o- v7 T. j2 M# k
; c. T9 a1 L: ]( F+ e: b
turtles-own [a b c d k f g h- ~" A8 u5 W. X& O* E2 C# R
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ) a( K9 ?! }, q1 P, w: F. V5 K
], p" _4 V- {3 V4 ?7 z: c
to new' U) K6 B- @6 j6 C. I
  ca
, P% j- T  Z( ~. Z" t9 x  crt 5 * num_of_building
$ o* Y- Z2 X0 Y1 H7 f1 ?3 n  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
1 k! i$ \0 f) r0 C+ v  scatter     ;;keep center-turtle random positions 6 P$ i* G' ~2 {+ X" {
  unit_plan   ;;make up the building plan0 O5 M: h9 U# z: ~% m" R
end+ O2 ~% r7 Z' X# h& G
to scatter% }9 n+ |& t! A) j
ask turtles with [remainder who 5 = 0]9 |7 U* ]; A; X8 o) ^
[* g) C' p, c6 W( c
set xcor xcor - 6 + random-float 15) e/ n" x0 s& q$ E+ h
set ycor ycor - 6 + random-float 15; y; y# Z8 |4 x7 ?
]+ _7 i' @3 H' f+ G6 Z6 ~
end1 W- _2 c6 ~8 C/ t' Q: ]2 s' m# A
to unit_plan * k6 L8 q8 {) r! a6 O' s
ask turtles [
/ H) E/ s. S1 t1 P. }8 D, mif (remainder who 5 = 1) [set a who 5 a0 J$ A4 u0 }3 w) n5 o/ f0 }' s
                          set x ( 0 - Wid / 2 )
9 b+ T1 r4 j' t# W                          set y  Dep / 2 ]) L& Z9 `9 d: `. {0 J
           set b  int (a / 5) * 5
0 h+ L& q( a# h6 f    setxy ( xcor-of turtle b + x )) c. i1 [! T" e8 R6 P9 X% O
          ( ycor-of turtle b + y )( a! f/ H0 a: V) m
if (remainder who 5 = 2) [set c who$ h% z, y. Q5 b* }
                          set x ( 0 - Wid / 2 )
* l0 T  M% [( m, r                          set y (0 - Dep / 2 )  ]6 R! Y9 y0 m% ~
                          set d int (c / 5) * 5. y; b& G+ v* a7 w
   setxy   ( xcor-of turtle d + x )
2 ^% |& j8 @* w+ h           (ycor-of turtle d + y )
& s0 q; L1 [. u1 X6 Q' |         
, O9 q5 l( C' Z* O            ! t; c& p) W* @2 L7 `
if (remainder who 5 = 3) [set k who
( j2 ~9 T8 u6 l* h2 i                          set x( Wid / 2)  ! S7 ]7 R' A9 C" P* V6 o( s
                          set y (0 - Dep / 2 ) ]
+ a4 x( v) G6 S; z' I8 M                          set f int (k / 5) * 5
( S9 `* L% Z- P* j6 i( f& m9 t  setxy   ( xcor-of turtle f + x )8 ^  Y- f" [! P( H4 l! O7 ?
           (ycor-of turtle f + y )
% n' x' h4 F: q' Q  ^           ' s% y) X0 E5 g- o
           1 E2 ?( j- |, r# P  x! L9 v  D, Z
if (remainder who 5 = 4) [set g who8 U3 r" B! ?2 A- @) P, e
                          set x Wid / 2
% ]! s0 ]4 j% U& M+ r0 n+ X                          set y  Dep / 2 ]+ F; `. J. Z: O! m1 ^/ f
                          set h  int (g / 5) * 5* B; f8 r# V$ e: H* b7 x; u
  setxy   ( xcor-of turtle h + x )- y& {; [% h$ a
           (ycor-of turtle h + y )
0 E/ K3 a9 |: f4 ?7 J, c8 ]% ^$ j                          ( `$ f! v6 ?+ ]7 u+ F$ {( h2 E9 Y
                          ! e# u3 n/ l8 u, u
                          ]2 P7 [( ~. }+ L
end
+ J$ G% f2 b# U, V+ ~; n) n3 P8 [7 H+ g' U$ f
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
3 Z% Y3 S& G# t, X% j应该是, H+ |- r5 t9 B6 |
ask turtles [! K* n% _. A/ a- d; {
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
. @& u; a! w0 A; L  ^2 [                          set y  Dep / 2
/ ~, L7 ?3 s1 S/ i  a2 x           set b  int (who / 5) * 5) i0 Y$ L' f- p+ U, p5 y) n0 t8 X' j3 ?
    setxy ( xcor-of turtle b + x )
. S2 t! T1 g1 W          ( ycor-of turtle b + y )]]
; }8 c: @2 p: S0 y0 Uend
1 i/ G1 s# Y$ X之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-9 08:32 , Processed in 0.015279 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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