设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7754|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。" k0 [1 C0 _$ S9 l: X
, C: q# e2 n+ @  ]  p
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。5 c7 p- I- @% ^; X" }

, g) Z% w7 I# I1 u8 [4 L! ]! bturtles-own [a b c d k f g h
: G# d. U4 b, P* E4 ~: W# I  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 9 c$ o, L1 M. q) T; q9 V
]* w/ t/ p6 s+ D$ M2 @
to new4 L+ j9 M, d+ M+ z* M6 T
  ca
# i- p- l0 ?* X: L. I4 G9 d' n  crt 5 * num_of_building7 _) _3 C; X" _  _# H
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
' ?/ p2 }1 g9 [( s  scatter     ;;keep center-turtle random positions
% g( T& V9 D! ~9 I* p6 K' Z  unit_plan   ;;make up the building plan
9 n. K$ r/ H0 a* _* zend
; W5 r* t6 o  c; `to scatter
, K4 }  }# x2 ?. Eask turtles with [remainder who 5 = 0]
7 @# M4 o' X: y/ O" Q% q[
9 G7 f% y1 P4 q% Q" \4 hset xcor xcor - 6 + random-float 155 a# z  b0 s4 \7 N! n
set ycor ycor - 6 + random-float 15
& m7 V. m* ]: X$ t6 Q]
9 _0 }* e. }; J4 T/ I) Oend- j: X7 B3 I; y% e: J7 D
to unit_plan 3 i! W+ A; _3 r) `! c/ `$ ?/ d1 K
ask turtles [" s8 v$ [. l* [$ w/ B" Q
if (remainder who 5 = 1) [set a who
$ ]0 f4 e  A8 U4 B                          set x ( 0 - Wid / 2 ) 2 d! G0 S; D- o# ]6 ]- |
                          set y  Dep / 2 ]
3 y: E, e6 E4 H0 c$ @# N           set b  int (a / 5) * 5
' D* G5 q7 [+ a% K! j8 K    setxy ( xcor-of turtle b + x ). W) D% x, n0 x  b2 C
          ( ycor-of turtle b + y )
8 M: p2 u3 u4 sif (remainder who 5 = 2) [set c who
0 Z  m* a7 b, x2 Z5 I                          set x ( 0 - Wid / 2 )
/ U& p7 C0 q% ^- x2 e7 V9 L                          set y (0 - Dep / 2 )  ]& ?/ w( ~  W( @* e# l/ l: H& \
                          set d int (c / 5) * 5* U0 g* T8 R; _! Z9 H$ v9 j
   setxy   ( xcor-of turtle d + x )5 E! I! w; A; [
           (ycor-of turtle d + y )
4 m# @5 j( [3 s6 |. Y$ \! @          8 }' q/ L* m0 G0 ~) [, H
            ! O3 S4 o! t: v1 {/ v
if (remainder who 5 = 3) [set k who3 ~  i2 @. c- U2 J' E
                          set x( Wid / 2)  
2 c( c( [$ z" P9 t$ \                          set y (0 - Dep / 2 ) ]
3 X% c+ g' F# {- L1 T7 o8 C) S) W                          set f int (k / 5) * 5
4 ]) S" J# G- B8 M  setxy   ( xcor-of turtle f + x )
! T1 |% R( V( A- ^$ G           (ycor-of turtle f + y ) 7 T( e7 ^3 i+ e( t, _
             i( m) ?7 Z" n/ r" H- Q
           ( t7 w3 ~' h+ C, a2 h  _8 B
if (remainder who 5 = 4) [set g who  K/ L2 l# B- v7 @, U. w
                          set x Wid / 2   A) ]2 E# s9 D
                          set y  Dep / 2 ]
+ _3 M& }2 D, r' q' c                          set h  int (g / 5) * 5# n$ l3 m) Q9 Q. ]1 T1 S& e" t
  setxy   ( xcor-of turtle h + x )
. y9 ]* n( z1 i+ G           (ycor-of turtle h + y ) + a) g& ~! t  ]1 ~. D& v1 `6 x( a
                          / q/ f5 f2 U3 s: @# E- h3 R) c6 T( U0 T
                          
+ D0 O7 X, W( v5 b$ P                          ]
" F+ F# ]5 l0 lend, i# Z9 n& X8 R, Y. @+ ?6 E: B
) C. Y$ \$ o! N& B3 o0 P; ~! z
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,& Q( c0 R  C. X9 C
应该是# u/ h* M) t: m' A* Y! b# z, o& J
ask turtles [
' |) K; Z. a4 Y: C6 D/ pif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
/ p7 f3 ]3 s" a) V                          set y  Dep / 2
  |! M/ O$ o. F) k2 v6 T9 i           set b  int (who / 5) * 59 E5 q  c  q% Y
    setxy ( xcor-of turtle b + x )2 v, z* E+ ]6 u0 I) n
          ( ycor-of turtle b + y )]]
9 ^; ?  |7 \/ W9 I4 P# ?& N& ]/ }end
' J7 k* p" }& F4 W6 V# X之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-25 23:28 , Processed in 0.017039 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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