设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7064|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。  J* ], S, _2 F, U
& Q7 t  V  n7 r4 ~
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
* d7 }3 Z; N4 e: B9 A0 x' r: T  i7 t
turtles-own [a b c d k f g h5 C2 p3 g7 `7 i" s& Y! y$ ~
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 5 K) V$ Q& u; N8 w8 }8 B4 a
]
! f+ o* k# |$ @, Vto new
3 s$ @$ d9 z9 D; n% U6 Y7 H) k  ca( F: k- c  L  F$ Q) E9 E
  crt 5 * num_of_building* L- d! y  T: J) I( D' l- T$ Z
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
3 Y1 N! B! ~9 g/ j  scatter     ;;keep center-turtle random positions
6 o0 y. P' J- z) j# k  unit_plan   ;;make up the building plan+ ~) p: [9 k, C, {0 B1 [. i( x- e
end! }. F' l1 ]' Z+ h5 c& R
to scatter
% M4 Y' o  \1 p/ bask turtles with [remainder who 5 = 0]
/ @( g& |1 P  o6 Q. L[- R3 }/ L% Z4 @* D! {
set xcor xcor - 6 + random-float 15
+ a$ q) ~3 g/ J( Jset ycor ycor - 6 + random-float 15
( `2 R  Z) w2 _+ r8 b]8 {5 g2 I6 Y9 {/ w* R; u  R, U! A
end' n8 ~# H/ Z9 x2 [4 M
to unit_plan 5 F5 y7 I" f* K. M  `) g
ask turtles [
% d" u: _$ i9 |- Y* m2 E- mif (remainder who 5 = 1) [set a who
6 Q, E& }- x$ c3 j, e                          set x ( 0 - Wid / 2 )
+ t+ W, E  y: _1 v                          set y  Dep / 2 ]
, m) W6 @$ P: Q: Y2 q4 @, |. X: C           set b  int (a / 5) * 5
/ b  Z/ R+ g+ `2 d    setxy ( xcor-of turtle b + x )8 v- K4 J2 d6 o0 B- }: V
          ( ycor-of turtle b + y )
+ |; j0 ~% c' R0 U: E, P7 ]if (remainder who 5 = 2) [set c who
$ Z. }1 j% D. y# @                          set x ( 0 - Wid / 2 ) 2 x) ]- ?" Q6 t
                          set y (0 - Dep / 2 )  ]
5 R% t0 T8 [8 F4 f9 `* b/ {                          set d int (c / 5) * 5
- V: C) U2 O+ i+ Q   setxy   ( xcor-of turtle d + x )
9 z* i2 r- c3 P! |: G9 h4 X. d           (ycor-of turtle d + y ) 6 c- J2 v. t  _2 H) ~, I% W: K, M* u( d" z
         
# _& o1 {1 v2 G) L            2 {5 M' p* {' |- b8 f; R
if (remainder who 5 = 3) [set k who
0 o+ ^3 B/ v% r8 d* Z% q8 b                          set x( Wid / 2)  
0 r) j% R) H' n- ^                          set y (0 - Dep / 2 ) ]9 }: X: \& c0 K; y+ ?# j
                          set f int (k / 5) * 5
) m- i! n7 O# t" c5 Y. u  setxy   ( xcor-of turtle f + x )1 _9 N2 b! t/ l2 {* u
           (ycor-of turtle f + y )
# H5 W; F; G( W5 o  K           ) o& V+ J9 g! b' K/ u
           ! N( I' \( a. Q; P5 a
if (remainder who 5 = 4) [set g who
1 G! D' q+ D, z                          set x Wid / 2 1 f& T7 ~" ?, q% j; H4 R5 q
                          set y  Dep / 2 ]' Q3 q, d  j( C* h
                          set h  int (g / 5) * 5
; ~* W- ]' X, ]9 e) y  setxy   ( xcor-of turtle h + x )- i5 |( f* W6 k  W
           (ycor-of turtle h + y ) & ]. Q( ]  H" d. s/ `
                          $ L/ `" }& i) j; j
                          4 l4 R( R/ R% G$ g/ k
                          ]
5 I( Y2 U- i. C3 a, a* E; pend
  ]! p2 L' P! S
/ c8 D" X' n6 O2 [& |[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
" K* X* h, q! A' \0 r" m: m; P应该是
( Y* [  \6 [7 R3 ]ask turtles [" B: D6 M) T6 j
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) * U3 G+ Y' T4 \/ |2 c. Y# v
                          set y  Dep / 2 4 j8 U" J% @8 J
           set b  int (who / 5) * 5' @% O' [9 L' E! h
    setxy ( xcor-of turtle b + x )
8 k; g$ T4 }( O5 O) I          ( ycor-of turtle b + y )]]
. H" v' ^) E+ pend
. e. A1 b( c, n0 w之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-24 10:25 , Processed in 2.032101 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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