设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8195|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
& k1 v3 [  H, i1 v8 s6 W4 ]4 F7 j
. T2 j( o1 K4 D5 |& B3 U但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。0 Z% o. {- e" V# D
9 j5 J) n; g0 D2 J: E; ~
turtles-own [a b c d k f g h
( R- k* l0 _# u7 a: h  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
: u9 O& z; j0 Y2 _: W]
6 f& k/ p: }+ a3 C" ?to new/ I  i' J+ Z+ `; s
  ca
' B) h, j- A- E  crt 5 * num_of_building
- }+ X* C$ u" U3 Z& `  c7 T3 k  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]) w$ P5 b( K0 z) c
  scatter     ;;keep center-turtle random positions
- ^. X; M5 |/ z. ~# R2 r* i4 J  unit_plan   ;;make up the building plan
8 D+ F' u! |8 q" b9 L8 dend
1 z6 `8 z, h, D. \to scatter' K: m1 D/ J# J: V4 k, d0 m
ask turtles with [remainder who 5 = 0]
/ I* P) E5 o# z6 P[# R  B/ D- v/ W
set xcor xcor - 6 + random-float 15
" u" H4 G& S# m5 W& S& nset ycor ycor - 6 + random-float 15
1 P. P4 p, k5 H, N, n+ x. R+ `]
1 U; a% |& |( }* a) p  C% cend0 M3 U' b0 F0 g8 V( r
to unit_plan
* T4 {6 B# j% J4 p& x1 t, {ask turtles [2 A5 T* O! Q! z3 ~; r; v' V
if (remainder who 5 = 1) [set a who
& |9 {$ l3 G! n- j) p8 m                          set x ( 0 - Wid / 2 ) ) |3 I- @( Y* F0 O9 [
                          set y  Dep / 2 ]/ I! X' d4 ^8 V0 |. H% i; k# L
           set b  int (a / 5) * 5
$ s" s7 n" A. o    setxy ( xcor-of turtle b + x )6 D+ `( `: `6 u5 n9 c  w
          ( ycor-of turtle b + y )8 D, U0 g8 W1 L) w2 p6 u1 k3 |$ w+ f  ^# ?
if (remainder who 5 = 2) [set c who9 i& m3 J0 `: g
                          set x ( 0 - Wid / 2 ) , f8 ^: v  R3 R* T' t4 A) Q2 }
                          set y (0 - Dep / 2 )  ]4 F) r3 i: i: Z) N- Y& d
                          set d int (c / 5) * 5
: L( S* O7 b% ]5 g3 S   setxy   ( xcor-of turtle d + x )) i/ ^/ `2 O4 h0 _) j
           (ycor-of turtle d + y )
$ {0 r  W/ v9 ^9 J          5 c" ?8 J- ~% ?: k
            
' x0 T6 G* q/ g6 Jif (remainder who 5 = 3) [set k who
$ J: q2 T4 \( M8 `                          set x( Wid / 2)  
5 w  Z2 W& ~  U                          set y (0 - Dep / 2 ) ]
: J$ }3 k/ U& i* l                          set f int (k / 5) * 53 G, j( _, Y1 h: K& H* d& e4 k+ B2 \
  setxy   ( xcor-of turtle f + x )( Z1 I2 j$ {% B: x& O
           (ycor-of turtle f + y )
) ]* L% P( Z$ ?' Q+ e7 b7 Z1 R           
$ Y# @! R( m- E; ^/ B           
. Q% e/ b/ p- P" e. J6 e3 Xif (remainder who 5 = 4) [set g who& S) }6 _. S' ]* K
                          set x Wid / 2 & y0 [0 y+ T5 x$ k! f
                          set y  Dep / 2 ]
( a) F+ n  w/ ^: a; L8 {0 y- t* o6 t                          set h  int (g / 5) * 5
& }- [( X  W3 [- N4 }- N7 {7 A+ Z  setxy   ( xcor-of turtle h + x )
+ @$ c8 N1 D$ I" J! ^3 i) q           (ycor-of turtle h + y )
% r7 `$ r) ?3 r) S4 K                          
" [# t0 K' h; V! P' M. h                          & U8 G4 g2 y( T% S5 R
                          ]
( Y7 r4 C7 N3 Send& C( i9 f) h, ?. \* ~! }* P

6 B* V. [' d- F[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
4 A: x6 s2 v( }" U+ S应该是" s: \1 Q# J% ~( V+ w" b1 P5 @1 M
ask turtles [
( K% M: @. f  }( Kif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
- p/ [, |, R) v8 A' ^# G0 R                          set y  Dep / 2   p+ `) C0 z: K2 J& k+ d$ p3 l
           set b  int (who / 5) * 5
. @1 x3 M/ q. ]+ B* V    setxy ( xcor-of turtle b + x )$ @! g8 D) v6 _: {3 F1 w3 b* C) a3 ^
          ( ycor-of turtle b + y )]], h2 N. W9 X- P; j
end
' a6 a4 Z  v3 U! H9 Z8 w9 A. V& c之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-17 05:45 , Processed in 0.018501 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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