设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6820|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。5 \! ^( `' u8 y
, G$ T" [) m* L% @$ P! W
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
  ~: e, L, @6 }  y5 |+ a. q/ I! h, N( a
turtles-own [a b c d k f g h
* r3 m. t7 n# ?  ^$ Z3 `" G  a  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
5 d) x3 Q/ _& l0 A4 t+ j# K$ _. I: C]
! v" x. E" L; {0 F- }2 i6 R4 Ato new
/ a' o+ ^+ R& L- s$ N  ca
8 q) ?5 L7 R+ X4 }, h5 d2 X  crt 5 * num_of_building$ b# l4 k5 _: n$ U2 s
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
9 f6 m3 A  s5 F$ }1 J  scatter     ;;keep center-turtle random positions % v. O2 j) {" p) K
  unit_plan   ;;make up the building plan
* }7 \0 `6 n$ v; D& C5 w7 n2 F' f% mend6 v2 m; N; b6 U+ B$ k
to scatter
% o0 K  {; `$ x. \2 Iask turtles with [remainder who 5 = 0]
  D& O" Z& X. H1 O) Q6 f[" R" j- O( j8 Y1 ]8 b7 N8 I! H
set xcor xcor - 6 + random-float 155 x4 w  r  P$ k2 e8 E# M! m8 d
set ycor ycor - 6 + random-float 15
3 ~9 G/ o/ @+ Y! |' O+ e]- N2 W) q  N% E3 g4 B0 z/ Y7 a; P$ t
end
6 Z6 ^6 D3 l8 j0 T4 c1 qto unit_plan 0 P. {# n/ O! U4 Q2 K) }" G+ Q
ask turtles [
( S* H5 J7 a3 ~- J' \7 p. wif (remainder who 5 = 1) [set a who 1 b1 ]) D0 I/ A6 V
                          set x ( 0 - Wid / 2 )
, [7 I! s  c  v) \                          set y  Dep / 2 ]
: x) `, V' P# Z/ C- j( n- l           set b  int (a / 5) * 5
- J3 G8 C5 Q0 F9 D- H0 j  J/ ]" T    setxy ( xcor-of turtle b + x )4 w* T3 p* ^' K; a5 \. D
          ( ycor-of turtle b + y )5 u; m/ \+ q/ K6 t; B! A1 u1 B: b
if (remainder who 5 = 2) [set c who8 }* d5 |, ~8 ^* n3 E/ Y( N) A) {
                          set x ( 0 - Wid / 2 ) - _9 j9 N/ h: h7 C* l% Q9 P
                          set y (0 - Dep / 2 )  ]& n) b* ]$ A! e" A9 ?5 C
                          set d int (c / 5) * 59 s, F9 ~. |- c  E( N* Y2 M
   setxy   ( xcor-of turtle d + x )! s7 _% D; b% L; t
           (ycor-of turtle d + y )
8 Q9 \$ A+ Y' o          / E& M3 ^3 {7 I7 l3 j6 X& }
            / ~9 j! |3 P* V7 p3 n4 a8 L# b
if (remainder who 5 = 3) [set k who
, h5 X# h/ f- Y                          set x( Wid / 2)  
  z* _( d9 K, S+ W+ @4 l7 r1 G                          set y (0 - Dep / 2 ) ]' [! V' ~, T. D- Q! j% \
                          set f int (k / 5) * 5
, Y' x7 E/ }% e% H& L' e7 x  setxy   ( xcor-of turtle f + x )# V9 d  _9 z! F4 |; C5 ?- C
           (ycor-of turtle f + y ) 3 a6 P" C* _8 y. x1 s2 p
           * ]* P  o: w/ }/ `, B  P
           2 o' @* `. Z6 T* g; a: b
if (remainder who 5 = 4) [set g who) p  \, v! H) t* M( f" a! m! z
                          set x Wid / 2
; f+ ^# p, P% t9 z, M                          set y  Dep / 2 ]& T" [8 v3 L9 b
                          set h  int (g / 5) * 5
4 C7 [" [. S6 F& R  setxy   ( xcor-of turtle h + x )
. ~' s( z/ Y# a. P           (ycor-of turtle h + y )
# n2 l( ]; A2 S+ i0 m# j                          # P" B! J( I9 w1 C! Y- h: T
                          / ]0 y( e' {# M4 f( q9 D4 m* y
                          ]
  S5 i! {; h0 U; Q1 yend
1 B- r6 U7 S7 D$ I; k+ U
5 U& N9 L( Y0 u[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,8 y2 B( ^  h9 k# m; e3 E
应该是& c2 {* Q' t( Q
ask turtles [$ T; U% ^7 S2 m  j
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 9 d3 a& b: }! [1 d
                          set y  Dep / 2
1 E  J/ M6 }2 `5 R+ c8 z           set b  int (who / 5) * 5) W4 d' S9 [4 m
    setxy ( xcor-of turtle b + x )
! c, a8 E) f! ~& j          ( ycor-of turtle b + y )]]
+ T; [4 T$ h2 E# D4 p! Y' Fend
9 i: d# a9 d8 ]! y8 W+ a1 O( J之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-26 05:48 , Processed in 0.018759 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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