设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7321|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
4 y2 q" [# {5 x7 k9 B
6 y/ b+ m# ^4 p& }2 |; e: F但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
# r% E, x) A0 l4 o% r7 j8 v
, W1 f$ p2 b0 |3 b5 cturtles-own [a b c d k f g h3 k4 Q8 a5 J8 g5 N: |$ [# @! V1 [% C
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle $ p, b" W/ E, u. U5 e3 L' O& F
]1 v" h7 t4 j) i  S; S
to new! x/ w. M, j6 w
  ca6 @- J8 u( f7 [6 z
  crt 5 * num_of_building
8 z. S( [6 f* g- E# r/ C  E! @  ]  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
% P6 g9 [: L! z- e" L/ }7 H6 l  scatter     ;;keep center-turtle random positions ; _! [( \$ u# v
  unit_plan   ;;make up the building plan
8 V  x7 V1 Z0 y7 P2 s& ^7 ?end
7 L* x: v& M+ K1 H& ?( h/ |to scatter
% l' s* k$ j; i7 W  x, K* Xask turtles with [remainder who 5 = 0]+ [: \% n% T6 |7 d$ L+ g6 i% V+ H" d
[  L. s' o7 h9 Z2 u, W1 V
set xcor xcor - 6 + random-float 15
  q$ L" D: @$ J( t' R0 {set ycor ycor - 6 + random-float 15/ S9 N0 V! k! _- |# b
]
+ g  Z8 ^2 [0 d. ]6 Vend8 ~' g& r7 y* x. H5 t7 |
to unit_plan
! \/ R: t. \) V' h* cask turtles [
" b; U, U9 `( m" }if (remainder who 5 = 1) [set a who
2 f+ r7 c' |4 r. ?# l+ s" O                          set x ( 0 - Wid / 2 )
8 L- c9 i7 W" d% p                          set y  Dep / 2 ]8 O' i) T8 a  N. U. N
           set b  int (a / 5) * 5
3 v: D; D& C0 D4 B3 [8 y! y( _) |    setxy ( xcor-of turtle b + x )8 G4 d1 \2 I! E9 a& y" ?# G
          ( ycor-of turtle b + y )
6 P6 ~! f: T& pif (remainder who 5 = 2) [set c who* a! c% _; \" v8 h! K4 U9 @$ |
                          set x ( 0 - Wid / 2 ) + f- _, C9 [+ W
                          set y (0 - Dep / 2 )  ], M2 \6 \. z0 r2 l
                          set d int (c / 5) * 5, q8 S8 ]4 T8 _) Q" D: ?' Y& _
   setxy   ( xcor-of turtle d + x )
; ?& G9 O$ S$ z& {. s           (ycor-of turtle d + y )
$ j; m$ F9 B( c% w+ e5 J0 X         
2 Z) y0 }. E: }7 {% Z            8 T- @+ f0 |# `' m4 s
if (remainder who 5 = 3) [set k who
. A# ^" v/ L& x* Q* ^                          set x( Wid / 2)  $ h1 b7 {6 y; f1 ~- G; M
                          set y (0 - Dep / 2 ) ]
2 N. l% ~: n2 ]3 {/ O: L; y2 w4 m                          set f int (k / 5) * 5
2 l5 J) {0 s$ d7 K  setxy   ( xcor-of turtle f + x )0 A  h4 g$ n7 _* o
           (ycor-of turtle f + y )
) n; u5 ?! a2 b, d2 R           / P' g9 B6 O5 E3 U) b% R
           
, \+ m5 e1 g) D6 f5 Y+ Rif (remainder who 5 = 4) [set g who8 d9 n3 l5 @9 j6 r+ h
                          set x Wid / 2 7 m3 c' B/ n8 I, J
                          set y  Dep / 2 ]
) ]3 N; [; ]. R' f) N/ U                          set h  int (g / 5) * 5# ]; \5 b, k# g1 c& ~6 Q  c1 E
  setxy   ( xcor-of turtle h + x )8 G- P& o1 L! h0 O! q: l& L: g
           (ycor-of turtle h + y )
" T( L; d8 g! u; R/ P5 }. X8 C0 d9 @                          
* L, C" a' _# W/ |                          
* I" |: v1 R3 s, [5 I                          ]
) k1 M4 }$ j0 d* `end' C0 [. Y- n0 l# F3 J% C2 m
! p- _# Z, [. q* H+ y# w0 q
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了," S+ W: b! L# _8 a
应该是
. R  y$ ~1 e/ v# u( }ask turtles [2 Y" X8 O! d/ z
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
$ d6 E* O2 j6 b& P+ \                          set y  Dep / 2 ( ]  o- {& \2 n3 Z7 H% z
           set b  int (who / 5) * 5
" q1 a/ O+ i  k: @( t1 u    setxy ( xcor-of turtle b + x )
1 L* X8 q4 n  n2 R* ~          ( ycor-of turtle b + y )]]2 ]( M" C6 t2 d+ m8 l9 x9 b+ m
end7 ^6 K& q( g3 [$ i
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-29 07:40 , Processed in 0.014512 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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