设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6798|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
* Q# X- N7 y: k- b6 M' i+ ?8 W5 d* Y9 x
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
: k  b; A" b3 K! O; K8 B
6 n5 ^. b6 c0 A' d8 y% Q! nturtles-own [a b c d k f g h/ s1 `) w0 O! D/ H1 |
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
6 M- W) ~- M* o]$ k7 h3 o7 y. H  Q; B+ N" ?
to new
# U1 a& R) V$ M6 L) ]  ca
7 g# x  h+ ^' W  crt 5 * num_of_building
* V2 b% J; U) Q5 Y5 n+ G$ y  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]1 G7 l- @3 k8 k. B0 D
  scatter     ;;keep center-turtle random positions
" C) b8 j; s) J1 W7 ^: u' M  unit_plan   ;;make up the building plan  T" O6 p/ _' v' Y
end! i5 l0 E& _/ z4 ~
to scatter) f, F* B" N7 l* l" J, U2 k' u
ask turtles with [remainder who 5 = 0]
5 l$ X' n- Y, q! @+ e' o[/ v( @( H* ~, s1 I4 Q. T
set xcor xcor - 6 + random-float 15# y! ?; l# C6 p1 S0 }
set ycor ycor - 6 + random-float 153 K9 U2 e1 `# v" F$ @% C5 B0 y& T; m
]$ W* X0 u# O4 Z& A
end
. u# z3 H5 w0 Rto unit_plan
, R4 ?  l% `! F/ _ask turtles [
5 c8 S6 p6 ^3 t! iif (remainder who 5 = 1) [set a who
) y' U9 r3 o, q  q* W                          set x ( 0 - Wid / 2 )
& [2 c# {* Q4 X                          set y  Dep / 2 ]
+ R: s6 C% y. E8 U8 M           set b  int (a / 5) * 5
9 e' K5 j) u1 u1 `" D& I$ N% a    setxy ( xcor-of turtle b + x )6 O# J+ i' Q  P
          ( ycor-of turtle b + y )3 m( u" O7 N  O' A) m
if (remainder who 5 = 2) [set c who
- x/ \& o8 B3 r                          set x ( 0 - Wid / 2 )   x& `8 a* D% E! B9 P* N
                          set y (0 - Dep / 2 )  ]
0 h% h' }0 i' s9 _                          set d int (c / 5) * 5
0 G" q7 K; M% x4 |2 P   setxy   ( xcor-of turtle d + x )  J$ m6 k3 g8 F$ g" s7 Y" V
           (ycor-of turtle d + y )
4 y; w& v1 q1 C8 a; o" P/ `         
. h$ r: ~. P% o4 A/ k( c            ! C  H0 v. m& `9 i3 e6 |6 h
if (remainder who 5 = 3) [set k who
+ H! g3 ]; w) x                          set x( Wid / 2)  * n: w$ N9 J3 O5 Q7 w
                          set y (0 - Dep / 2 ) ]
+ ?# {& B! o  r/ o) p                          set f int (k / 5) * 5! A% l: O5 `- J
  setxy   ( xcor-of turtle f + x )
3 M5 V* ?  |# y           (ycor-of turtle f + y ) 3 R7 z8 O+ A* J! _4 p' W
           # ~. t3 a' o7 \* \* k# y
           4 P1 l5 I: }% F- J( H- f
if (remainder who 5 = 4) [set g who
/ W; E% h+ A" R3 K9 z/ |" a3 m6 S                          set x Wid / 2 8 }- ?' L. e: I3 _
                          set y  Dep / 2 ]% f2 X) n( e1 G4 F
                          set h  int (g / 5) * 5
$ [; S0 e% Z' T! q5 r( D1 [  setxy   ( xcor-of turtle h + x )1 j: X6 H. Q7 L9 y
           (ycor-of turtle h + y )
- u6 T! N4 K% X7 c$ s2 n  y                          
' \$ q! x( H2 r  E" U3 m$ P                          
) z8 x- ^0 J. q  g; c7 G                          ]
0 H. r3 O/ K: G( k7 L# m) D2 u$ nend, }& {1 a/ j  Q+ u$ ~; a
/ o: }" U8 a2 I) x$ h- P+ A, E
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,. m, h; S* L5 e) y- Q
应该是! e2 h& y1 [+ m9 a3 _' r
ask turtles [
$ c& }) J3 s) T3 ]8 sif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) $ c) C9 w2 d: D8 m! U
                          set y  Dep / 2 ; B. Y& H! K0 D, h7 o4 B9 W
           set b  int (who / 5) * 5- b- y& V6 @! W8 K, e9 j
    setxy ( xcor-of turtle b + x )
0 _6 i# ^% H( m* b* s* e0 {0 Y* g1 F          ( ycor-of turtle b + y )]]
2 F* d3 g! b2 J- b; y. F9 W5 }end. n4 Y2 d7 V; E8 n' a, T$ f( Z& ~
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-24 09:44 , Processed in 0.018688 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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