设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7921|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。, k3 L: B7 w0 M9 p( A

9 I- d: X) W- H, U3 E' M2 U) o但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。; s6 R0 c+ c: u

) A6 e0 p4 S7 p8 A; tturtles-own [a b c d k f g h
9 l* a* C3 \; i( l3 K  x y     ;; these are the leaf-turtle's offsets relative to center-turtle - N$ f, k1 \8 l' r' p: r8 O- f
]
/ o; \$ [" ~# c& V, W: ^to new9 h% Y% `9 o, v$ c, Q
  ca1 z* w$ h! M( v1 }2 b7 Y
  crt 5 * num_of_building2 w; b+ Y& G% `
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
/ k& Z1 I+ E1 p: T( D  M  scatter     ;;keep center-turtle random positions 8 l. m' s; {) [' w9 B
  unit_plan   ;;make up the building plan
7 u% Q% c8 `. V! Nend1 c) p/ d* k2 a) I" ~' [" E
to scatter
1 @( s: k7 M  j+ bask turtles with [remainder who 5 = 0]0 q( l, W( E: k' W4 s
[& y& A9 `1 `8 V
set xcor xcor - 6 + random-float 15
$ u' t# h- Y: H0 _1 q7 sset ycor ycor - 6 + random-float 157 \( P3 z" Y0 Z. X4 O; q
]
; ~6 q: Z/ ?* h% q$ r0 Fend& i3 E( Y0 Z: ]
to unit_plan 7 w" q/ y/ E" M+ I% z& X
ask turtles [
! K" C9 X. \7 Z& tif (remainder who 5 = 1) [set a who
1 ~4 a1 ~( s* r/ M% V# D3 h2 P                          set x ( 0 - Wid / 2 )
1 Z1 \4 G$ O' a; s. `6 R4 o* A" p* |                          set y  Dep / 2 ]
6 \# c. B2 S+ B5 w% L           set b  int (a / 5) * 5
" O" Q5 v: d* D1 P5 T2 a    setxy ( xcor-of turtle b + x )( E) k1 I5 D" Q* a9 ?
          ( ycor-of turtle b + y )2 ]0 Q* l  H/ _3 u, p, }8 G
if (remainder who 5 = 2) [set c who
; {9 d: v( _1 |: T! u                          set x ( 0 - Wid / 2 ) 5 u" ?+ [4 ]8 z4 s, L
                          set y (0 - Dep / 2 )  ]/ N: S6 ]: N. }( X+ D* z/ v- k
                          set d int (c / 5) * 59 C9 o( Z9 }" ?" A  A
   setxy   ( xcor-of turtle d + x )
$ e5 n* n9 U6 l           (ycor-of turtle d + y )
' _& u" }3 ^% \( Y) F2 g, w          3 {( o% `7 \8 K* v- h( r
            
1 d! K, U9 c/ A* x! P5 uif (remainder who 5 = 3) [set k who. A8 l, W; _  z' e2 O% b. i
                          set x( Wid / 2)  
: I' Z; B% `  C$ s( T/ G                          set y (0 - Dep / 2 ) ]
* |* t2 }0 d1 p  W" h9 g                          set f int (k / 5) * 5
7 H2 E, t: s9 ]# X% ~$ R  setxy   ( xcor-of turtle f + x )
/ ~6 e: X* T! h% r           (ycor-of turtle f + y ) ) X4 z2 N8 w: ]* P, w
           
- k5 x4 H* y( U           
/ A; t, r+ U7 Cif (remainder who 5 = 4) [set g who* ?8 m2 N# o$ ?. V: m
                          set x Wid / 2 % Q/ U/ s5 ?: d! [
                          set y  Dep / 2 ]
; e! K) G) L& z5 j) P# n- b6 I5 F                          set h  int (g / 5) * 5, [5 p. I- X% [- W
  setxy   ( xcor-of turtle h + x )
; d: K+ _3 r+ ?& \6 V           (ycor-of turtle h + y ) " V: m: T, R1 E" M7 O
                          - S5 g# [+ t  Q9 D- |2 R' B5 D
                          5 H' a, k" o, ~% d
                          ]
! l& i" Q2 k" F$ e$ Wend; H8 U- Q9 G+ l$ P1 F

+ Q# C4 o% D: ]5 p[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
+ j2 l1 {* [: j3 g1 s- D  t应该是8 {+ T2 l$ k, P) k# Q" R
ask turtles [7 a, q# |5 q0 i5 C! z; |% O% K2 m
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
$ E+ U, `% ^) y' w* k; }$ {. Q* v- Q                          set y  Dep / 2
- H! _' u  ]; A/ Q; i5 g           set b  int (who / 5) * 5* l/ o& R2 `/ a: p9 I9 V
    setxy ( xcor-of turtle b + x )
- r$ F0 E% r+ q& @1 B) w$ B4 a          ( ycor-of turtle b + y )]]
1 j- t7 l4 w$ L6 n7 g* iend
+ s/ Q7 N! e7 |! M* w5 Y' Y, n5 [之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-17 23:51 , Processed in 0.015463 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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