设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7681|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
. r+ \8 g) a9 q2 ~- Z1 K9 _: B$ C' T+ i9 C
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。3 x3 }. Z% M& Y% G. V
% P5 r9 c! D+ }
turtles-own [a b c d k f g h, I9 B/ t4 X9 F+ q# Q& G8 P( d( Q" v
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
# }- z; x6 n0 D. F1 b]3 ]1 [7 i% y( \  ^4 e
to new* L  ?" b) S" J; J& ?
  ca
; E' ^. D  W, B* K5 b3 Q  crt 5 * num_of_building. b0 n6 k- Q# r4 K# V+ S
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]) B! V( z7 P. N1 f, J+ i) n2 @
  scatter     ;;keep center-turtle random positions
) g& ], M/ ^5 b" l4 n6 s' `  unit_plan   ;;make up the building plan# E2 s. Z& J6 i8 Q
end
0 H( U- ^) [0 e  Ito scatter
: N1 y; N3 [! a0 O# ^/ oask turtles with [remainder who 5 = 0]8 c9 O; M2 V9 w5 z+ r! e* F6 n" a
[* X# H! [+ ]  \& d# D; j7 N% V- p- g
set xcor xcor - 6 + random-float 15
) J$ L$ c0 }/ w) `$ L. oset ycor ycor - 6 + random-float 15
9 m! s3 E2 g: F( s1 T- P]; r( J$ b9 l, ^5 q
end
( H" t% u$ z5 n$ ]! I  f$ ito unit_plan
8 ^; }2 x4 K( C7 W8 n! o. zask turtles [
7 ^5 I: T( l9 x! ~if (remainder who 5 = 1) [set a who
  Q, i# w# Z: o0 U                          set x ( 0 - Wid / 2 )
4 P8 c. ]& V- D. V5 F* x                          set y  Dep / 2 ]
! z7 i9 G, E. m- L  K           set b  int (a / 5) * 56 X- M3 b: [# y# x+ s( @3 a
    setxy ( xcor-of turtle b + x )4 p) e, [5 V6 @$ G+ Q* T* B
          ( ycor-of turtle b + y )4 e! y/ g" E( n, S( \9 \, t/ [8 g" m
if (remainder who 5 = 2) [set c who
8 j" e3 M% {! W                          set x ( 0 - Wid / 2 )
8 q. u7 q1 {0 ~; {& U                          set y (0 - Dep / 2 )  ]
( R2 b5 J8 s7 k" l3 z3 B                          set d int (c / 5) * 5. ?0 |) M* W. `: q: I; n* Q& C% B4 q
   setxy   ( xcor-of turtle d + x )+ I! h% \/ n. o
           (ycor-of turtle d + y )
: d, v6 H- N" ?8 c; M! M0 B7 U         
) J0 U+ H! I: f            
! |" b. m, K- P& w' Jif (remainder who 5 = 3) [set k who5 E5 X/ z7 @/ e& J. {
                          set x( Wid / 2)  + Q: D5 G% c( A- g3 U
                          set y (0 - Dep / 2 ) ]+ Z, R1 H0 H- x: O
                          set f int (k / 5) * 5" H3 J3 S" N$ g' k0 k% a4 G$ a& x% Z0 `
  setxy   ( xcor-of turtle f + x )
5 U1 x* [0 v. f* o' I' s           (ycor-of turtle f + y ) - }: A7 K# l! q
           
3 n. A: R) l& k7 e           
( W" X# x# ~8 K- L9 I8 V) {if (remainder who 5 = 4) [set g who. s9 D5 \, q* f( N
                          set x Wid / 2 0 f( o4 M& p% x
                          set y  Dep / 2 ]& D6 ^  v/ ^8 {% U& a
                          set h  int (g / 5) * 5
6 b7 x6 p' G# e% f( c) ?! Y  setxy   ( xcor-of turtle h + x )
+ k" \) O6 [! t+ M, T4 {; a9 m5 y           (ycor-of turtle h + y ) % e: w, ]0 ]0 m
                          , O+ T. t+ \( I1 y; h6 F
                          - j0 m" w+ o" c5 i! G
                          ]2 {3 w  C( r* V: x# C$ o, x
end/ U$ Z. p" a/ }! p# K  |) `

& }# U( p0 @' w. U/ m# S! W8 ~3 L[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
& l5 z% O3 d7 b. `$ a* K应该是/ O$ V& D# y% Q) k9 D
ask turtles [
9 X  E" i2 n: o( k) Sif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 0 U% N8 B% [/ e3 v, S# `) R4 j
                          set y  Dep / 2
1 f& i) H- k6 w5 @6 \' \           set b  int (who / 5) * 5
) L  \0 H9 a( X' v+ }' p2 r    setxy ( xcor-of turtle b + x )- |0 Z# E; p7 K9 e" Q1 q# \, W9 d
          ( ycor-of turtle b + y )]]
2 V/ f" n) d) Cend' }, T/ s" z- A, b
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-13 19:30 , Processed in 0.016940 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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