设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7806|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。) A$ @- h% S* Y+ w$ ]
  z- p3 |* q# O$ g$ x( ^9 C
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。3 E) Y- G0 `4 T1 W
( E7 h, S0 h; r6 Q/ I5 O% n4 o
turtles-own [a b c d k f g h. p0 Y/ ]' N3 N' g& G
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 8 E3 Z7 u2 s- u) h+ u! n7 Q/ n0 P( O
]
" g$ o  @: K- z3 d: K# ?9 mto new
! Z  [7 I3 _8 l( d. {  ca0 [0 n2 ~0 m" r) D7 [
  crt 5 * num_of_building
# [; E1 ^1 n- v  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
+ g& o4 [/ @2 x8 @. D  scatter     ;;keep center-turtle random positions , F% m4 L* R$ J9 \, @1 _
  unit_plan   ;;make up the building plan
2 \( b! r4 h- y4 Xend
$ M# b) q3 k  j: N' Lto scatter
0 M" \' Q& M0 dask turtles with [remainder who 5 = 0]1 G/ |/ L3 [7 O% ]9 z
[
+ ~$ O& f- V4 W' o4 @& d$ R7 z3 mset xcor xcor - 6 + random-float 15
) D, l, R" ~' U; v8 j7 u3 Sset ycor ycor - 6 + random-float 154 Y$ J( s' |: p6 C8 B) G' C
]
: A5 O  I: F# v& P$ `2 _3 O# nend8 t/ Z4 E8 S0 \! k3 E3 Y7 G* V5 S
to unit_plan
: J9 H% i: {( Sask turtles [' \- R8 U8 M/ f, a5 D& Y
if (remainder who 5 = 1) [set a who
- g! C* O  n6 g5 J; M                          set x ( 0 - Wid / 2 ) ) z8 S6 Z7 p3 k2 I- e
                          set y  Dep / 2 ]
& m6 @8 l- \- p           set b  int (a / 5) * 5
4 \1 T: c# ]' J- S( M+ i. O    setxy ( xcor-of turtle b + x )+ S) e$ W' x/ C
          ( ycor-of turtle b + y )
' {  I9 y! n' H0 k  e6 Nif (remainder who 5 = 2) [set c who
# j5 c5 f$ E2 b+ v, v8 k                          set x ( 0 - Wid / 2 )
0 Y) H5 K5 i( B# P6 _! s                          set y (0 - Dep / 2 )  ]. V8 n: m, V- k3 {% N7 }, S
                          set d int (c / 5) * 5
. v# v% L( |  w; t& y. e* m/ q   setxy   ( xcor-of turtle d + x )
5 B0 X1 x# {' x5 T$ n           (ycor-of turtle d + y ) 7 M- [8 ~5 |/ k4 G8 w* E) ^  U3 ?5 i. `
         
8 r2 }' i0 M* V+ {1 O, c            - Z* N: @1 R& p- f& d- C
if (remainder who 5 = 3) [set k who0 e7 _; h* v7 [  l
                          set x( Wid / 2)  
3 g; ^1 H5 u9 ^) X$ O                          set y (0 - Dep / 2 ) ]3 _% ?! C. L4 b- {) z! G
                          set f int (k / 5) * 56 M: X( M) ^3 U8 f* p
  setxy   ( xcor-of turtle f + x )/ a* c% _/ @* I" R; H6 w  t* I
           (ycor-of turtle f + y )
. h# P% I" M# L; I/ l. N7 T           
8 F9 T3 W1 i; g! Q5 d# h- j% B           ) H# i0 Y8 {: C; E: T& q
if (remainder who 5 = 4) [set g who0 _; w- W3 P, i; A4 s3 @4 f
                          set x Wid / 2 3 Y  E1 v, e2 z7 T& o  M; ?, o
                          set y  Dep / 2 ]
+ T; I# r4 ]# G                          set h  int (g / 5) * 5
9 x! G- K- L) \  setxy   ( xcor-of turtle h + x )  |/ q4 y% `6 \3 m- q+ M
           (ycor-of turtle h + y ) # q  q2 J. I  W9 f1 a
                          4 ]1 c* m8 p, b2 ?  f/ q& ~3 N
                          , _( i" p3 n2 A" @
                          ]$ O8 D+ y' P- y. `/ T6 A) f9 O. O
end
! n3 m" B& j# k" c" P. i0 O( g' i& f, S" {" R
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
( x% j: V' z( X. M& K/ B# r' b应该是
' A; t) |; g5 G, p& mask turtles [4 `* D" Z% q0 K9 L$ Q
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) * H; u4 |7 h/ `6 Z1 f' \, D
                          set y  Dep / 2
! k# Q7 z" D& {- B, ^           set b  int (who / 5) * 5
" J+ w* v# `2 N$ ~  g/ p9 ~    setxy ( xcor-of turtle b + x )( W$ X5 T8 u8 M5 p' v. c4 ~4 V
          ( ycor-of turtle b + y )]]% Q; {+ ~6 P7 ~$ }
end$ }9 o& I7 l, S) u7 R. Z" s/ C7 y
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-3 13:53 , Processed in 0.018426 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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