设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8924|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
0 z: ^& H) H# M" s8 c" [' _
0 ~6 O1 S. l9 J0 O/ X/ a" K但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。& p4 j+ [) ?8 r9 D  q

; S+ D2 I& D, u8 A; Z4 O5 m: u  y) u" Bturtles-own [a b c d k f g h
8 o, h) E, C3 P) J  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
( V* t  w5 s; w# k; q]
, O. G0 E0 ~1 p; Ato new! _9 O; K& L7 N# Y" X
  ca* I1 c; c/ G/ |" V/ E, A) R1 U
  crt 5 * num_of_building
- b* c1 ^) ?: p" ~. @$ [  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]+ a" E; ~) j5 |7 i
  scatter     ;;keep center-turtle random positions 0 |- Q* x. K1 Z' e9 h0 L
  unit_plan   ;;make up the building plan9 D$ I- S1 c7 P% T- N' ]
end& e% K5 `2 T- q% m  S
to scatter( U; U3 j2 B- c3 i
ask turtles with [remainder who 5 = 0]- z7 i+ A% p3 d, C& g
[
9 F& [* w( D% x: H! [set xcor xcor - 6 + random-float 15
" H/ @# [1 G# u- G/ q: F. Kset ycor ycor - 6 + random-float 15, j" T3 `# N  f3 @
]2 R* C5 j" o! j7 I( q  [8 R: v* h+ `
end7 _7 \0 R0 q) T: O3 I
to unit_plan , m' z0 C: X' r* _, {" p, V. \. F
ask turtles [
7 s# x! B: e% Q( F9 l" e% p: aif (remainder who 5 = 1) [set a who # _! o' N! T* A0 E
                          set x ( 0 - Wid / 2 )   N" J/ o; q  ^- Q' u- j
                          set y  Dep / 2 ]4 J1 g) g* a. u0 G7 C7 {6 h% _
           set b  int (a / 5) * 55 `/ ~' T7 C5 j. q
    setxy ( xcor-of turtle b + x )8 c: U# G# B% x' s0 ?9 S6 o
          ( ycor-of turtle b + y )
) m9 E! q3 [  L) u$ f5 Kif (remainder who 5 = 2) [set c who
! E1 J- n  R! W. M& s9 `3 c: g                          set x ( 0 - Wid / 2 ) * [" c3 i6 r! Y8 {
                          set y (0 - Dep / 2 )  ]
+ Y: X; ~7 E# \( K, [+ H                          set d int (c / 5) * 58 o/ X5 m0 \- w' W
   setxy   ( xcor-of turtle d + x )! s- t7 ]: f- D2 N
           (ycor-of turtle d + y ) # {4 l) Y) c* E! ^* l
          / E* ]+ x2 X6 [
            3 c. Q' O1 ~+ E9 _
if (remainder who 5 = 3) [set k who2 K1 i$ i; W+ L& h8 D
                          set x( Wid / 2)  ; {4 g0 \  ]! Z1 x! z
                          set y (0 - Dep / 2 ) ]1 k8 [; E, G' ~% U
                          set f int (k / 5) * 5' V& y1 P* i" i/ Y) X
  setxy   ( xcor-of turtle f + x )
! q% p$ v- L9 k0 @3 @           (ycor-of turtle f + y ) & ~9 ^# U# e0 C4 {5 }
           / g* h) `4 p: A- S! K6 r
           4 B* v( C* S" [. F& Y2 e6 }! V
if (remainder who 5 = 4) [set g who5 b  ^, n- z) _8 V1 A
                          set x Wid / 2 7 r0 f! P# l  |1 ?: f$ E8 {2 h
                          set y  Dep / 2 ]( o7 K  C1 |# ^4 t
                          set h  int (g / 5) * 5/ x/ r9 x( t6 S6 p* x: s: l
  setxy   ( xcor-of turtle h + x )
/ w* \4 O2 u9 s* O7 R, B           (ycor-of turtle h + y )
5 E' y1 X0 s( [* N: p( |                          
- I" i) V& w4 B1 R% F                          # f" G; _0 r, q
                          ]
8 v- t4 R; V! |end* Q: L1 o! Z# p, P7 \9 P4 \
  ~/ S+ H% x2 w+ P/ J; }
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,9 A* e9 Z% J9 X3 W6 w& H4 c; S; G
应该是
3 M$ B  e% S9 Nask turtles [% o5 C5 C4 L7 ?5 U
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
* W% z# O; x1 i+ ^6 s/ M                          set y  Dep / 2 6 Z' Y+ A# y4 D% m! a
           set b  int (who / 5) * 5
" M  ~. x% V* v& S$ R, z. c8 z    setxy ( xcor-of turtle b + x ); R6 @7 ^' O- ]" \2 D
          ( ycor-of turtle b + y )]]
% x! j7 s4 ^7 i- \end6 Q& n# ?: Z) N! N
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-24 21:16 , Processed in 0.015856 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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