设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7314|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
8 X8 S" L- {0 K, J: a6 G  L7 K8 t# Q8 Z$ W
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
4 F4 s3 I; J/ f0 D
1 L- {9 W. L' s, p4 `+ s6 Uturtles-own [a b c d k f g h4 {6 c( x; {7 @
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 2 s9 @% G) c& ^
]
8 E1 F: ~  X4 s8 z& d6 lto new
; `( d1 ]  O6 ?* R  ca
0 E% y* t0 n# }6 g& _4 H3 _  crt 5 * num_of_building
2 n" p; K9 F; U) m* ]3 w& _0 g- m  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]  r* L, ?- F  r+ H, }! X; a
  scatter     ;;keep center-turtle random positions ( }& r( Z% i9 h# h
  unit_plan   ;;make up the building plan4 ?8 D" @% y, o
end1 ~6 b9 X6 P+ f2 h- P# f& g
to scatter; F0 s: r. D, l7 a
ask turtles with [remainder who 5 = 0]9 z. A# }: o# g+ d$ h
[
- S$ I! U4 }: M6 K# r' Iset xcor xcor - 6 + random-float 15
: G, q/ Y* j& g0 @$ Vset ycor ycor - 6 + random-float 15
5 _7 }, N( m) {$ N* t' ]) Y]  y8 P9 `) g7 P4 |" t; Z8 a  Z
end
1 X7 Q6 D$ B  [4 T. Wto unit_plan
% S5 S, q* [6 ?! S) N8 vask turtles [& p. }7 C  W: k& m8 s  d+ D
if (remainder who 5 = 1) [set a who % r9 g& T% u& X' i0 f( V" p
                          set x ( 0 - Wid / 2 )
8 ~$ z" `& W% @3 v* M! i                          set y  Dep / 2 ]7 k4 o) j. a5 s$ V3 J0 G9 L2 G
           set b  int (a / 5) * 57 T* S, n- U1 G6 R) K
    setxy ( xcor-of turtle b + x )2 v' x: B5 w9 m: K" d3 h3 s" l6 s
          ( ycor-of turtle b + y ): p" G/ T5 V; e  D7 B
if (remainder who 5 = 2) [set c who
# }' M8 e& C) r( l0 S4 Z7 P                          set x ( 0 - Wid / 2 ) % R0 _6 W. r4 F
                          set y (0 - Dep / 2 )  ]3 J0 `; t! x4 k. X2 q3 V9 n
                          set d int (c / 5) * 53 _& [: D4 T$ t3 `
   setxy   ( xcor-of turtle d + x )/ A' @4 S2 W. L+ T9 m) M; o- e5 |
           (ycor-of turtle d + y ) , R7 Z$ P) _) _- a
         
' Q' ]( ]7 I' H/ W, B1 S            ( d1 y* \. P5 |
if (remainder who 5 = 3) [set k who
3 s- t, S3 X6 s$ `1 I$ R8 s                          set x( Wid / 2)  
' N, Y) q$ W5 a9 \& ^: [                          set y (0 - Dep / 2 ) ]
" E, `; ]1 z$ L( J9 ]                          set f int (k / 5) * 5) j& o* m" [1 B9 Y
  setxy   ( xcor-of turtle f + x )
0 m" V/ N( m% g  W! c: n7 k           (ycor-of turtle f + y )
# v1 _' p9 z  x           
. h9 a7 D6 ]& I+ ^$ y( X) F. T           
; g/ S& j% X) |/ D( ~1 \if (remainder who 5 = 4) [set g who
; ], W1 `: W" i                          set x Wid / 2 ; x4 h% Y; ~* c5 {7 }. b
                          set y  Dep / 2 ]6 M$ |) i; H( n9 P) A, X
                          set h  int (g / 5) * 5
5 @# ~1 N2 t  z4 A  setxy   ( xcor-of turtle h + x )
2 x' z  Q7 ?, m1 G- ^           (ycor-of turtle h + y )
# g0 Y. C& N6 ]. [                          : x8 \& k4 G1 I! [9 }
                          2 N/ Y1 R) r7 [. T% ~
                          ]" ?, O, ^2 r7 }% q; Y
end( u. a# N2 N" H5 |+ Q# G# W- e7 f
6 D2 H( `* j# i* K5 \* c& N( r
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,; G# `4 P! F* N5 k' f4 @
应该是9 i+ C0 j, Q5 q( s- y7 O9 I/ r9 W
ask turtles [' @& Q0 C  ^8 d, O6 {
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
0 i& l9 }. F6 t  x$ s                          set y  Dep / 2 $ T" K! d( ]1 v4 K' e' a7 m
           set b  int (who / 5) * 5
9 |# J% i" x) }. z# @& z+ x- b    setxy ( xcor-of turtle b + x )! t) z' p6 }! w2 ^) S2 Q5 C" w
          ( ycor-of turtle b + y )]]( [$ x/ Y9 X* m+ y( S8 e* [( p' o
end9 z" C9 r+ _2 \# B
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-28 13:27 , Processed in 0.014199 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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