设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6571|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
2 x  Q1 h* F; k+ d! a
: Q  E) L( y+ N% }/ E/ j8 ^但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。# x, D4 b. \7 |+ |% ~' I0 v

& \' J6 n$ Z  B- h5 J* j, e1 H! `* rturtles-own [a b c d k f g h
# g& ~# [# h# h0 L) K5 {# a  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 5 P: a8 ?7 Q+ O2 C
]& l# @) d, w' B- ~' G: t# V- v. ~3 T5 Q
to new. T5 ~9 k; p; n2 d6 S/ B% a( [
  ca: |) t7 q. |5 k
  crt 5 * num_of_building2 d. c1 X  O# s/ \  v
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]/ E: M' c3 n" T: X1 G! R1 A8 a5 V
  scatter     ;;keep center-turtle random positions
  r0 f$ T/ H& H' H  unit_plan   ;;make up the building plan
# Q) N2 L' Q3 w- I" Uend9 E% k& n# x& ]) i  ]9 R
to scatter7 q/ b9 ?3 D* B
ask turtles with [remainder who 5 = 0]* @8 A+ I! @$ o7 u- ?  q- m
[7 }/ s0 j- Z2 b7 c. H
set xcor xcor - 6 + random-float 15, Q! N' G4 Y: `; Z2 J
set ycor ycor - 6 + random-float 15+ r/ T9 o( z4 L% a- V6 _& b- j2 r
]
9 t) D1 M7 [6 O% e) }' a, |end+ V. m6 k5 k. L; [. m! q5 |5 r
to unit_plan
5 K- m2 Z% h  kask turtles [
0 ]% l( u$ z) k* Wif (remainder who 5 = 1) [set a who $ J; k+ b4 J7 D: M( n- X
                          set x ( 0 - Wid / 2 )
0 B) P# @" ?) Q                          set y  Dep / 2 ]8 a, j( a- o: |+ ]" }
           set b  int (a / 5) * 5
) ]$ W- v3 J& W( m- \. `5 g    setxy ( xcor-of turtle b + x )
% D. O1 ?$ o. d* r% f9 k          ( ycor-of turtle b + y )
/ Z* N9 p0 n# Hif (remainder who 5 = 2) [set c who; a1 R* l5 w$ @. d. K
                          set x ( 0 - Wid / 2 ) 2 ?! d+ Y1 {) M5 [  ^; n
                          set y (0 - Dep / 2 )  ]
; n! |% o! W+ w                          set d int (c / 5) * 5! G- v' l7 V, x2 B# F
   setxy   ( xcor-of turtle d + x )
9 i8 c  D: X! r7 B$ W) x& |" q3 `           (ycor-of turtle d + y )
3 S: ]( ^4 Z- }1 X( Z6 L3 D& K          . @& E4 G+ [% o4 G  z
            
% B( q2 L0 Q' ^0 S6 Q: Q1 Iif (remainder who 5 = 3) [set k who0 L- r+ ^1 a! r, V4 l
                          set x( Wid / 2)  
; a$ b# w, i$ p' S! P                          set y (0 - Dep / 2 ) ]
5 O( M& X; W3 a$ {                          set f int (k / 5) * 5# f( t. R3 m! w4 l' z6 }
  setxy   ( xcor-of turtle f + x )
0 s" [7 e2 k2 U& H; n2 K, Q           (ycor-of turtle f + y )
2 ^0 N( ]" n% S% C) n, Q           
, X: L* y) {$ S           - N5 l  }' G5 O/ l8 i
if (remainder who 5 = 4) [set g who; J% U& Q8 f7 c+ g
                          set x Wid / 2
0 w% j3 d5 k' M4 h3 \7 h! ~                          set y  Dep / 2 ]+ h. L6 C7 Y3 y$ [# ~9 j
                          set h  int (g / 5) * 5+ f) }# w0 |& _
  setxy   ( xcor-of turtle h + x ); J  G0 D3 v, J: l# `! ]
           (ycor-of turtle h + y )
' N/ h4 W6 c6 j. E7 a) e1 @: q                          - B, ^/ B1 s0 C
                          , {6 j0 e+ a2 H! H( B: y- W/ _
                          ]% W7 `( z/ r  P0 N& B
end$ X; n) v4 _$ L/ U6 ^1 g  u
  N* h7 r. \3 m' ~' d3 {* P+ H* y
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
7 j5 v. d6 Q' V2 k  O& ?9 H应该是
* {/ u  P, R! X. z  ^& e/ bask turtles [% {7 k4 m, ]2 l; T7 M
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
0 F- J+ `: l4 k1 y                          set y  Dep / 2
3 T9 z' D- D$ l4 F  Z3 V           set b  int (who / 5) * 59 }# @5 C+ C6 U! X& x0 s$ c, f$ _
    setxy ( xcor-of turtle b + x )0 J1 y$ c7 S9 T8 @4 ]0 P
          ( ycor-of turtle b + y )]]
  Q, c6 I1 O9 r( Q; q! ?5 i- [& Qend- Y0 f9 _) B5 H# L" b
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-10-29 23:59 , Processed in 0.018105 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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