设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7582|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
2 D, ]  a6 l# s" M2 p0 T
" ?. }$ n9 y7 q. m3 Z' R  o. [( M: ?2 b但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。7 r0 X; i/ T6 T5 |$ V% V0 P

5 S1 e) A$ G' Z* T, j+ p6 kturtles-own [a b c d k f g h0 `& a% _! f$ ]/ J4 W" m- X7 o
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 4 T1 U' R' ^1 D7 Q
]
+ g7 s2 d6 k3 D. Xto new
4 J& u5 q: z6 n7 u9 e* ]  `# k: e  ca9 O1 c* o* }( b6 h' M
  crt 5 * num_of_building* d0 A* h: e4 p4 l5 L$ I4 Z
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]( e4 Z% K" i1 }$ k* H. v3 h
  scatter     ;;keep center-turtle random positions ! `6 j; x- A$ G8 L& V0 e3 L
  unit_plan   ;;make up the building plan
6 H: G5 o2 H+ P& G, R; Z1 iend
7 H5 J  s( o/ U  ?5 J+ B) ?" n( gto scatter# [5 x3 M, B. B; c4 B1 w* O
ask turtles with [remainder who 5 = 0]
9 h  }& R  ~5 x$ B6 r[. }7 ]6 i9 o, L
set xcor xcor - 6 + random-float 15
" j4 z' U" r* S- v; rset ycor ycor - 6 + random-float 15
& |* D8 b6 Q5 i]4 r, F9 f+ c" l6 j( l0 c+ U
end3 g% M/ x* y2 p* Q8 O% G9 ?5 B
to unit_plan , g( K0 G+ V4 `+ h
ask turtles [/ C0 v, b8 r# f- B! j
if (remainder who 5 = 1) [set a who
0 t- i4 k; s" L                          set x ( 0 - Wid / 2 )
. e. I% N. F5 Y9 ~: N& p                          set y  Dep / 2 ]
* l! R/ K) l7 B/ ~, M           set b  int (a / 5) * 5$ d. q0 }( B# k" s( M
    setxy ( xcor-of turtle b + x )
$ T/ T0 W0 C: t6 ?$ R! C4 y6 V          ( ycor-of turtle b + y ), L! Z, [/ o5 b2 Z
if (remainder who 5 = 2) [set c who
6 q* f  _% V. U                          set x ( 0 - Wid / 2 )
2 o2 O6 U8 f' y6 j                          set y (0 - Dep / 2 )  ]' I1 z5 p4 C2 b5 n( T* h
                          set d int (c / 5) * 5
. X- e. }+ l7 W' A8 j   setxy   ( xcor-of turtle d + x )
" S/ E. B8 J; c) H8 f           (ycor-of turtle d + y ) : n  A9 ?8 U# `
         
- K( y  F# u; `1 A) R$ p2 H; a# u            
/ Z& b) O/ ?0 E4 Aif (remainder who 5 = 3) [set k who
. Q) N  t) p; d. t' r# R& l$ J2 G                          set x( Wid / 2)  
3 d( t+ ~% h" }# M; L4 j                          set y (0 - Dep / 2 ) ]
' t0 z; p& K- b0 Y7 I                          set f int (k / 5) * 5
3 F& ^& E& ^1 M* _6 D  setxy   ( xcor-of turtle f + x )
% O% I3 ?" Q" w           (ycor-of turtle f + y )
/ z) T4 s! u5 F$ v6 [* @           ! q+ e# |: Q+ ]7 t, S& Z( p  V7 j
           
. Q& `- X2 R* |if (remainder who 5 = 4) [set g who
5 S6 G6 D7 \/ D                          set x Wid / 2 % ]) Q' s- e% J3 D$ U
                          set y  Dep / 2 ]
( m; y" e' Y6 b) e- n$ T- P                          set h  int (g / 5) * 52 e! c- ~/ |  ~, b6 Q4 @7 X
  setxy   ( xcor-of turtle h + x )
, N7 m! Q# x( P1 x+ H           (ycor-of turtle h + y )
# x% T" L* I7 [) h) \                          
) k4 b% H' V; t& O$ ]7 k                          
3 V  K. r) `1 S: l                          ]& Z$ t0 S# k& B- ^" P
end6 i+ ^5 o" ]  A$ j
1 u& U. v0 n6 c4 v) n0 j' u" k
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,) p- b# Y: {1 Z5 R
应该是# p+ L8 F" e# k) K2 N: ~- g
ask turtles [& g9 p; ]* p2 C, Y) {6 m$ V( t
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
; {6 N+ X1 n" j8 _! D                          set y  Dep / 2 * G, c( V* X" r, t* n
           set b  int (who / 5) * 5
! G+ E  |+ K' w4 `0 X    setxy ( xcor-of turtle b + x ): @( L" K$ N' r0 i+ \4 h
          ( ycor-of turtle b + y )]]1 E8 @: W. R5 \. E( R
end
) x9 q" X  ?! V  I) Q. `6 Q之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-1 20:53 , Processed in 0.018145 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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