设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7335|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
  R, l$ m. T# G) B  Q- I  e( t# v. Z( d1 X
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
2 ~2 y7 T# ~, ~, w* o, G% P2 q7 _3 P* G" D% z2 _
turtles-own [a b c d k f g h
0 R4 G0 S$ Z- N- E4 W  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 6 V) X0 o4 u. R7 c+ `  r+ v
]* o/ M) i2 ^1 W6 j9 B
to new( y! L& Q/ `6 m) f( m& B8 `
  ca& \: a7 J9 D, B( s0 _
  crt 5 * num_of_building
! ]% f* h# m) S6 }3 I7 w' o( U4 N  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]+ W4 Z0 y" f# E
  scatter     ;;keep center-turtle random positions # J/ x, p9 C0 v$ R  c: Q
  unit_plan   ;;make up the building plan, s0 u0 c, Q' j0 v% p
end: _9 `3 {; p7 X) Z' U! k
to scatter
- F! S$ z5 Y3 C# ]" ?0 v: m' k2 Gask turtles with [remainder who 5 = 0]
0 [- F# D. h0 S) A" h4 q6 m) V) r+ q[. I" x0 j6 N; x5 j0 H& `
set xcor xcor - 6 + random-float 15
7 m9 k0 m# j1 N7 X* z8 x2 ~+ Lset ycor ycor - 6 + random-float 156 L2 \& W9 e+ u( ~% j7 H4 G; E- ^  z
]
2 y0 A5 K$ i" |8 P8 bend
! ^5 j, v( g0 Y2 l1 Zto unit_plan
( N0 \; J8 [2 n  _ask turtles [
* n3 Y5 r8 S6 B1 [: s& A7 Fif (remainder who 5 = 1) [set a who
- I5 H1 l/ A6 U: V                          set x ( 0 - Wid / 2 )
  ]" G# F4 B( t; J. _5 I                          set y  Dep / 2 ]
# v! V0 A. _$ ~. J           set b  int (a / 5) * 5
) @! W/ ^, \) I# U9 N% a    setxy ( xcor-of turtle b + x )  R+ d0 e1 W  i# ?; |3 g2 A
          ( ycor-of turtle b + y )
# W5 ?2 U$ l; ^5 `if (remainder who 5 = 2) [set c who' \6 o8 f: A8 [0 ~& T& L
                          set x ( 0 - Wid / 2 ) : M2 N- d9 N% V! a, E; ^
                          set y (0 - Dep / 2 )  ]
! e! |) P3 D" ~- N                          set d int (c / 5) * 5# V1 {6 t  R5 _$ j4 P
   setxy   ( xcor-of turtle d + x )6 ~1 _0 P  W. G. t
           (ycor-of turtle d + y )
5 r# ?$ @% H/ ~  A" s, Q& b         
0 B5 T3 ?7 Z6 Q1 L# G9 \            
2 T& G. _% y( r$ iif (remainder who 5 = 3) [set k who
9 J3 X6 d7 J6 G& Z7 N* Z                          set x( Wid / 2)  1 P4 |9 ^6 o( ?$ j8 d( X
                          set y (0 - Dep / 2 ) ]
+ x7 _0 W6 Q0 U: S                          set f int (k / 5) * 5( B7 @* s+ q! k; N5 y+ G4 t
  setxy   ( xcor-of turtle f + x )
+ m* t# w* B0 ~6 I! l           (ycor-of turtle f + y ) 3 c; A  ?1 V- g
           " j$ r! C5 }+ n1 \: B# O* z) V
           
4 s- t9 ^+ E9 yif (remainder who 5 = 4) [set g who$ d$ [$ h% y$ Z2 A: V( O
                          set x Wid / 2
) i3 k& p" P' ?8 J$ e                          set y  Dep / 2 ]
( ]+ A( i( z- j3 J! x- o9 Y, m! g9 ?- H                          set h  int (g / 5) * 5
; M7 o" C" `1 C: x  setxy   ( xcor-of turtle h + x )
( h+ ^0 S& E( G, v" t; V, S6 j           (ycor-of turtle h + y )
/ r3 F4 N: H3 I5 l  y" {                          
  u+ I% r" Q. v% D                          2 ]  E3 [- K! g. E  N
                          ]. `: }7 d7 @1 R9 t3 T) k
end
: o  c( k8 A& x# @" q+ i( r# ~4 P' N; V  D
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,+ r2 L1 _0 ?5 L; s
应该是& Y5 a. _9 u4 f8 }- r
ask turtles [) F+ h/ }! d& u1 @( T, ]
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
. y2 S/ Q6 U% O$ @4 f, ^% z  G                          set y  Dep / 2   s  U6 ~" n% p4 N1 j  Q
           set b  int (who / 5) * 5
7 H+ X- P, M7 u% q$ s( A    setxy ( xcor-of turtle b + x )
4 h# J# \% a5 w6 w, V          ( ycor-of turtle b + y )]]; Q7 E1 Z6 ?' t
end4 y* P% L5 Z/ A/ J/ o3 K/ O
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-30 15:28 , Processed in 0.013048 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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