设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8307|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。6 H3 L) y: ~1 [8 Q/ F. H, P" F
- }- |. E. `; p; `5 m9 n
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
0 _2 Z" m$ o* d  |8 [" ~. @' p% [. G
turtles-own [a b c d k f g h7 d3 B1 g$ A3 w; V% W
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
, T& i; z% i# e# ?]
, z4 D) g- |/ u% b, H1 [& Qto new
- K5 d/ O$ z+ `+ U% ~3 ^5 U  ca+ g( W, `* r  P  _
  crt 5 * num_of_building/ ]4 j' U* [$ y. \# ^' t
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
3 j' g& ?  ~/ D, c% T5 I  scatter     ;;keep center-turtle random positions
  d4 ?7 J: T! m0 V2 ?4 ]  unit_plan   ;;make up the building plan
1 c0 N' W3 M& Z% ^end/ l, `- u+ n7 a. k7 Z& k% D& ^5 F9 E
to scatter
& m4 d' M; X1 Y7 s- O; S" X, iask turtles with [remainder who 5 = 0]  H9 W6 }+ r. F6 Q7 Z, a. T7 \7 h
[
/ g2 h. V& S- k! G8 ?5 @/ qset xcor xcor - 6 + random-float 15" C+ E. c( K9 k6 u4 Z" b% a3 U! [
set ycor ycor - 6 + random-float 15
/ ]2 r0 ?( q9 Z% Q# }]
# ?; D: y* i. Gend' |: W1 K% U; E' z* Q% J3 P
to unit_plan * c5 B- i3 g" I  w' ?) A# o
ask turtles [& {. F0 g5 I1 t4 C/ Q, Z1 n
if (remainder who 5 = 1) [set a who
/ G- i( c, ^) _5 {& w                          set x ( 0 - Wid / 2 )
+ V2 m/ k5 u8 T$ _. N, w% ]+ C                          set y  Dep / 2 ]4 r) o% j* |6 M& T8 T+ ^
           set b  int (a / 5) * 5- y$ X# ^: \8 k1 ?* k
    setxy ( xcor-of turtle b + x )
& p7 M7 O9 e5 l/ C          ( ycor-of turtle b + y )) \' ^( m4 s4 d+ ^. a8 f0 X
if (remainder who 5 = 2) [set c who$ d% @: U  ]0 Z! v5 a* C
                          set x ( 0 - Wid / 2 ) 3 Z3 x  I8 S7 H
                          set y (0 - Dep / 2 )  ]
  B( ?; ~9 l; ~6 A. M( t                          set d int (c / 5) * 5; V# s. a( k8 K& f% D9 v
   setxy   ( xcor-of turtle d + x )
# F+ a8 e3 m; j& g; o" t; i  y6 _8 T) ~           (ycor-of turtle d + y ) ' G& `* v& e) C/ j+ r' Y$ m. i0 _
          1 d& U) f; A2 ~5 Q6 P
            
: s8 A1 H+ `- z0 P4 \  ^( k; W5 Hif (remainder who 5 = 3) [set k who
( G2 s8 \% d+ ?" ~7 m, |                          set x( Wid / 2)  , ^6 }& c8 ~9 r7 ~% ?
                          set y (0 - Dep / 2 ) ]
, ]( B' T0 s7 n. s4 b                          set f int (k / 5) * 5
1 w3 n! Z8 o/ L  setxy   ( xcor-of turtle f + x )
/ B8 {0 s/ S* Z, \! y# q8 I# O# h4 t           (ycor-of turtle f + y )
/ }4 g7 t; a8 b           
! T' R3 N: q8 G' N- L4 D, d( p           
3 M1 G/ R0 I" Z' `7 {, N, _# Tif (remainder who 5 = 4) [set g who$ r; s$ N9 L  d/ F; c% m
                          set x Wid / 2
& x  U  L" F! P4 N% e( U; y7 Q                          set y  Dep / 2 ]
; p5 G; F  x0 m% j                          set h  int (g / 5) * 5
# w6 ~3 Q; B2 z+ c! q) @  setxy   ( xcor-of turtle h + x )
3 s) ?4 s8 N/ R9 R1 o' m- w, s           (ycor-of turtle h + y )
6 c. `# A4 |. E2 I. q- h                          
' h. T8 w( N1 K3 q6 [, a% N                          
, d, p5 }* j0 a9 n8 r1 T6 _9 ^                          ]
/ F) z6 v: t; J6 _+ t3 i- M: Yend' S# P/ P* W% C. k; U

) Y; C+ p: z. B9 V& ~' T' i[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
) Y0 u$ r  ~4 o1 P* H应该是9 U' k5 K* U  J+ P7 _
ask turtles [6 I3 l1 ^( P, n- [# T# Q' v' {
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ; _3 c7 a* n; `& T# m6 n0 [
                          set y  Dep / 2
* j' m& a& H7 |7 E/ i+ Y           set b  int (who / 5) * 5: g4 ~0 @6 F" [- O' Y
    setxy ( xcor-of turtle b + x )
+ [) @7 M9 m2 K$ @          ( ycor-of turtle b + y )]]) I) {8 k; @# A$ F& ?) F! ^$ _1 w& X: q
end
4 b+ G. m! _7 s& h: L之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-4 14:00 , Processed in 0.014791 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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