设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7177|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
1 `3 r& Z4 Z1 S4 ~& v  U' }# b
6 S( c9 L' r# I但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。/ z" q9 u) s/ i( J: `0 V4 X! S

7 w- v  o* K2 f8 L: v6 I* zturtles-own [a b c d k f g h
6 t6 E& k( z3 `8 X  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 3 x; p5 n% ~- J- F* `
]/ [5 F7 F. I9 H# r& \* j( T% i
to new& _6 y! h) R5 L$ P; p& H3 }  V
  ca
' _8 F4 x/ [8 m( C5 h  crt 5 * num_of_building
5 ]6 x. M1 g( r1 O) x  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
! I: k9 p7 V% X% a/ e$ N( Q2 T  scatter     ;;keep center-turtle random positions
. m* P2 W) e# R  unit_plan   ;;make up the building plan
: Q5 P- ]' B, A9 Y" t5 e8 Jend
, s& z7 g* f& N  X, f! p8 Ato scatter% a) I3 p* X4 a6 U. p
ask turtles with [remainder who 5 = 0]
, ?4 t, T3 i) B) ]3 H[
! t1 q, Q* d3 Bset xcor xcor - 6 + random-float 15
$ U+ L7 @3 W/ L: E6 C( i- eset ycor ycor - 6 + random-float 15
4 d5 ?# h4 x6 ]- C4 n0 j]
/ R4 ]" m) o' c" G) F; N: kend' j. c2 Y; B+ b) \. Q
to unit_plan
6 G9 ~' i! p% ~ask turtles [) Z) \2 x2 X/ l: ?+ Z3 I
if (remainder who 5 = 1) [set a who : x  r/ I" Y1 q) _$ r  H1 Z
                          set x ( 0 - Wid / 2 )
% w; h1 t5 d7 \9 G$ p% O( Y" k                          set y  Dep / 2 ]
$ M! p& H4 N  |6 T) H$ [0 ]           set b  int (a / 5) * 5: z- c  Q7 |6 h3 c! A2 y
    setxy ( xcor-of turtle b + x )
' y2 O. T1 |9 D% C* q          ( ycor-of turtle b + y )
9 K. |/ x3 N4 wif (remainder who 5 = 2) [set c who7 g, B2 o+ J# \1 x- `4 \7 N+ {
                          set x ( 0 - Wid / 2 )
6 ?7 M. \4 j  ~# g8 F6 ~                          set y (0 - Dep / 2 )  ]8 I2 t) O$ \/ T! T
                          set d int (c / 5) * 5
: O, Y& g* ]9 f: K1 Y   setxy   ( xcor-of turtle d + x )5 |+ o# _2 B/ r( o4 |
           (ycor-of turtle d + y ) & G- b* Z, e1 s8 J% `$ Z& n% F- u" ~
          ) B0 |9 B& d5 ]# V; T3 f/ q% Y
            2 Y! T. y* o0 M0 v1 ~
if (remainder who 5 = 3) [set k who
  N4 B# P7 R  X& X                          set x( Wid / 2)  5 O7 ?: p$ D# k6 @! a  Y' v
                          set y (0 - Dep / 2 ) ]* }0 q0 O# A# C# ?2 _9 d& P/ Y
                          set f int (k / 5) * 5; f9 M% `1 k( _  m7 o% w' ~
  setxy   ( xcor-of turtle f + x )4 m' G0 s6 T" R$ J& s6 p
           (ycor-of turtle f + y ) 4 V# |- D; F/ u9 a) C" Y
           ) _# P/ s7 H8 N
           2 S/ L" h4 F6 o: C
if (remainder who 5 = 4) [set g who
+ m! v: I6 L# f                          set x Wid / 2
% D; N6 p% b: B: C- q; k                          set y  Dep / 2 ]
  E. r* _! H* r7 }4 V. S: Q1 ~                          set h  int (g / 5) * 5
7 G7 x" [  G0 o. L  setxy   ( xcor-of turtle h + x )
! }5 e  Y  C7 x           (ycor-of turtle h + y )
0 }  G9 |3 e: ^9 O: M                          
- v: C# Y+ n% B$ w' W: g                          8 @( G4 \2 L( v1 U: ]$ d0 Q
                          ]* |, D( k) n7 }* G% g
end
" J! n" @4 l2 _: P) C  Q( V6 k/ ]
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,# b8 W5 T' ^0 O3 X$ Y
应该是6 l  H# l1 n* O, b0 @
ask turtles [
2 ?+ P) H' C( T; I( Mif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) + ]% |" j3 z( U  d! u4 f
                          set y  Dep / 2 2 s. w7 J4 L' ]# H4 E  c
           set b  int (who / 5) * 5
+ a9 n4 ?9 t6 v* {* z* p  K    setxy ( xcor-of turtle b + x )" S+ I4 }2 y8 R0 s
          ( ycor-of turtle b + y )]]
+ `  z) r/ J7 w5 |9 ]end
4 E  `8 e3 P1 I8 S7 `1 ^之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-13 20:54 , Processed in 0.017423 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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