设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8515|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。' |8 J1 @8 ~6 h, G

; |1 O1 s" U2 F) H- j/ s- D但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
3 a' Y: `4 Q5 _" q; h' X2 Y0 @5 v9 E  ^+ i
turtles-own [a b c d k f g h8 |2 z, m2 O, T
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
) Y! f  T. r( I7 l! W]
9 q" D' u+ ^) @" |# s; nto new2 i' i) @" m; ?  Y$ }" h+ `
  ca
2 _0 j5 `! p% U, P+ q/ F" v: y  crt 5 * num_of_building
+ @5 f9 O' b- t  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
- b/ B! @5 v" g3 L  scatter     ;;keep center-turtle random positions + }. @. w8 T; H
  unit_plan   ;;make up the building plan6 T+ f0 y' @3 @8 ?" `  t. q9 H5 N
end
( d9 @+ _' w  S3 @  G2 e. Oto scatter+ a, ]$ K, b) S. \
ask turtles with [remainder who 5 = 0]- I' E8 j. B, R3 g& F
[
% H8 O/ r! D0 e9 Lset xcor xcor - 6 + random-float 156 W; o/ k6 _' T! h. j; E8 L
set ycor ycor - 6 + random-float 15
' }3 S  x4 ^, s; i- A2 L]
9 q3 h. }" r5 Y" R9 ]end  K0 }8 }, i8 b: w5 M
to unit_plan
4 {/ m& p' d5 K' e% |$ aask turtles [
+ U3 `) I& Q2 L/ J  Aif (remainder who 5 = 1) [set a who
( N) k9 t6 K% o, n" Q( y3 S                          set x ( 0 - Wid / 2 )
" m& q% P7 D( S4 |6 p7 H0 K                          set y  Dep / 2 ]
- c. J8 |5 _, `  c  ]           set b  int (a / 5) * 5& O& i" W- Z8 D( U
    setxy ( xcor-of turtle b + x )
0 v; n: `4 O  O' X' P          ( ycor-of turtle b + y )8 g* W# ~! Q% l1 s! W& C0 V; Q- w
if (remainder who 5 = 2) [set c who
1 r6 q( K) w6 d. J" ~                          set x ( 0 - Wid / 2 )
: G9 }3 R) z; `$ a4 @                          set y (0 - Dep / 2 )  ]0 r* l: ?0 E. r* r6 l
                          set d int (c / 5) * 5
3 n/ C4 }" U. E6 s* `- f5 k   setxy   ( xcor-of turtle d + x )( e* R/ B8 @- j
           (ycor-of turtle d + y )
1 y# |3 ~) n* b6 Z3 I# `         
. m, @4 \5 V" u6 e/ [& a9 J5 A              B1 n" E. n$ a
if (remainder who 5 = 3) [set k who5 e# m  R  o  X% h4 f3 I( c
                          set x( Wid / 2)  
% V" @" y5 y; P; U/ o3 M                          set y (0 - Dep / 2 ) ]/ T! r' r5 h9 B' U  @; A
                          set f int (k / 5) * 5
1 i; P* w/ ?1 k; O  @/ Q1 R$ m  setxy   ( xcor-of turtle f + x )
* C- [3 W/ w. s8 s: v: k           (ycor-of turtle f + y ) ) U2 m4 p* @1 a) y2 L+ g9 w6 C: v
           ( B9 z9 m0 Q+ n
           
# d4 @. |! b9 R$ L7 F6 K$ Kif (remainder who 5 = 4) [set g who
' d0 q3 Z7 E+ _/ K: p                          set x Wid / 2 1 R/ k' E0 r- o% c
                          set y  Dep / 2 ]
! S# R1 `4 _' c+ n                          set h  int (g / 5) * 5
1 ~  u9 U5 w  z, y* i  setxy   ( xcor-of turtle h + x )
8 p' S+ v- L+ J3 A" y' K0 Q           (ycor-of turtle h + y ) ) w, \: Y. `. B* m; Z
                          
  y. K7 [- J  `5 m: _                          
- @5 z/ O, y5 t                          ]
' q) I$ s$ O( U. eend* x+ \2 z: A, p0 |
- A" |! w/ u5 r, b. ?
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
, v! ?3 J9 L, u, R3 j8 ^应该是/ `1 E! o2 Z& B
ask turtles [8 p6 c- t) \3 Q$ O7 |) A; n0 Y2 Q
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
! P( P  x- ]0 S' U0 G! z                          set y  Dep / 2
2 M! ?2 Q+ O( n$ u- S' C# \$ o% s           set b  int (who / 5) * 5. N( r8 U6 ~0 u  P4 @, u
    setxy ( xcor-of turtle b + x ), O7 D" {" J4 K& P
          ( ycor-of turtle b + y )]]
+ M- l# ?, H) H- bend4 ^' l) z  ]* N+ W% b# Q2 C
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-8 23:49 , Processed in 0.015739 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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