设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7276|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。, O' Z4 }& P  n" i: c- D! f# n
: _+ I% Q5 _& O) {4 x% r6 \
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。/ m7 N$ v  b+ ?7 f7 o' ]/ M

( M# S; M  c8 ]- i. P/ Y4 g" Mturtles-own [a b c d k f g h
% B! \/ J7 U1 [3 F. ~  x y     ;; these are the leaf-turtle's offsets relative to center-turtle : M# a9 Y. Z3 |0 m
]4 G/ L/ @1 A/ q, o6 b
to new
  M) p/ p# L- F3 W( c. T  ca
  F. \3 C4 }0 r; T' l0 i1 S  crt 5 * num_of_building  q. q( t- _# L
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]0 Z3 T& M: X: J0 ~7 u3 s
  scatter     ;;keep center-turtle random positions
! }0 O$ y  ?4 T' O4 n4 w, H  unit_plan   ;;make up the building plan
5 K, P( S+ q- P7 \( `  m+ T- lend
* g7 E+ `  ~; o9 Y1 C' l- ]9 U4 xto scatter4 V% T/ e5 e8 {+ p
ask turtles with [remainder who 5 = 0]
/ m0 |9 F% L  P7 h4 J4 j[$ u  w3 \: ]6 j1 ~
set xcor xcor - 6 + random-float 15
& l% p' H3 B1 Y, _+ e7 Bset ycor ycor - 6 + random-float 15
, M# g' x. W3 W' c% B4 }5 w, d]9 D( e) J, `2 ?& W- P9 F
end, ]9 m: t5 J) C
to unit_plan
8 X+ G0 H1 {. l" E9 x& b6 m/ Q# B7 ?ask turtles [# ^! G9 A" C& T9 P
if (remainder who 5 = 1) [set a who
( \% ?! A+ p3 q                          set x ( 0 - Wid / 2 )
' S, c; k* y  I1 P: g                          set y  Dep / 2 ]8 o' K# D0 {0 g' u% K, g6 w% v
           set b  int (a / 5) * 52 ]: w$ g; N9 Z$ g% \) R+ L
    setxy ( xcor-of turtle b + x )
( C) E* e# L: F  o7 w8 ^          ( ycor-of turtle b + y )8 j* p; I- }" K4 x8 z+ H
if (remainder who 5 = 2) [set c who
) j3 j& {1 K! j+ m                          set x ( 0 - Wid / 2 )   K8 A( |1 k* H0 D
                          set y (0 - Dep / 2 )  ]
; B" U- q( F- A                          set d int (c / 5) * 5
1 W$ F9 Q5 b) I   setxy   ( xcor-of turtle d + x )4 \" S' W2 _+ z5 Y) n4 p8 g% J
           (ycor-of turtle d + y ) $ R( _- M! w/ o  F' L
          , H* ~4 P- q' K  U1 T& n( m/ K
            % h  D' d! V8 T
if (remainder who 5 = 3) [set k who6 ]5 d- i" s: T" j6 w: B
                          set x( Wid / 2)  2 X9 w$ |# ~7 w) y9 t% h( g. n
                          set y (0 - Dep / 2 ) ]: d! [0 C' ~2 N% O" I+ `* \
                          set f int (k / 5) * 5
2 W3 u) x( s/ `( o# l1 J1 z  setxy   ( xcor-of turtle f + x )
# O$ ?9 }  S) V- k7 d+ z/ `. _           (ycor-of turtle f + y )
# T: O  U( }3 }' c# ?! y           
) M& x3 v9 T) J; Q           
& t4 s  L" O( I& O& C- \if (remainder who 5 = 4) [set g who: B$ g# |# `' @+ v+ _
                          set x Wid / 2
8 Z* |; ^8 d5 w% C5 s( o                          set y  Dep / 2 ]* l% T8 X: I* g2 G" a
                          set h  int (g / 5) * 5
( N" i7 i& F7 A* ^% x7 T  setxy   ( xcor-of turtle h + x )% D2 ^  I3 d0 G) j4 c
           (ycor-of turtle h + y ) ) ]7 W& s, d# G6 U9 f* o' l
                          
3 |4 i- Z7 s# f, c0 U9 ]& R                          - j( c4 g8 z/ B( z% A' o  I( N7 f( ~" ~; B
                          ]
; c, _1 o, z) M3 y' \end! n* l2 r4 {/ D- n

# I* [$ `/ a+ x[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
/ @* ~5 b7 S% y9 Q; \* O; l% c应该是/ j4 s. ]/ S! f8 |" C3 @
ask turtles [( f3 y/ x/ E" W  o
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) , ?- G" u0 k* _
                          set y  Dep / 2
) e5 U  V/ F  }) D. v3 {9 G3 `& f' a           set b  int (who / 5) * 5- n5 V6 |# Z% k/ t- z
    setxy ( xcor-of turtle b + x )$ W- h! r6 u% N) z, W
          ( ycor-of turtle b + y )]]2 W5 K' H3 k4 C+ |( t! N* B
end
7 z( e  L/ M7 `; w9 x8 [& p& v之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-24 10:09 , Processed in 0.017418 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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