设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8489|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
+ p" \+ b/ k9 n' Q; p9 S0 E
  ^' ^% B7 _3 P8 H5 V; l但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
2 p. X  t# u6 n0 U+ e: \
# Q) a! E* T1 X% lturtles-own [a b c d k f g h
; |1 e, p( u: g4 T* h9 L/ |- d  x y     ;; these are the leaf-turtle's offsets relative to center-turtle   i& a8 \5 N* s6 S( [* t5 H
]
( t2 ?4 M9 z% Dto new
: I0 |1 i" G+ o3 F2 R! u2 ^  ca+ ^& U7 k4 G% U
  crt 5 * num_of_building! _* H; s1 r1 p9 w  F
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]6 R, C4 Z" b5 i# Y+ x! t
  scatter     ;;keep center-turtle random positions
5 A2 w* j% @% H- \5 i  unit_plan   ;;make up the building plan
+ o, u* e  ~' I% W( U$ Bend
* J. c& J. A. @/ R  qto scatter7 v5 v* l9 x2 [. I9 [8 O) X
ask turtles with [remainder who 5 = 0]3 [5 I' }: Q* C/ x1 f
[, H' S# ]) s8 e: C, L
set xcor xcor - 6 + random-float 154 r* f2 H9 f4 b$ c% ^) B$ l* L! f8 x
set ycor ycor - 6 + random-float 15
& G/ M, k" f! s; a, A- n+ P& `0 }0 T]- t8 Y; j2 s4 B
end7 c; }, }8 J9 Z- D
to unit_plan
0 ?) q+ l1 }9 B, Bask turtles [  _* z8 i7 q  a% ?' V" f+ z4 _
if (remainder who 5 = 1) [set a who 5 b! I$ A8 Z8 D& d
                          set x ( 0 - Wid / 2 )
  [, w# a1 O4 U" Z1 C                          set y  Dep / 2 ]+ \2 j& [2 @( E! V6 r7 \
           set b  int (a / 5) * 5
1 @1 Q- E  f; A$ _0 t    setxy ( xcor-of turtle b + x )
0 x% r6 c' }* E          ( ycor-of turtle b + y )
- r5 G$ M- j; W( C& vif (remainder who 5 = 2) [set c who
* d) x8 ]+ N$ J- ~3 E& L+ v. s, D                          set x ( 0 - Wid / 2 )
5 \! w1 V/ I9 R/ T: R                          set y (0 - Dep / 2 )  ]' a- [3 ]5 T1 _" j# O  m3 `& U9 V
                          set d int (c / 5) * 5) V+ u' {; u: n6 C
   setxy   ( xcor-of turtle d + x )* C9 X8 ~% X4 t! H' z
           (ycor-of turtle d + y )
' S# i% O3 `' d$ P          * J% U8 z- R  A3 a
            
4 k) B6 R/ o4 b" `3 b& [$ Xif (remainder who 5 = 3) [set k who
- c7 N+ Q+ z6 t9 B* B                          set x( Wid / 2)  
) m% Y% p1 T- R. }4 O- U9 e                          set y (0 - Dep / 2 ) ]
6 K# i$ E4 F5 ^                          set f int (k / 5) * 5
* a/ Y6 a! T: b; _/ W" l( w  setxy   ( xcor-of turtle f + x )3 K& i1 z, D2 L
           (ycor-of turtle f + y ) " t; g, z0 E8 m/ V4 ~) y1 f. B
           # {3 N' n; C) i" ^( b8 c
             S: a5 W8 L- c& r
if (remainder who 5 = 4) [set g who1 Q5 \/ L$ X. z  J8 ]- q
                          set x Wid / 2
' X. d2 Q6 }1 [+ X                          set y  Dep / 2 ]+ d& \5 K9 \& J. v
                          set h  int (g / 5) * 5$ ?3 W7 j5 y, H3 _* k. b
  setxy   ( xcor-of turtle h + x )
+ C' I. z6 H" @  C  _) v           (ycor-of turtle h + y ) ' A+ }$ m' T( z! e% A1 T
                          4 u! g3 Z; [$ M5 M. [- X7 V
                          6 \2 U- f8 m  H0 N
                          ]
7 A4 Q9 y$ H7 R$ [* aend
4 n' b3 e3 k- a# a" Z- H& J+ z4 f" e6 r
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
% Z' o1 w$ v$ b8 M6 v应该是, K- U6 {. t0 J1 x& X
ask turtles [% o$ O2 z# O8 H1 x& d
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
+ c! E, T3 @+ V& f+ b0 f7 V                          set y  Dep / 2
# g# v: B0 f. Z4 X$ C           set b  int (who / 5) * 5  y5 {; Y* Q4 |( ?; j( b! K! r
    setxy ( xcor-of turtle b + x )
0 {1 y2 @" ?* w- j, F: B' H8 s          ( ycor-of turtle b + y )]]
% E/ X6 R/ n/ X- |9 X7 c5 A  D% Fend4 S' h# x  h- t7 Z% I) t1 @
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-3 16:30 , Processed in 0.017014 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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