设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6740|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。  N8 @7 ?% W8 I
: ~0 q% o4 L( }
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
. n+ L4 M5 y/ Q( J! T, C- s( b, w* E
turtles-own [a b c d k f g h) h& U9 |. b, T2 s
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
& z" w1 F, n& E]
; G4 Y  T# g4 l4 o" b. xto new
$ \# @6 Q) s  l  ca  E* m  [1 _& f# ]7 j& M/ c
  crt 5 * num_of_building9 S4 F4 Q! |$ ^* N: I+ u
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]' y  j7 J$ P/ @  [: ]7 H- z
  scatter     ;;keep center-turtle random positions
' C5 A* M& D* ^) A- D  unit_plan   ;;make up the building plan9 H3 `: b$ |9 x4 N1 ]" a
end6 e: s$ t3 H/ w5 U) Q
to scatter
$ B! _7 _1 A5 t, task turtles with [remainder who 5 = 0]& f6 x2 K( r- O  L$ a2 c% q- ^# E& T4 E
[) Y" l& \3 T$ X0 a8 H9 ]+ z
set xcor xcor - 6 + random-float 15, l5 i* B5 f" _$ z3 J8 ~- F
set ycor ycor - 6 + random-float 15
' C- f$ D0 o. E]0 A* ~/ R/ A) }. M) W: s& G
end
/ v" ]- j7 N0 q* d4 rto unit_plan
6 y  S: P; y: A: rask turtles [5 r" H; q% V, q! y8 n9 v& R! c
if (remainder who 5 = 1) [set a who ; Z. n) _% `! `, W- X
                          set x ( 0 - Wid / 2 )
! {3 }5 |; |5 k7 x                          set y  Dep / 2 ]$ q' ~3 W. ~& X  K9 O3 v, |
           set b  int (a / 5) * 5
/ b8 J- A7 |4 l. F    setxy ( xcor-of turtle b + x )
/ y5 q& K: H7 H1 c# A          ( ycor-of turtle b + y )
. e# x1 C1 Y; iif (remainder who 5 = 2) [set c who6 ~% c: o' m- K2 u
                          set x ( 0 - Wid / 2 ) . J2 _, T6 B( l, P6 Y2 \& D
                          set y (0 - Dep / 2 )  ]' i% T6 ], Z; z6 v/ |6 R
                          set d int (c / 5) * 5  H7 A' J9 B' a% Q/ O' S0 X% s) Y
   setxy   ( xcor-of turtle d + x )- F2 x6 I/ v: y3 a1 {
           (ycor-of turtle d + y )
* S, M( q7 p3 v          : R5 D& M0 I! f* s) v3 f
            
  [$ T! C5 N% P2 K8 S% L2 \if (remainder who 5 = 3) [set k who3 S$ U) t- c: o- A5 L9 ^/ b, p) v# u8 c
                          set x( Wid / 2)  
4 V! @8 D( ^" y2 R  @; w: p3 l% j, v                          set y (0 - Dep / 2 ) ]
) V" e, h1 c/ _& [                          set f int (k / 5) * 5
+ |$ S$ {* q" _0 ]. U* H  ]% T' x  setxy   ( xcor-of turtle f + x )- C1 D  ^% W. K" d7 L. q
           (ycor-of turtle f + y )
0 b4 D9 C  Y7 i/ b. s3 W1 s           ; u! T; q8 }+ k0 |2 H0 m! ?
           , c. W1 m0 U  \) n$ y2 |( R
if (remainder who 5 = 4) [set g who
3 N- R0 N# l- O4 D/ a                          set x Wid / 2 3 y. i) z. h( E) [$ w% N% d
                          set y  Dep / 2 ]
( ^, u& L0 Z9 s# S. w0 u9 z                          set h  int (g / 5) * 56 Q# L& ?7 w- O4 E4 Y5 e! ?! s
  setxy   ( xcor-of turtle h + x ), x/ O" g  c# r4 q* M. m4 u
           (ycor-of turtle h + y )
  \  j/ u  [1 @, k5 I7 K                          
( H8 O  x  c' F& O2 G* x5 G                          
0 g" e, a7 C; s: u1 R                          ]! k( h" N. U2 I, N; a1 z
end
% O, G" G, `. |
0 V8 ]; ~3 N" P3 P' Y[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,; V, x5 w4 y- B/ {. ]
应该是. p8 V/ k( _, H# L/ _6 E
ask turtles [- E  M6 `" }  F- Y% _( A# _0 _
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) " O( B" D' r  E# M( i6 M6 k
                          set y  Dep / 2   U. ^0 O! G3 P- U: D7 `9 ]- @
           set b  int (who / 5) * 5
4 g" z8 H4 y# E    setxy ( xcor-of turtle b + x )( h) V' i' J' o9 x. J
          ( ycor-of turtle b + y )]]
4 @2 ?" {& P: _( J# U, wend
& }" {1 ]. j" j* m& y/ g9 }' e之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-19 14:22 , Processed in 0.018494 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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