设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8340|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
! f- \2 g3 e5 L5 m# }# ~
4 z/ P6 h2 T: t2 H但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
3 Y" w& L. P. }3 ^. `' ?
; _0 ~6 N2 V. G$ d+ J6 t. rturtles-own [a b c d k f g h/ ?5 h- a# h& x
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
3 G8 q: T- Z# u6 C) D]5 ?7 i0 B9 \4 J3 ]$ N% w
to new
6 B7 c  P3 V4 c* ~4 Y6 [* E  ca
* T6 l$ B( c0 E8 O  crt 5 * num_of_building8 m3 E2 g% W" @, l# n; E, }
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]+ g9 o# A  A. p
  scatter     ;;keep center-turtle random positions
6 S" @% \% h4 K+ |) a$ M* i  unit_plan   ;;make up the building plan
0 C# p; ?4 t+ r4 b; yend
( F$ }  I0 g" h* l  K0 O9 Ato scatter8 Q- K& }& `' i3 Z& o$ o
ask turtles with [remainder who 5 = 0]( B0 Z8 ~+ z0 e3 [0 y
[
7 \/ r# r/ o- o' b! P9 a0 Y% kset xcor xcor - 6 + random-float 15
1 b  S4 J, [$ \0 Bset ycor ycor - 6 + random-float 15
) b. [6 a! I, w8 a]
$ c, J& r' w3 T. Iend8 d; U6 X- f+ G( y9 I  S: E
to unit_plan $ E8 b( p; h  Y, {/ B  f; {
ask turtles [
2 M0 N4 C0 k$ I& D# [/ o/ mif (remainder who 5 = 1) [set a who 3 i2 r( q4 N2 P. `; j1 y
                          set x ( 0 - Wid / 2 )
8 ~, u& h2 n, K$ I" ^6 @+ f7 c                          set y  Dep / 2 ]- i# @' c( L* l2 f  [
           set b  int (a / 5) * 5
& J7 h, p" I# |" T' v/ q    setxy ( xcor-of turtle b + x )0 \/ e, w3 @% D" W( O& i2 X. @
          ( ycor-of turtle b + y )* Z; I$ n$ ~  o' ?/ }( Q
if (remainder who 5 = 2) [set c who
9 v- g- I! T$ D( y) u- k                          set x ( 0 - Wid / 2 )
0 q6 R- r, u8 M* A5 ]                          set y (0 - Dep / 2 )  ]/ @) e' x- t: Z" V+ f7 Y/ z$ {
                          set d int (c / 5) * 56 h" S. @5 M2 k* u. E5 h: c9 O$ u
   setxy   ( xcor-of turtle d + x )
8 Y  v0 L6 \+ q/ n- @           (ycor-of turtle d + y ) 2 e; v0 [, ?$ R+ d
          5 p1 p% ~0 b1 H9 u. x/ |) O, F& ^) y
            
4 s7 H! y% A4 E  o! C' y3 S( bif (remainder who 5 = 3) [set k who
% z( ?) Q, V& t  V" y$ u                          set x( Wid / 2)  
7 o) o6 |& {9 e& ]/ l. K                          set y (0 - Dep / 2 ) ]( K  a4 Y% T# d) c4 v: `4 b
                          set f int (k / 5) * 52 Q& j2 K% t* W# d. B
  setxy   ( xcor-of turtle f + x ); u: X& a# T- l9 Q! K: s4 `& u
           (ycor-of turtle f + y ) ; y- g& y! y+ r; }, q
           
7 s# G. S/ }# H+ K8 T           ( e1 O3 D5 C! ^# r$ P8 p4 R
if (remainder who 5 = 4) [set g who8 D' `# u6 X& K3 t) ~9 L
                          set x Wid / 2
. l5 }+ b# ~, f. \0 |8 h1 Y* N" v                          set y  Dep / 2 ]
# Y( ]. d' s7 k% o4 q                          set h  int (g / 5) * 5  }, f! k' I' F- O
  setxy   ( xcor-of turtle h + x )
; U" b% v  G, D; S2 @           (ycor-of turtle h + y )
' `7 d$ W, _% w* h% R                          
! B' Q, B3 e3 p2 }+ @. L* X4 Y; D0 c                          
5 {9 {8 ?! [2 C/ ^0 U- N                          ]0 n# ~0 p  O* K3 F+ ~
end- a+ y: V* ~1 y* I
* ~5 S# O+ n8 B' X$ y7 w/ m5 V3 N
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,) Y( @# ]( ~. T$ f2 R
应该是" i9 P8 k: m  @
ask turtles [
) j/ {8 J: {, q& Y% L! o3 |# bif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
: h; [5 a% O8 P! L                          set y  Dep / 2 6 M7 N( m8 z4 L) j+ M
           set b  int (who / 5) * 5" J5 |7 H. @- o, T
    setxy ( xcor-of turtle b + x )
% D  K; W" a- o" D          ( ycor-of turtle b + y )]], V4 R* I& j% q$ B* i! i' s  S- {' C
end% T7 @7 d( b2 }4 H
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-10 20:24 , Processed in 0.015561 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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