设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6796|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。  t" ^* k3 L1 }* K: P

! Q4 F7 `5 ~5 P5 x+ m4 T但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。* R: A$ {7 G5 H3 l# T  L7 f- [
5 \- c1 P, d' S) H" y. m
turtles-own [a b c d k f g h
5 a* V; T5 c+ J  e1 c' d4 ~6 u  x y     ;; these are the leaf-turtle's offsets relative to center-turtle + e' C3 g+ q& `6 g0 d# A# z
]7 ]0 _# h# ^5 _1 f; c4 R7 j
to new
8 u7 \: q' Y5 b. s/ ?  ca
2 V8 I% [, s* L; s) o7 ?$ }( ^, v( |  crt 5 * num_of_building
0 z, C% g0 _  W- ]( j5 o8 A  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
3 G$ E! R& G$ u7 u3 p) d  scatter     ;;keep center-turtle random positions 3 I; I. g. i7 @2 }
  unit_plan   ;;make up the building plan' T2 v7 ^1 V2 Y. F, _& t9 H1 h3 n" `) C
end9 K! r" R0 j+ x4 v7 {# ]6 _: t
to scatter9 P% {, B9 H; B( e7 K8 |
ask turtles with [remainder who 5 = 0]
  G/ y2 d# `$ C  I" f+ P[
; \' Q7 N  n7 {2 A* Gset xcor xcor - 6 + random-float 15
+ P. J" W( h' Wset ycor ycor - 6 + random-float 15
1 G# O  m7 u. C, }6 r# m]* _7 j9 w' n& w5 y$ b
end+ b( ^- Q3 V% _- a+ h7 _2 C) U7 L% J
to unit_plan
2 H9 x' T+ j5 u# Z, eask turtles [
) u4 H! F8 K( o! D* Oif (remainder who 5 = 1) [set a who 4 V6 s5 w, K0 F- D! j' E
                          set x ( 0 - Wid / 2 )
1 g( U; ~9 R5 N: L                          set y  Dep / 2 ]  V) Z+ k0 }/ ~9 v6 ^- w, T
           set b  int (a / 5) * 5
$ t+ x- c9 Y  ~& `9 w: P, v) g    setxy ( xcor-of turtle b + x )
- l3 p  S% O+ b! m          ( ycor-of turtle b + y )
9 L* x# A2 W" p" G4 c+ I8 pif (remainder who 5 = 2) [set c who
. f% V# F  J3 a  W                          set x ( 0 - Wid / 2 ) ; e: D0 v" T6 s
                          set y (0 - Dep / 2 )  ]  S$ k( x3 z4 p7 E. X% B
                          set d int (c / 5) * 5) g& a4 {) z1 X
   setxy   ( xcor-of turtle d + x )
! x; C7 G0 j2 m/ [, H3 Y  n. G           (ycor-of turtle d + y ) ) M  W' |- K# S
         
. D/ q! x) g( T% Q, K            
4 x+ q/ p  x) n& N8 z$ e7 Pif (remainder who 5 = 3) [set k who- t4 b3 y: H" ~; y
                          set x( Wid / 2)  * _( L, v5 ?. g0 A6 m
                          set y (0 - Dep / 2 ) ]4 o* K7 W' n6 c6 w
                          set f int (k / 5) * 5
. L  e2 c5 @) a1 X7 Y6 R9 n* \% F5 n  setxy   ( xcor-of turtle f + x )
8 j/ n+ A, b. V' o! M. b           (ycor-of turtle f + y ) 3 b2 j% ?2 X5 |  P" w) v* s/ b
           
0 p9 d2 L% r9 u  }           
6 y( Q- u  Q3 k" B8 [* }- bif (remainder who 5 = 4) [set g who
) l" ^. V* t5 T                          set x Wid / 2
' K7 F! h- @1 w  q                          set y  Dep / 2 ]0 n5 N: }4 u( J) D) `4 j1 Y' _
                          set h  int (g / 5) * 5, u5 H/ }% |7 i' W5 B7 A& r% T
  setxy   ( xcor-of turtle h + x )9 X$ }( [4 G# V+ w) a2 y! V
           (ycor-of turtle h + y ) 7 d. ]1 M: I8 {9 y0 f
                          
: a! I$ r% h! p3 D$ X: g                          6 a# c7 d, o4 Q# ^+ }" \' C
                          ]
" y% M/ O. \. }1 |end0 _8 w, N2 T# Q  X3 C
) l7 X/ \5 S' h+ J
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,0 x+ V8 A5 ?" X
应该是
1 L3 I! w( K7 m3 b! Q7 ^ask turtles [' K( u9 y; }  {8 v9 K) w4 e, p5 D
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
5 T$ y+ B( x+ E7 V- @: Q                          set y  Dep / 2 : B4 O; O6 D9 ?* R* E
           set b  int (who / 5) * 5
# V) x/ I' u# e+ P/ j% ]( v$ K: m8 ]    setxy ( xcor-of turtle b + x ), a, @+ Q5 J3 a' m! p
          ( ycor-of turtle b + y )]]6 J  I' z4 P. C6 d
end. a. q# m4 b1 L
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-24 05:11 , Processed in 0.019846 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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