设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8098|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
9 ], l! s9 N1 K) M6 H+ B; ^, ~9 g! b6 P$ x
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。* P- \/ \6 J, T% ?0 e

6 f" M7 i1 m" s3 h" t# nturtles-own [a b c d k f g h7 r4 \* D7 x) J4 h
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
" m  A4 S- H5 w/ t/ h- ?" l]
5 H9 ^( G- j2 ^7 ito new2 Q' d$ Z6 T; U- x+ y% b/ c7 n) s
  ca: s/ E. B' Z% R) a. S: y
  crt 5 * num_of_building
- H- y3 T- d# X! h5 i  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]$ L( c6 U0 m; W  P3 y4 I7 S
  scatter     ;;keep center-turtle random positions ) y# v" F4 Q- X5 W8 a: T. i( b
  unit_plan   ;;make up the building plan1 z! T0 T# U/ F) k; A
end* }* ^5 e4 Q4 V
to scatter
) F( c! F% k- Zask turtles with [remainder who 5 = 0]
: e& h* Y8 i; h  b6 s' S3 @, i. l[" x. r) d0 M9 M/ z4 f$ _
set xcor xcor - 6 + random-float 15) e; \0 x% b4 p1 h6 q8 s* f# Y
set ycor ycor - 6 + random-float 15
$ I! u2 A" ?* l- Z. w]2 x( U0 _3 J8 H7 [
end
- Q; H5 c; g; D( f) C0 |# xto unit_plan # S# [8 H) U! L5 s+ C
ask turtles [) _& D5 \' w4 L  O% n3 h, h, y* i
if (remainder who 5 = 1) [set a who
* S* u3 g" d) P                          set x ( 0 - Wid / 2 ) & Z4 Y& ~4 J/ A0 w+ g
                          set y  Dep / 2 ]
0 C& a" V& y4 u           set b  int (a / 5) * 5( t( d/ }2 r3 o9 V; Z1 t
    setxy ( xcor-of turtle b + x )
9 a2 l/ u8 R  s7 n/ A          ( ycor-of turtle b + y )$ I3 A& ~& R8 O/ b* [
if (remainder who 5 = 2) [set c who
5 d" W( B- G' c+ [                          set x ( 0 - Wid / 2 )
/ [) a  Y9 M3 t0 P% k                          set y (0 - Dep / 2 )  ]
) P" V. T- j- r! h# Y& U" _                          set d int (c / 5) * 5
2 k% B+ [  ^9 o% R7 J   setxy   ( xcor-of turtle d + x )
5 `/ |/ I% a$ U0 C1 _           (ycor-of turtle d + y )   t8 w6 D( Z* {# c' u/ F
          - T  b2 c2 _2 Z5 l2 _2 @
            ) u% F& a* k0 o
if (remainder who 5 = 3) [set k who
- T4 e' s' I' N: o- u0 z( b" {/ X                          set x( Wid / 2)  
& ~! ]) b! B6 H( w+ m                          set y (0 - Dep / 2 ) ]$ o1 {. |0 L( j' l: s' _
                          set f int (k / 5) * 5& S, O5 @% X! L4 y4 X8 Y3 R& p
  setxy   ( xcor-of turtle f + x ), f$ Q; K4 |& l& w8 E: z% w. C! k/ ^
           (ycor-of turtle f + y )
- v7 _, |+ m: C; x- {  j" a5 |7 L           
: x3 Q% E+ n" u, N: ~6 W9 o/ Q; U           
) `  z5 _! p2 F, rif (remainder who 5 = 4) [set g who0 `/ s. k% F( p6 M
                          set x Wid / 2
8 Y8 `( ^$ j3 b  w# j- e) I, X                          set y  Dep / 2 ]2 G# J* D* m, @% S0 o
                          set h  int (g / 5) * 5
" c! \/ u( H" j& K! F$ L& q) |9 ^  setxy   ( xcor-of turtle h + x )
' y, [: w  v: A, p; N2 ~4 ?" v           (ycor-of turtle h + y ) ) C2 r" Z0 b. j: y- |) \; N7 y
                          
7 Q3 ~" D* u8 G3 d& Z                          2 F2 p8 b: q1 i) g4 B! ~" p, n
                          ]3 \$ i; |# ~& J( a; F
end' Z+ o9 s0 B* z  i* Q+ ^

+ h% x2 s7 |, K; b0 Z[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,4 D3 q. V* ]3 L$ p0 m
应该是( b. w; z+ @4 u, `* H
ask turtles [
0 w$ ^) G) q8 c$ kif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ; ^. I7 V. \9 L5 C' f' q+ C
                          set y  Dep / 2
' S* _  u  E" _5 c           set b  int (who / 5) * 5
- x6 E& v) r2 @" q2 \    setxy ( xcor-of turtle b + x )
' @" D! Y: t3 V6 M9 j! S. [5 u          ( ycor-of turtle b + y )]]
" M$ n4 Z0 M9 _' bend
9 i3 s! b5 q% F之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-7 19:12 , Processed in 0.014234 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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