设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6776|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。& b) z% }2 f- k' }! d+ h6 [& c
; [4 C- E9 Q7 z0 |4 \5 M1 b
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。3 \0 H3 u8 C, y: ?$ [

& a' L; b  ?3 A0 m( `turtles-own [a b c d k f g h( |8 ^8 N$ l) ?6 Z3 C' _( x
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle & `) U, V4 L# [1 R" I# K" n
]
8 k6 W+ \! E4 h8 ^8 o' b  V2 Z5 \to new
6 q7 J6 W3 i8 ?& |7 i0 M$ D  ca- X, \# o: T& W8 F( _
  crt 5 * num_of_building
/ c5 Z6 b2 G- L& f; @  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]$ d4 K0 G9 C: Q' V; @
  scatter     ;;keep center-turtle random positions
4 T/ p6 T/ ~( d! V  unit_plan   ;;make up the building plan  N0 N% m' X; ~! {! y, }3 c
end
4 ?: j/ L: J  N; n" a; [7 p1 rto scatter2 b1 k# E1 `3 a2 X6 }
ask turtles with [remainder who 5 = 0]. D. o% b; v0 ?) C+ B: |. A
[
# ~) G% b) _+ Tset xcor xcor - 6 + random-float 15! H4 D9 L9 t: l7 q; }
set ycor ycor - 6 + random-float 15
% f! y% U7 B% K% j) [# _9 l- _! {& h]  _5 b* A. t7 Q! ^& S" b
end3 h7 x3 |7 X& {) z  u3 F
to unit_plan # d) g4 H# d+ T% `4 q! w9 m
ask turtles [
/ g+ D3 X) B# T* ?0 u, bif (remainder who 5 = 1) [set a who
% e; J3 K6 M3 R( H' r                          set x ( 0 - Wid / 2 )
8 C7 G; y5 {6 V1 [' f: X( {2 u                          set y  Dep / 2 ]
/ I/ t! o/ g" o( K           set b  int (a / 5) * 5
: ^4 T) u  R  P% S$ U    setxy ( xcor-of turtle b + x )
9 V; U9 N- l, U" s, h4 o0 e: k          ( ycor-of turtle b + y )
0 O' O1 t. m3 G9 l) tif (remainder who 5 = 2) [set c who" f9 w! S3 s2 J  r4 q
                          set x ( 0 - Wid / 2 )   L( c, n0 e, n9 W$ D+ ~
                          set y (0 - Dep / 2 )  ]
% n- b' O/ j. m6 X7 I1 C                          set d int (c / 5) * 5
4 e. [) _( |2 W- c2 b! F   setxy   ( xcor-of turtle d + x )
8 l. |/ n$ u( F& d           (ycor-of turtle d + y ) & U" A" E# H0 G' w( B% k
         
9 P9 ^) M$ B6 }5 O' ~7 d; _            
4 ]6 U' _1 @, F# n$ A2 D- }6 Wif (remainder who 5 = 3) [set k who' a9 p% n" p2 L: C: ^) ^
                          set x( Wid / 2)  & X$ D% |1 L8 I/ A& q
                          set y (0 - Dep / 2 ) ]  G* Y. f: D; A( f
                          set f int (k / 5) * 5
9 u/ r' @+ G& f: F; _" O9 R  setxy   ( xcor-of turtle f + x )
7 r6 b# E# J* |8 U4 b, C           (ycor-of turtle f + y )
# t$ S* z& j0 c2 |: P# Z; r           . Q9 H, B* N: u" q& p
           
1 b- \3 L4 z9 L0 f9 Kif (remainder who 5 = 4) [set g who" M5 A- n4 ]' y9 {) T+ n
                          set x Wid / 2 ' j1 S* y# X# k( O: Z  P0 e6 P
                          set y  Dep / 2 ]% A5 P. e, U5 a8 v6 a: B
                          set h  int (g / 5) * 5
( E  I- j- [, J" j  setxy   ( xcor-of turtle h + x )1 J! v" a( d) ?, c3 p
           (ycor-of turtle h + y )
$ C: ?- ~3 P% t                          
! n4 Z5 ~& D* l* E                          
% E% x) J; ?7 h0 n& Y4 T                          ]
" L* G5 N# L/ ^9 y, ^) l4 ]end5 G+ E* `5 K0 H
0 H5 h$ _" B$ ^- P. l
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,' P& w$ h0 V/ K" q  @9 F1 b
应该是( b( _) V" }( O: y) Z4 ]. W$ J
ask turtles [
- s3 T2 ^0 m. e4 d* \! O' zif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 7 ]0 [' e. D" w# z- l5 h
                          set y  Dep / 2 9 w0 j" X( n/ c' @8 b4 ^
           set b  int (who / 5) * 5
2 M* k* X" I" c" `+ W    setxy ( xcor-of turtle b + x )$ P$ E2 T$ j4 F
          ( ycor-of turtle b + y )]]
3 j( w! o: D0 N* v2 m+ e0 w$ Pend. C! l. [( R2 ^0 w* g1 O# W
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-22 15:16 , Processed in 0.016019 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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