设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8590|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
3 [. l- P' }$ R6 ], T- a: q- j0 R% B- R  Q
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
: A2 _2 F; o. g4 a, E; z. X# l: |  L" }" J* s0 C$ D, j$ K+ P( z5 a
turtles-own [a b c d k f g h
: A1 n2 N; s) Q! H2 c( P0 s- X( B  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
4 A: o8 ?* H7 I# E. B! k; k. ?]% B' U8 O% i. `: P' I; M: O) T
to new4 D0 f+ y' i: f3 G9 r  |# l; }
  ca# j: K& X5 x3 s1 Q: G
  crt 5 * num_of_building7 M# D! O0 t/ N. i" V/ A7 v
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]6 n  O, w. X. ^, Y5 d$ w
  scatter     ;;keep center-turtle random positions
* A+ Q7 H/ s9 R( C! W  unit_plan   ;;make up the building plan
- s. d0 V# X* h0 N  _end" }  n- O. T/ h/ }
to scatter, @3 y, ^' ?6 P3 e
ask turtles with [remainder who 5 = 0]
2 ]4 M6 u- E- o5 t3 _/ V9 Y[
" W+ h; g4 z9 R# E( M/ |set xcor xcor - 6 + random-float 155 a' o6 X/ v9 K0 j
set ycor ycor - 6 + random-float 15# O+ K# ?. E/ |2 k& ?2 D6 ?
]+ r$ ?* q: X+ O/ }$ k7 P+ n
end
" I* a- `9 J* c+ U$ j& G8 |8 k( _1 O+ Zto unit_plan $ K7 L+ f  e% T
ask turtles [
( B2 U& l6 q/ T( D( H9 mif (remainder who 5 = 1) [set a who
/ I! l1 F/ ]: p: A                          set x ( 0 - Wid / 2 )
5 l: V/ p: v# Q% ~. g                          set y  Dep / 2 ]5 f2 R  |1 R8 V8 I
           set b  int (a / 5) * 5# C+ ~% T0 v9 |, `; A2 x6 K
    setxy ( xcor-of turtle b + x )
$ I" _8 N4 D3 s2 l5 G: D7 L          ( ycor-of turtle b + y )$ A6 i1 ?9 u; U; B) F# ^. c
if (remainder who 5 = 2) [set c who
1 @3 k1 U& \' r1 p+ W+ S9 d; K                          set x ( 0 - Wid / 2 )
. X8 D( K+ G3 _% B8 l                          set y (0 - Dep / 2 )  ]9 `: o0 I/ V# G- i/ x3 r
                          set d int (c / 5) * 5
3 s3 O3 O: j; a   setxy   ( xcor-of turtle d + x )4 t$ c- b" B1 A2 ]7 o$ u) q; s
           (ycor-of turtle d + y )
( y/ O& }( C8 v3 T         
! u. ~. ^, x2 ?- I            
1 N7 g6 ]! `& v- f; B8 w* d0 m8 oif (remainder who 5 = 3) [set k who
% |/ I) X* s. W9 i, u6 E1 f                          set x( Wid / 2)  6 C" H" e! F) I$ h0 ^% L' ^5 H$ i
                          set y (0 - Dep / 2 ) ]) a. i$ }/ U/ _4 t3 B
                          set f int (k / 5) * 50 D7 J& i5 K: c% C) I% O/ `1 m
  setxy   ( xcor-of turtle f + x )
, o+ L  d: R, h' L7 H/ [           (ycor-of turtle f + y )
" c& t: s& ~: M7 r& A: z8 e           ; F  Y1 R% \3 n" I) w' {
           
0 J! P: K" E. Yif (remainder who 5 = 4) [set g who- N6 n$ G  H- L; R
                          set x Wid / 2
% w; p9 M" o8 m# Y' ^/ @+ A  ^                          set y  Dep / 2 ]
6 l! ]' Y. M2 k' B* h+ N' u3 @                          set h  int (g / 5) * 5
) M; Z, ^, R- y7 u! l3 L# g  setxy   ( xcor-of turtle h + x )
* |: `( \) w. k           (ycor-of turtle h + y ) ; ]' n* F, R; {2 x; R+ J* V
                          & |, F- V3 G1 f2 U7 W
                          2 m0 z. C- |+ s- J; c+ u! g* o
                          ]1 r6 D* p" I8 X! ]% W0 S- ?
end! h8 D/ P" _0 U# o) M

# b" j. s# b  l" [[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
" K4 n% J  x2 ]4 @% C应该是( i% T, }7 S, K+ {" ~0 {) x
ask turtles [
/ r) I7 q0 _: X) l( n  ]if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )   P5 c7 W! a5 l$ i0 O. {) H5 J2 r; ~
                          set y  Dep / 2 % K. h1 H) o8 I) Y, k1 Q5 d$ v, G
           set b  int (who / 5) * 5% g! i" c7 i0 L2 _
    setxy ( xcor-of turtle b + x )+ m, t" ^+ O2 f4 T) K
          ( ycor-of turtle b + y )]]7 `: R  c% p9 w9 g: n! f8 Z  }
end
0 T& K5 f% K, u& j! _8 u之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-15 01:50 , Processed in 0.014890 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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