设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8908|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
" P$ E- N2 j  p& C  D& D% |9 t  j) D6 V5 K5 K
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。7 D* M6 a/ g% |, N( {

8 M1 P  [/ J# i1 \' B' Jturtles-own [a b c d k f g h
5 j$ p! H2 X7 b8 N: S4 y  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
- I4 e" y& s, G- n  N' C]% J/ A/ I  h9 Z& ^' Q0 @7 `
to new
# z  @5 W" T- ~/ {; h% g  ca& M+ D" Q1 @0 w  Q
  crt 5 * num_of_building
" m2 Y7 s: j" z1 g5 R  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
8 e; B6 v/ Z' _8 B8 p  u$ }7 k8 Z+ U  scatter     ;;keep center-turtle random positions - L0 S3 S/ _2 a
  unit_plan   ;;make up the building plan" `# i4 e3 U' j3 q) }, I# \( ~
end
) o6 I- ?7 M" g: \# gto scatter
* C0 m  ~5 ]7 n" N2 W" O6 [ask turtles with [remainder who 5 = 0]
8 ]) |* y% ^9 [8 a( k4 J: W[0 i7 O& @  [3 B& j& `- z
set xcor xcor - 6 + random-float 15/ t5 a7 @- m5 |% K5 @9 k: `3 _
set ycor ycor - 6 + random-float 15
# ^& ?4 S: `' [( m+ C2 k( A& n0 w]
+ s3 C! [8 L4 e4 \8 r; Uend" A# p, d$ v; c; P: C4 J2 s
to unit_plan
( w5 _" k, q- Y; u0 l% }ask turtles [2 D) I  a3 M. v* L1 Y2 B( ^
if (remainder who 5 = 1) [set a who 3 B: ]! m0 h$ Z1 h( d
                          set x ( 0 - Wid / 2 )
5 G; U- B4 T2 Z9 ?                          set y  Dep / 2 ]( w2 T% T3 J% k; l& y' `6 R, Q+ o( K
           set b  int (a / 5) * 5
( c/ e" k7 t! p8 }, c    setxy ( xcor-of turtle b + x )8 s4 y' w5 y( e. a3 l6 H; F
          ( ycor-of turtle b + y )
5 a$ Q8 s8 ^9 i& }$ k' Sif (remainder who 5 = 2) [set c who* c+ L& I- j0 A* p: N2 z; B( k" f
                          set x ( 0 - Wid / 2 ) 3 m' h* K4 n* W8 w4 z+ ~
                          set y (0 - Dep / 2 )  ]4 t' M7 V; Y* a
                          set d int (c / 5) * 5. [: G5 x" y: _, U4 F) a, l* Q+ r
   setxy   ( xcor-of turtle d + x )1 u4 J2 I6 ^( M' r3 j
           (ycor-of turtle d + y )
5 I0 W6 C, ?; f3 Z5 g         
8 {$ e( P& R7 h* \            0 f/ W( d# A0 l4 D. t
if (remainder who 5 = 3) [set k who
6 N2 M3 D1 I* {- f                          set x( Wid / 2)  
$ S2 Y" P. D& ]  ?( Z& J                          set y (0 - Dep / 2 ) ]* f* A( W7 W& k5 b
                          set f int (k / 5) * 5
4 h. B( X2 s# A. x0 d* a  setxy   ( xcor-of turtle f + x ): E. J% Q- }0 u" l, v8 b
           (ycor-of turtle f + y )
$ u5 G) t; T" p- E, e           ( U  d  B* Z5 ]( g
           ( `  C: u" j( Q
if (remainder who 5 = 4) [set g who+ @( r: X) f* }
                          set x Wid / 2
# b# g, B  N3 l  I. L! m/ o, [2 g                          set y  Dep / 2 ]
, m8 s+ x7 w( t; L5 F  U                          set h  int (g / 5) * 5
1 j. j; U! u5 I( d- f- V  setxy   ( xcor-of turtle h + x )
4 x4 \, c4 \) e$ q3 S3 u           (ycor-of turtle h + y ) ; s! i& q* s5 X6 V: `6 \9 z
                          3 Q, @5 P7 l# ~) x( e
                          
; a* ?- X" y: n8 U9 h5 {                          ]3 k6 J6 v9 j. \; I. t+ X
end7 D3 e7 W7 e$ U

# M; q& W# ?* b$ ]. u/ k( P[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
: x' N5 `( t( K: I1 \2 q4 H4 l( T应该是' V/ D9 `3 d: {# ?  N# w
ask turtles [0 v/ b! X; S! G1 I
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 7 h. H; j! ^3 V/ Y
                          set y  Dep / 2 0 \/ i& _$ P' e' U8 s+ V
           set b  int (who / 5) * 5
6 v, x* }. N7 |2 F% v# V% Z% Q6 m    setxy ( xcor-of turtle b + x )& F, q% a- C& y1 H7 p! N2 V2 {
          ( ycor-of turtle b + y )]]
5 ^) P5 i/ U7 m1 l- t1 ~- m6 ?end
$ @4 L; ~# y* n之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-22 02:25 , Processed in 0.015429 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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