设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9039|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。9 ~6 L( y1 b* |: h  _
2 O8 K1 r( j6 y9 f  v& O$ ?  b" j
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。2 W4 C. R8 J+ F
1 Y0 E7 K/ S% _4 a( a1 j3 ~' F
turtles-own [a b c d k f g h
, k1 Z: \) k" z- W" o  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 6 Z+ i* g! m8 n$ o* W. k
]0 {% h* `- y7 w( m7 W8 H2 J
to new
0 O) N' S  l1 m' O& a+ v  ca
* @1 @( \: @" D) E  crt 5 * num_of_building  i3 g3 x$ J, r4 A) m3 A" _
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
2 ^! N; ^. @% k! L  scatter     ;;keep center-turtle random positions $ a  Q5 {& S8 c1 O
  unit_plan   ;;make up the building plan
) t" J8 ]3 r3 ^, w5 t: |% ^end
& G1 ^! J+ B4 N+ u4 |0 Y! [to scatter* u: |4 Y! Y+ G* f: Q
ask turtles with [remainder who 5 = 0]$ o0 N0 {) s& S0 v
[
0 c$ P; ]2 P4 U  ]. }set xcor xcor - 6 + random-float 15
! s7 M9 Q# V- h& E$ x! Gset ycor ycor - 6 + random-float 154 D& Z: N! y9 Z- A$ w4 A" L7 I
]+ _+ G0 z: n. y
end" L7 ^3 D$ B6 A4 A3 g# [& R3 B
to unit_plan
1 j. P3 M0 [9 H! M, u* Sask turtles [
- I* y2 S3 x8 [& Q; Uif (remainder who 5 = 1) [set a who $ R8 A" t0 Z  R" w! Y4 R# V: J; {
                          set x ( 0 - Wid / 2 ) $ I4 L' g9 @. u+ Z: r/ d: a' S
                          set y  Dep / 2 ]
9 y7 V* W' S) K7 i$ l: T           set b  int (a / 5) * 5
! ~6 i& d  r- |. _5 @    setxy ( xcor-of turtle b + x )# \4 @) T6 v* t- z3 e6 f& ^  X
          ( ycor-of turtle b + y )
5 }6 g: |) K( {7 v2 dif (remainder who 5 = 2) [set c who% V0 x5 M0 y) V0 a$ c1 @
                          set x ( 0 - Wid / 2 ) & ^3 s1 b$ V9 D1 d% z2 W
                          set y (0 - Dep / 2 )  ]5 z' f8 F5 K4 ]/ I' }( N
                          set d int (c / 5) * 5
& v! F; R: P, s' R8 g3 g   setxy   ( xcor-of turtle d + x )
- {9 r- g# {: z# H" ?           (ycor-of turtle d + y )
3 u4 F7 U7 e/ o9 t4 e9 `! M6 X8 q         
. d, e7 J3 ^) y3 T8 K* a' n3 X            
* k9 H5 f9 L9 i$ b1 e! zif (remainder who 5 = 3) [set k who
6 F7 e* d0 }% r6 y5 g7 V% D                          set x( Wid / 2)  
8 d5 O  K2 h; k8 c+ j7 \% a                          set y (0 - Dep / 2 ) ]9 {- \/ {' B  c4 `& L& o. S/ F, b) |) e
                          set f int (k / 5) * 5
- b+ u5 C* B9 z& Z9 F  setxy   ( xcor-of turtle f + x )0 @/ [9 X9 S* h+ q
           (ycor-of turtle f + y )
+ G6 v  W, u! X$ w* @           
) r! q) R- P7 _8 J$ _5 {           1 t2 l5 a6 p, i7 S/ L
if (remainder who 5 = 4) [set g who
% f2 t) q4 ]" d9 ^                          set x Wid / 2 8 w9 ^& i. F- P1 j
                          set y  Dep / 2 ]
1 U' V  D" O$ m# V5 X                          set h  int (g / 5) * 5
/ I; O. r* R4 I* w9 ]  setxy   ( xcor-of turtle h + x )
' g2 s2 U* J" p% F) `           (ycor-of turtle h + y )
  t7 l- `: H4 q; e                          
3 e& L* D! {8 [8 O3 e# e                          
3 [( d! i7 D! }- I                          ]; ^6 ~, W. U: y2 k: N
end
( D, T1 k9 V! f. [* Y
$ M! W3 Q- Q7 c/ e( Y[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,% g0 _% l/ H% U/ ?5 d1 q
应该是9 E  E. Z& E0 j, d
ask turtles [
7 i8 U) O3 s0 G% b+ Y5 dif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 0 y. y. l7 A3 F0 T
                          set y  Dep / 2
$ |1 Q& G5 e- P, |9 q$ C           set b  int (who / 5) * 5
% @7 t8 Y; C/ E2 _. H    setxy ( xcor-of turtle b + x )$ G% S; ?! b4 e* _/ I& [3 v8 x
          ( ycor-of turtle b + y )]]
3 `! J. [+ Q7 y( E# |& c8 i( Gend; j2 D1 i9 L! f+ x3 w! z7 ~
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-10 13:40 , Processed in 0.018608 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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