设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7337|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。6 b- T; J4 p( d3 n' q! I
! S7 Z1 r8 q1 f
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
  g  _) b, f( b4 r
7 g3 L6 [7 g1 k, F6 v* Eturtles-own [a b c d k f g h5 C- o1 P# r5 x7 f2 X* ^$ d. E
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
( o5 T% P) a. m/ a0 U* g$ ~% s]
6 ?! d' w- Y/ k/ n* Sto new  \9 r+ t0 L* |  k/ f
  ca6 a& o1 E) s# Y8 h$ u
  crt 5 * num_of_building
( C( I0 {, ]2 ]9 s4 D9 c  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]( m. Y8 ]: I  D& s( |+ X( k- V
  scatter     ;;keep center-turtle random positions 3 g. ^3 v6 e2 r. t" S& X  m! B
  unit_plan   ;;make up the building plan
/ c$ d: m2 L% M' I% _end
* Z* D$ _% V/ mto scatter( G% z$ a" ~2 Y+ K
ask turtles with [remainder who 5 = 0]
7 p8 h/ E* g7 X5 T1 S% D[- v7 \7 {. h5 ?. c% y
set xcor xcor - 6 + random-float 15
' m2 _, @! X( l9 S( wset ycor ycor - 6 + random-float 156 M1 @' X) y' w; Y  h( F
]3 E- w7 O1 J8 g1 X  ]! }+ ^4 g. i( D
end: z. X5 U: X2 ^4 l5 E6 ], m
to unit_plan $ M4 n2 u: u  c# }4 ~2 ]( ^
ask turtles [/ n5 |" d; G6 a: j) `4 v0 h3 N" G
if (remainder who 5 = 1) [set a who . g; m4 C' O. Y2 J4 b
                          set x ( 0 - Wid / 2 ) 5 C# l  {/ w" H) T3 z$ p7 t  H
                          set y  Dep / 2 ]3 x9 F3 c6 _  `( [- |7 u. t( ~
           set b  int (a / 5) * 55 X% D! }( l$ O' w! Q
    setxy ( xcor-of turtle b + x )
  U* ]0 [7 }$ V1 H6 P# o          ( ycor-of turtle b + y )
% g5 P, j) _. @1 S, Yif (remainder who 5 = 2) [set c who% Y" j9 M1 x$ C% I
                          set x ( 0 - Wid / 2 ) 4 d% ^. X3 P2 V  E" m5 G6 @
                          set y (0 - Dep / 2 )  ]" B' ]& g( z% I
                          set d int (c / 5) * 5
4 j& [% D' a0 U, _, W   setxy   ( xcor-of turtle d + x )) a" q0 D, w5 g+ `' |' N6 i8 e0 n7 z
           (ycor-of turtle d + y )
* b9 t. O( C7 x; e$ G+ ?5 b         
  p- r6 t( e/ a. h6 t            ) R1 h6 W: i, b1 K& @& `  t9 D* `
if (remainder who 5 = 3) [set k who; _& \/ M( A# Q' Y
                          set x( Wid / 2)  # j# M; L( t, H. c7 G1 P
                          set y (0 - Dep / 2 ) ]
( D% [) \8 o( K8 S4 H                          set f int (k / 5) * 5
, B) F# s# ]$ G) k1 l# S( }, i: {3 v  setxy   ( xcor-of turtle f + x )
4 b/ G$ {% O6 j           (ycor-of turtle f + y ) 1 y5 R9 m2 F" F& p/ C
           
- ?' E9 L0 ?3 p8 G1 i           
1 N. Z+ B$ S( p8 R" ]' Cif (remainder who 5 = 4) [set g who
5 A5 V: ]5 W. J+ i( D8 N$ c0 T                          set x Wid / 2
3 Y: A& B, S" `/ \                          set y  Dep / 2 ]/ F+ e8 H8 K# a  e( J2 q
                          set h  int (g / 5) * 5* z) E3 f7 }; C9 j; S
  setxy   ( xcor-of turtle h + x )
. n5 Y, h/ j' w% K2 T& k2 l5 \& Y           (ycor-of turtle h + y )
) Z, u6 X0 Q% F/ y% A; k' [                          
7 q2 r% H, m( a                          
/ B7 }. d( J' Z  L                          ]" \: X+ r. n2 P
end
3 c' \6 `6 M3 x8 ^
6 P/ O7 ^  ^/ i[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了," Z1 u5 H* M  S6 J2 u& ~
应该是+ {7 I# s$ a+ A* u+ U. m' @! \8 h
ask turtles [
* V; w  V/ h. U& Xif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
% _4 m: X# w, b) i                          set y  Dep / 2 , m6 l3 z% n4 A0 |$ S: q$ m
           set b  int (who / 5) * 5
. t8 h4 S. K# x* @$ j    setxy ( xcor-of turtle b + x )
, z( O& @, `* H: q0 ^5 Q* H          ( ycor-of turtle b + y )]]
- Z1 @6 J. E. u5 Eend2 P  Z8 D1 p  {* q6 S) U0 Z, I
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-31 02:05 , Processed in 0.016782 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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