设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7736|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
- b6 Q4 n7 A& x0 F; y7 w9 S7 s2 H9 K/ y' I3 L( N
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
  E! M" L6 ^% ~" R! w9 [
, \* t; O6 \3 Z/ P" v# Bturtles-own [a b c d k f g h
1 c' I1 o) B; j8 n$ ]/ @& g  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ( E0 N2 E9 ^' n3 }" y
]
1 F6 M$ {9 t7 z7 Bto new: l. d2 U) G" v5 K$ D9 V5 `$ V- S
  ca  M- |3 o" ]& ?
  crt 5 * num_of_building
" L8 a3 o  ?1 k& y. v4 ], l  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]/ O! i1 E- y( M# }* O
  scatter     ;;keep center-turtle random positions
& t+ E0 E1 H5 I7 o. {+ F0 K  unit_plan   ;;make up the building plan5 i6 l& D0 \; S) f0 x  S, q2 B
end
% a6 k" Z3 D: v% J, Oto scatter& w! u4 |( O5 G0 y9 m5 Y) e
ask turtles with [remainder who 5 = 0]
; l0 u4 _2 x0 h7 r! Z0 Y[$ {2 w& e" T* q: }. T
set xcor xcor - 6 + random-float 15
+ J5 p$ Y3 t* c1 k3 P7 aset ycor ycor - 6 + random-float 15
1 \4 j$ W1 _( @+ C) I* h/ V% G+ @]
1 n* e$ N2 \$ send- o7 K0 \; Z" t+ Z9 m- F
to unit_plan
% ?( E# R4 C+ Z  ?6 d1 }ask turtles [/ q7 G& i1 Q, `8 Q' Q
if (remainder who 5 = 1) [set a who * f3 B, P  M* c) J+ k* s2 i
                          set x ( 0 - Wid / 2 )
. l, x8 E0 l9 V; j                          set y  Dep / 2 ]
' n9 \$ E0 M5 D) ~           set b  int (a / 5) * 5
1 c% O* G3 `2 C5 A3 m    setxy ( xcor-of turtle b + x )
. v( A& Q7 b) m: p; V          ( ycor-of turtle b + y )
6 B( _# L: A% ~4 ~7 I: ?if (remainder who 5 = 2) [set c who
* ^2 ?6 M: F, d$ @                          set x ( 0 - Wid / 2 ) 2 S2 R6 d& f3 h: `
                          set y (0 - Dep / 2 )  ]# p: X& ^$ `3 M$ W4 B/ `
                          set d int (c / 5) * 5
/ }: b& j1 Y! p4 V& {  H! J   setxy   ( xcor-of turtle d + x )
* I" f% a: ?5 w1 {           (ycor-of turtle d + y )
5 n8 O" G- {, I% y! R3 {         
# K5 N3 r- \& S5 n            , E* C6 I0 ^+ h: F
if (remainder who 5 = 3) [set k who4 G7 W+ Y  B! z/ _8 W% E
                          set x( Wid / 2)  
1 n& h/ y: n0 U- g+ W2 o9 b: k                          set y (0 - Dep / 2 ) ]
: p: k4 h9 N7 ]6 A7 J# Q                          set f int (k / 5) * 58 r3 j0 K9 Z/ t7 U3 `
  setxy   ( xcor-of turtle f + x )
0 E9 L& V* B7 R- I" s4 B( ^           (ycor-of turtle f + y ) 2 w7 S  C( S* c! R9 d* m
           
' q: ?; f2 |7 B           
& V) ?6 D. T3 I" {if (remainder who 5 = 4) [set g who
3 D' U- L7 Y$ ~0 o  _/ X                          set x Wid / 2 ; o3 J' V% T- @' E: i5 H
                          set y  Dep / 2 ]* Z  d% u0 z# j  ^
                          set h  int (g / 5) * 5& w8 e7 P- s3 N
  setxy   ( xcor-of turtle h + x )
. M  h% y& R2 N' I2 _) |& h" h           (ycor-of turtle h + y )
# M: u0 Y- ?: l5 L# D                          : j4 c9 g2 u' ]0 r& |# _
                          
+ E! e9 h/ a% x% Y2 X                          ]9 B4 G7 x6 s' C: f4 l6 _+ j; _
end
  g, a0 C+ _0 W) \) J1 D
, I# E  k0 y) L: ~[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,4 d. r; J( {, p* j9 f6 b
应该是
; X1 B) i; W7 Z& h. f$ j" ~ask turtles [4 f' _/ i! z1 a8 ^# J6 O
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) + r' H3 p; Q) l5 n/ {5 B% ^
                          set y  Dep / 2 3 {8 Q  a5 N3 h3 ^" r$ g
           set b  int (who / 5) * 50 s  l" W6 g) ~$ l! h
    setxy ( xcor-of turtle b + x ), \0 H2 c% z4 B* F
          ( ycor-of turtle b + y )]]0 l3 X" r- W/ F( u  B1 P
end
; q* \% r0 c2 P4 b$ s+ Q, Q: F- U之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-21 08:51 , Processed in 0.017885 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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