设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8186|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。5 `9 d0 C# [: u* B, B3 C- p

! f/ o7 ^5 u- y7 O/ ?但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。! A: }' l9 A; G

: i3 l4 D% l+ D$ \' Aturtles-own [a b c d k f g h
* J( Q5 I0 Y4 ?' |6 ]& g- I- m9 R  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ) {/ `4 ]& l  X3 K- P5 E
]# u5 C; h; V; ]1 V$ N
to new
7 o# q& r& G9 Z9 Y6 Z  ca6 r( {" y2 @1 F/ B9 r5 j- A
  crt 5 * num_of_building* c* S0 E5 ~2 A) A0 r6 `1 }, P4 a
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
+ W$ `2 h% G& u  scatter     ;;keep center-turtle random positions
% |$ n/ O7 H% i  A0 K9 x+ Y  unit_plan   ;;make up the building plan4 ?5 O; x4 k" E
end3 z0 [: S' k1 E' |) p
to scatter  `! g5 ?9 A: {2 O( |  X3 B
ask turtles with [remainder who 5 = 0]
1 W/ W, J1 S7 `7 s[( ]+ r5 c1 b. R
set xcor xcor - 6 + random-float 15% O. ^4 f) `8 Y! u4 f
set ycor ycor - 6 + random-float 15
& r- i" K1 {8 ~' S" }]0 Y6 q9 y  z% e0 l4 m# T* u
end
% E; z- ?, G# d$ n4 I5 ^to unit_plan
! `4 Y( u+ ~7 T  o  z& Zask turtles [
, e$ V  r% N' u! S) z( aif (remainder who 5 = 1) [set a who
0 C& h$ J: G# f* W' U                          set x ( 0 - Wid / 2 ) 3 R( J& t1 D- m' e: u1 a# o4 P' X
                          set y  Dep / 2 ]
& v# ?" H1 r3 s6 W  M, ^7 M4 r) n- Y5 F           set b  int (a / 5) * 5
' T7 P( |! m% W  [3 E    setxy ( xcor-of turtle b + x )" U( R( W$ [; X+ ]6 @, C
          ( ycor-of turtle b + y )
1 W% C3 ~4 }3 v/ Y& y" t, Uif (remainder who 5 = 2) [set c who* z- W' _' ^% J2 A, X/ E) a7 h: {
                          set x ( 0 - Wid / 2 ) 7 M% p3 s+ f7 V! h+ H% }
                          set y (0 - Dep / 2 )  ]
2 r2 _" k7 @0 M                          set d int (c / 5) * 5
6 I& K9 Q, R, O" c& \   setxy   ( xcor-of turtle d + x )  N3 e5 h( t! f% F
           (ycor-of turtle d + y ) , p9 t6 k) i! M. T1 A
         
: F& N! d. }) w            5 {" N6 A2 @% Z, g9 W# v
if (remainder who 5 = 3) [set k who
  z' P" f% j5 N6 T6 n: F                          set x( Wid / 2)  0 T$ L  l4 c: P
                          set y (0 - Dep / 2 ) ]' c7 {9 o3 _, A
                          set f int (k / 5) * 5
& [  X$ y0 c- G* q- y  setxy   ( xcor-of turtle f + x )3 ^# ?* h: `2 K1 [: c& ?
           (ycor-of turtle f + y )
# `7 z( i0 W/ a2 d2 B' q2 D           8 B9 P% b1 ]5 c
           
+ Z( M" Y6 _3 w* V0 {0 Xif (remainder who 5 = 4) [set g who8 B2 M/ b' x! C$ ^) ^1 U# c0 D" T2 h+ L
                          set x Wid / 2
3 ^. q5 D- y1 n/ _" k: R8 V4 y' d                          set y  Dep / 2 ]; @$ i/ s0 F" D7 }& Z
                          set h  int (g / 5) * 5
, C2 P$ \$ i3 x# B2 e" a  setxy   ( xcor-of turtle h + x ), h7 S# |  i. J0 \! ?
           (ycor-of turtle h + y )
2 a! i# \# k* G* K! A* L! K& [+ O3 l9 ~                          
7 w/ y3 m1 N- G5 Z( c! ~                          
$ T+ ^% j5 Y) n" W1 ]. C                          ]$ G1 C# j* e2 ?' f. w* A
end! z1 E7 K+ ?, M6 J5 x0 j: J
3 D9 T# G6 u8 r2 V2 i
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
2 k! x  ~! U% ]* ]' D应该是
: ?' [& l& Z# Z" l1 y6 task turtles [. V6 z/ Z6 _8 M
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 1 \. }/ y8 h# q
                          set y  Dep / 2
1 Z  i3 q; q! A; ?& {           set b  int (who / 5) * 5  L6 @  l2 ]! D) F+ v9 H2 x
    setxy ( xcor-of turtle b + x )0 O* r5 i8 U0 ^
          ( ycor-of turtle b + y )]]
6 |) ]+ y8 D6 A7 M) o! x1 A3 |end
3 J4 Y; t& s; ?- w7 i9 ~之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-15 22:08 , Processed in 0.017201 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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