设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7711|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
1 h7 H# u) M8 a( v. d4 j3 N1 j- }. t
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。) @( l0 k( ]* M7 y0 X, N- O

3 a% T1 K" z9 G- Y# x( d5 }turtles-own [a b c d k f g h
" M, \+ X7 Q9 r: z  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 2 V" d! ]; X1 O" ]8 E3 v- J
]/ R' }- O9 h5 M* P- b, d
to new
0 Z* V2 I* K5 q: h- W4 @! T  ca- R9 f; l/ |$ n  i; Z
  crt 5 * num_of_building, _' g/ X, ~  W
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
; M8 T. P$ M0 ^7 b4 K; U  scatter     ;;keep center-turtle random positions
" g. p0 B2 ^9 s  unit_plan   ;;make up the building plan
2 A7 ]* _7 E: ^end2 s6 ?0 ]$ }2 m5 R" X6 o
to scatter
8 H' A* d$ n/ |  J3 R, Kask turtles with [remainder who 5 = 0]8 q+ V! F" G; E+ |6 h. w" x
[7 i% @# y+ \4 V
set xcor xcor - 6 + random-float 15
" k3 F. r; t+ m/ m9 Fset ycor ycor - 6 + random-float 15! n$ _- _" C5 ~6 o2 Q
]
) Q6 E2 I/ c& @& o3 P( D) I3 l2 k. Qend& Q; e5 ]# t! i+ H$ f! x5 c
to unit_plan 4 j- C: F" L4 _5 t
ask turtles [! z9 S" [& w& q2 t
if (remainder who 5 = 1) [set a who
; x2 c4 j$ p! W- f  Y1 S6 n5 k& t                          set x ( 0 - Wid / 2 )
8 V% f3 J& G1 u                          set y  Dep / 2 ]
) d) t6 s; Y& \6 i+ N           set b  int (a / 5) * 5
( v- p8 C1 V% E1 u* T4 K+ K5 S    setxy ( xcor-of turtle b + x )3 I6 g( ~4 V$ H, p1 n
          ( ycor-of turtle b + y )
. T; ]9 H6 r: C7 R( L: lif (remainder who 5 = 2) [set c who7 u) r  F+ J- {' P  A: N
                          set x ( 0 - Wid / 2 )
: r2 [. k! }# x1 V9 }3 W                          set y (0 - Dep / 2 )  ]
1 g! R# I% S& s                          set d int (c / 5) * 5+ E* A% ]8 S$ w) U1 u7 l
   setxy   ( xcor-of turtle d + x )
7 J9 L1 P2 I# j% o2 W, l' D           (ycor-of turtle d + y ) 1 F, I  n* y7 y4 ^; E( H
          $ i5 n' p& e9 u0 u
            , G" t. [% F4 j( I- |
if (remainder who 5 = 3) [set k who
: _( X1 K1 W, z: B' Q                          set x( Wid / 2)  
! ~+ ?# x1 n* r5 F5 \$ U' @                          set y (0 - Dep / 2 ) ]
2 D( }: J5 G, ?3 E                          set f int (k / 5) * 5( X5 [5 t9 X( u5 w) [& ^* W
  setxy   ( xcor-of turtle f + x ); M2 q+ K2 w! D! n
           (ycor-of turtle f + y )
/ f5 E9 V3 o+ h+ J& d8 y: g- ]           
/ U6 o% y' v; q) S           
" o$ C( L+ d% R2 tif (remainder who 5 = 4) [set g who9 a4 ~4 v! {0 a  r# I6 P+ k" I
                          set x Wid / 2 : ^1 z9 K5 ]# d; v- i* X* Y9 Z
                          set y  Dep / 2 ]
: [1 v0 F. z3 P0 T7 I2 c                          set h  int (g / 5) * 5
! N8 a# j+ z0 N6 Y' O  setxy   ( xcor-of turtle h + x )6 f  O3 S: Q2 z2 R, |" }
           (ycor-of turtle h + y )
5 F" q* f3 H+ W5 x/ U1 c                          $ {4 P1 C* w, v$ h0 @1 u
                          , g* P2 j; Q4 A- j
                          ]
' N' X' U) v9 p! w3 pend
# H2 p, j& D1 M: S5 \2 X: ?' ~" E0 [' Z, M9 P( R
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
( {0 r& a2 H: d. m应该是- Y3 T# l+ w- _5 o; T# z* ]8 q
ask turtles [  B$ n* }; e& I0 w% z
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
- n4 \) S; Y+ \7 `8 v1 D                          set y  Dep / 2
: w9 ?+ k6 V; G5 r! K: v           set b  int (who / 5) * 5+ J! {" E8 Y! {- h& @
    setxy ( xcor-of turtle b + x )  \  u2 I+ p2 |
          ( ycor-of turtle b + y )]]
7 d( k2 U7 X0 Y* P  ~: |5 tend
/ v* U, R) C. B1 M) ^" W1 O之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-18 13:41 , Processed in 0.014617 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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