设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7196|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
& N2 V9 \' P% W0 c2 ]
, o+ b% F1 }( S5 Z* Y5 Z但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
6 N: j. g2 t1 v5 p
  y- L  X! G0 f% t7 Q1 E$ }( Nturtles-own [a b c d k f g h
& M9 l  v3 }1 S% X1 @  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 0 @& V, Q: }( F) \+ M7 w
]
9 u9 n4 b( W" m% R2 L" d% @' oto new
, s3 l3 B0 `& K- o8 ]5 c  ca
% Q9 F7 K& W& ^( \" l5 N4 f  crt 5 * num_of_building
: G- T7 K7 [2 V3 x6 l  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
( z: I; p: ^1 ]. ]  scatter     ;;keep center-turtle random positions ' b/ l, V0 E" s) V+ R
  unit_plan   ;;make up the building plan
+ D) u' [1 j' F9 u( H! yend( g0 u" b. e3 r# H2 R% x; k
to scatter
. l2 B! p/ j/ {ask turtles with [remainder who 5 = 0]
) w4 P( a5 P. ^9 d4 ~0 c; a6 n* H[
1 e' C& d, K% B8 [! Sset xcor xcor - 6 + random-float 15
5 D% R9 X( x# gset ycor ycor - 6 + random-float 15" ~) d6 i% U& J. U3 S8 ]/ u
]
& Z6 `1 {# p8 O" [; r3 oend- O' P2 H8 G/ i) }
to unit_plan # f* _  E. {. S% d6 S$ y; S& I- Z; e
ask turtles [! M+ \: G7 u; N' p  R
if (remainder who 5 = 1) [set a who / p5 `& s' d3 ^0 N' g& S
                          set x ( 0 - Wid / 2 )
$ M3 g; T( i. b( T                          set y  Dep / 2 ]
5 c$ p" `5 D! [$ A+ t           set b  int (a / 5) * 5
4 Y  j% o) b8 B2 A3 u; _% H    setxy ( xcor-of turtle b + x )
3 \0 p8 V; I" H3 }& d) K# Z! r          ( ycor-of turtle b + y ). D& Y& h8 {- z. ~6 s, x: x& ^
if (remainder who 5 = 2) [set c who
/ S5 _& p2 i7 S7 ]                          set x ( 0 - Wid / 2 ) ' ^( h  ~; r6 m& k5 X3 q
                          set y (0 - Dep / 2 )  ]
# y# ^; H! h1 z9 _6 k" X$ U4 ]! @                          set d int (c / 5) * 54 P, ]1 Q3 [- ?  B- x& K
   setxy   ( xcor-of turtle d + x )
! }0 V' I0 [! o+ c           (ycor-of turtle d + y )
( `8 B* V$ ?$ x, _( t/ T4 n/ _          1 b5 h8 J6 b5 F& v2 h
            
/ H0 c; c# _" Y9 N. }9 Xif (remainder who 5 = 3) [set k who: K: f3 A" }2 H* `& N
                          set x( Wid / 2)  
' @! c% s6 e3 S                          set y (0 - Dep / 2 ) ]5 O5 d) U8 V' s6 U# f6 l) L
                          set f int (k / 5) * 5
6 Z% U* L6 T4 T9 ?. x2 y3 n  setxy   ( xcor-of turtle f + x )5 j3 H% g, |5 H$ W
           (ycor-of turtle f + y ) - d! A* _7 @2 K% ?2 g9 o6 z9 l
           1 U+ X: G/ n" i! R- e: M
           % l1 x$ i. j" F& U5 k+ B* v
if (remainder who 5 = 4) [set g who) Y* ?# f! ]" ?, ^( E2 A6 L
                          set x Wid / 2
, Q& |0 _- q8 m( d9 H                          set y  Dep / 2 ]4 C& J1 U$ ?& F+ w% W  D5 S
                          set h  int (g / 5) * 5: q8 }: K5 q7 }4 k5 R- G
  setxy   ( xcor-of turtle h + x )
6 u- m1 t* t# `% b, z7 f& z           (ycor-of turtle h + y )
0 R) E0 F% l7 `- D/ _                          " K3 X2 q4 W- E4 C, W) F
                          
* r5 E) X6 `% ~6 C                          ]
/ z& X7 n" v0 f# B3 N& ~! Cend$ ]! E) ?& D6 j& R1 d) e
3 `1 F/ |, W' s, c( U
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
6 n7 Q9 E! U# j$ ^& L1 y- O% S应该是
% ?+ k* U+ [1 o$ a3 d- Q- Jask turtles [
) n* I# [- ]: }/ q1 k) oif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
6 H6 Q8 B4 W7 X4 u8 o0 k3 Q+ Y                          set y  Dep / 2 & m, Y% G! J; b1 e6 C" F
           set b  int (who / 5) * 59 m/ n1 w. o9 r: v. i$ g
    setxy ( xcor-of turtle b + x )
0 j4 {# h7 P$ B( T& o. D          ( ycor-of turtle b + y )]]2 F: X% V; C, o. }" }9 N- @2 c
end
6 t- k' T$ K0 ^7 O8 h之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-15 10:44 , Processed in 0.020481 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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