设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8083|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
! V8 Y, a- B- A3 m$ F
7 g, S4 ]! J: S, G/ t但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。  G+ t6 r7 `& a3 T; r1 Z
+ s! P# t) }  ]+ z. q+ \0 g7 D, ]$ ]5 A; t8 {
turtles-own [a b c d k f g h8 L9 a9 \  m# n; k" V$ }
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 9 F; m/ f2 t- t* S
]6 X) {$ l" q- h4 ^2 u' s, R9 C
to new
, L2 S* h. g0 X' P1 E* c. D% d5 K* q  ca
5 M- B; j( C5 U" k1 C5 a  crt 5 * num_of_building  x; V4 Z* M: U6 s$ s- h0 O6 C* ]
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]" e0 s7 e8 }4 r
  scatter     ;;keep center-turtle random positions # H( ]& c$ t+ C' e0 K; X' f
  unit_plan   ;;make up the building plan, P. J) G( a* I7 d7 _5 j0 {$ ?
end& M$ `0 I6 j6 n1 y/ k- q
to scatter. z( u! f& d3 F8 E
ask turtles with [remainder who 5 = 0]/ ]& {- n8 `+ k8 |$ U
[
. \! P3 t/ Z6 w" D! }set xcor xcor - 6 + random-float 15
% S) t: o6 n8 y7 sset ycor ycor - 6 + random-float 15
: w) [2 ~9 x' M6 T9 Q2 o( t; |% E/ A% W]
0 s6 |2 _( y, j" o0 s6 C, _  cend
' b" U2 `( a! q2 r. ?to unit_plan * l! l8 i- P+ \, G) P* B3 c
ask turtles [$ ^& y( i. u) |
if (remainder who 5 = 1) [set a who 4 |) c1 M0 U2 w: t- D
                          set x ( 0 - Wid / 2 )   v" F  A+ U& p# x4 g" c, ?$ X- H4 X
                          set y  Dep / 2 ]
% j8 r& W4 r) D3 W' y1 d           set b  int (a / 5) * 5
) x# T! N8 o* R3 H    setxy ( xcor-of turtle b + x )6 x: n& o0 l: R" C
          ( ycor-of turtle b + y )
) H8 a7 R% t3 ^1 n8 [if (remainder who 5 = 2) [set c who
7 O  f3 `5 S8 }                          set x ( 0 - Wid / 2 ) 4 \* o* E( c: I: X5 U' ?
                          set y (0 - Dep / 2 )  ]1 D) w) J8 D' X) A: _* d
                          set d int (c / 5) * 5$ A0 @; v* j: _+ R$ n
   setxy   ( xcor-of turtle d + x )
$ B6 k% l! z: l/ i6 M           (ycor-of turtle d + y )
2 W4 c/ i( A& t/ I% D          " f5 q% j) G: c& p+ a
            $ S3 y' c( i/ \/ U7 Z% j1 Y+ Y
if (remainder who 5 = 3) [set k who3 N1 ?+ t0 Y$ \8 g3 f) p4 `/ \
                          set x( Wid / 2)  2 |' ]% H8 F1 s
                          set y (0 - Dep / 2 ) ]& L$ P3 ]! J9 `
                          set f int (k / 5) * 5
6 k: W; [! ^8 X- b  d) w$ C9 s8 ~  setxy   ( xcor-of turtle f + x )/ q4 k1 b8 B& B9 _- t8 c4 e5 Z# r
           (ycor-of turtle f + y )
  u8 ~* \+ t' V# F6 N2 Y6 z           5 p. }' e2 R1 O# p1 ~8 d
           
' o9 N, S: e2 m1 d3 kif (remainder who 5 = 4) [set g who
4 E7 D: Q0 N/ b5 t                          set x Wid / 2
3 X* z: a+ U7 }                          set y  Dep / 2 ]
* a( ~! Y/ \9 q" t& ^                          set h  int (g / 5) * 50 f; f* [& Q8 D6 \6 }6 J9 k% ~
  setxy   ( xcor-of turtle h + x )
3 G- t+ g2 a1 T/ V5 `           (ycor-of turtle h + y ) * d4 M$ R4 n2 A9 j# H' ~4 _
                          
+ t2 x; ^6 J. z/ l                          9 D, D0 S( _$ z
                          ]0 N3 K& N* r) {9 w' z$ g+ R7 T" o
end
( J- s' g: b# k% o6 ^% e: Q6 s
, M- z7 S  ^3 j[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
" ]" L- n+ m8 \( p应该是0 K# U( K  f% ]& ?! r
ask turtles [
( |- e  k- X% sif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) , z; g+ w7 t! z% W6 ~
                          set y  Dep / 2 " @; S  X$ w( g1 r, z: W9 x' j
           set b  int (who / 5) * 5
3 S" }0 S5 t" `# j- ^% l    setxy ( xcor-of turtle b + x )& _4 R' q. P# N, W
          ( ycor-of turtle b + y )]]# x" _& \( @( F9 \6 o( }6 X
end2 F9 r! |. X- i" |, E
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-5 19:32 , Processed in 0.015991 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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