设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7128|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。( j& ^+ t4 v/ j7 }
$ R! H, z8 y+ G* `* F
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
( n4 b6 j, U; q& L& I0 t) W
& i% {# u/ i2 \2 J2 S5 r& D% ?turtles-own [a b c d k f g h
  f& c) y0 z4 h2 b/ z  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
( _% ~2 f+ c; c+ M]
0 G6 f  V; Z, i1 I5 ^to new8 I+ ^9 \; d( X3 \; h  L* @; M  c' F
  ca8 E7 }6 \5 E/ T" U
  crt 5 * num_of_building
6 E) N1 H% Y3 y4 m8 G  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
: K. c& q2 t1 L+ A  scatter     ;;keep center-turtle random positions
  K9 s* z* z9 f* `  unit_plan   ;;make up the building plan
$ N; K! r* w5 e" d% @. U; xend0 ]% W0 ^! \2 o+ I
to scatter
2 Z* B, \7 Q+ G0 S1 yask turtles with [remainder who 5 = 0]
0 c# r+ l! v7 ^+ _[
9 k/ b" W: r& y) J" h# l" H' ?set xcor xcor - 6 + random-float 15
+ \7 }% V2 ?6 R$ j6 l- V) X0 Wset ycor ycor - 6 + random-float 15
+ W' H1 q8 y: r: e, a3 d; n]& u( G+ q& Y4 n6 A3 B) H* \
end+ u# M/ k! h2 r# D% n- K
to unit_plan $ n$ m; C" d: w: _" T& s3 r
ask turtles [
, L$ }: {& i, y3 I, Yif (remainder who 5 = 1) [set a who
3 x- e, q  o( k                          set x ( 0 - Wid / 2 )
$ b" h( k) F) @2 m                          set y  Dep / 2 ]& _3 r' Y4 e. Y$ F. W
           set b  int (a / 5) * 5! `" M, x0 V' V  p2 z, E
    setxy ( xcor-of turtle b + x )
' k  w8 E$ I7 {# n, F$ N          ( ycor-of turtle b + y )6 b  c8 g# Q9 Q: c0 ]( y
if (remainder who 5 = 2) [set c who, M" ^5 d! D9 k8 K1 k3 i& j
                          set x ( 0 - Wid / 2 )
/ L5 _4 v0 K! M                          set y (0 - Dep / 2 )  ]) s: j3 e8 Q0 [: E. P8 B" V
                          set d int (c / 5) * 5. Q+ m8 \7 D' W0 [7 d# z! e
   setxy   ( xcor-of turtle d + x )
& a( _+ a) [, I% |6 T: H           (ycor-of turtle d + y )   w9 f9 a& q# f
          6 r& J7 R3 i  n- Z/ R
            
1 }: s( D+ x) @: X; Uif (remainder who 5 = 3) [set k who5 g/ z5 u/ I+ O; q* i* |
                          set x( Wid / 2)  ' t& a3 P/ ]$ a
                          set y (0 - Dep / 2 ) ]
, E+ D$ J7 A& i                          set f int (k / 5) * 5
7 h4 Q8 O* _! J+ {( J" n! D+ S  setxy   ( xcor-of turtle f + x )
+ D! k$ D9 W8 y8 z5 D: M% U' p           (ycor-of turtle f + y ) $ C3 i2 F) @. X6 F% k) d: y
           8 p- j, L, k" t1 Q; J6 ^0 O6 ]
           0 J8 [7 _  B0 }% \5 K
if (remainder who 5 = 4) [set g who
' x5 n1 ~/ p+ G1 F1 e$ `2 F, Z7 O5 R                          set x Wid / 2
3 y* Y5 W8 V: o$ S7 L2 g                          set y  Dep / 2 ]
/ Y: W$ _2 g* h4 e. c4 b( {                          set h  int (g / 5) * 5
' E! n) L/ ^8 i$ a( e  setxy   ( xcor-of turtle h + x )
  O# j' ^$ ^( p           (ycor-of turtle h + y )
4 L4 `, R) y3 [4 [4 e% l                          5 X& L4 K  j3 H/ ^
                          
$ J" B* W! @9 o+ n. O  o3 M% ^                          ]) `2 _7 ]& V: K9 Z# F7 M) B
end+ u- L" D8 }- P/ X1 S$ ~

/ _- Y: {1 p! Q0 v4 J[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
8 k5 ^! r3 z7 f& p7 X" h4 U7 k* \! L应该是
: J6 M$ @! s6 ^ask turtles [
  a8 E# y' F, k! b" \) Zif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
; r* v. I* F- f/ R" B) ?                          set y  Dep / 2 * S& B% \/ j- s& n8 s: ?$ W( h# e: o
           set b  int (who / 5) * 55 B5 r4 w( L4 @/ L" P* U8 i  v
    setxy ( xcor-of turtle b + x )
' ^5 Y* X( q7 a! Y9 q          ( ycor-of turtle b + y )]]
+ ?. @) b* f5 I) ], W& `end
) K; f. k% m) n2 T# E+ v" P0 \2 o之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-3 01:19 , Processed in 0.020813 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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