设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8352|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。2 G6 d( e( n! U/ j

3 N6 u6 Q. f4 {: ?2 G但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。  a$ A3 a) j: U8 G# e

8 M% U4 F0 W1 ^9 {: D" mturtles-own [a b c d k f g h$ N' o0 y9 _% Y. ~3 I
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ) I9 l' |, @$ `! B& ~0 w  o
]( y9 w# B9 O. P3 z. _
to new" M: k) m3 ~. v# L- H
  ca- ]6 M9 r. y, `' Q' L* E
  crt 5 * num_of_building
# J) Y8 T( U* r" V* b; K  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
, Y+ g" F, G  c9 w4 q+ w5 m% Z8 U: n  scatter     ;;keep center-turtle random positions
) |3 \9 t$ v3 c; z/ T/ y9 k7 C  unit_plan   ;;make up the building plan
& K9 g5 R& B2 ^! Y; f% _, Y3 M& }end
# ^6 _8 _7 i5 _( k# ^! r3 mto scatter
3 b# y/ w+ S  M& s8 _ask turtles with [remainder who 5 = 0]
9 h3 p* ?; |9 }; U  ^! g1 u[
* ]$ K" X) T2 b; g. b- n4 r! [5 s0 H" {set xcor xcor - 6 + random-float 15
6 w; t2 n; Z6 z( D% ^! dset ycor ycor - 6 + random-float 15
; X; h5 d  j% c% A& q* b9 [* |]
! H( w; n' k0 [' x4 i4 x& v; aend
5 ^& a+ L# i6 t, s3 qto unit_plan 2 L' G1 c3 i* M4 k1 ^
ask turtles [
5 S: I( U) u4 R9 Qif (remainder who 5 = 1) [set a who 9 m; |5 D' ?, @. w6 ~3 K' K
                          set x ( 0 - Wid / 2 ) 9 Q; S' Z3 B$ ~' D( }4 \3 _
                          set y  Dep / 2 ]# o1 O* d* R% n
           set b  int (a / 5) * 5$ q3 z& i# @! `
    setxy ( xcor-of turtle b + x )
  J) Y  c" c, n1 ~9 [          ( ycor-of turtle b + y ): x0 ^( h5 _9 M4 v+ Y( v3 J( I
if (remainder who 5 = 2) [set c who- C8 K* C4 \# }2 y1 V6 ^+ r
                          set x ( 0 - Wid / 2 )
" U" r) N3 ~+ F                          set y (0 - Dep / 2 )  ]
* R- B3 {1 `! P1 d6 z/ W5 L' _1 W: X                          set d int (c / 5) * 5
% k/ M+ p9 h$ C; x& S   setxy   ( xcor-of turtle d + x )
* ]0 p- Q" T. d6 P% V           (ycor-of turtle d + y )
$ q. R9 y4 g! V3 s& ]" ~          # A9 b, p5 n3 S( E
            ( s: Y# ^- E& Y; T# l  W1 @
if (remainder who 5 = 3) [set k who
! T5 i% E! {' T" s' _                          set x( Wid / 2)  
5 O! C5 g3 o( K% T. N: \                          set y (0 - Dep / 2 ) ]/ O' @0 s! ^6 G/ M# M/ Z: V
                          set f int (k / 5) * 5
# G& _! T& Y" k# k7 g. x7 g- ]  setxy   ( xcor-of turtle f + x )
2 H! E& r. m: H           (ycor-of turtle f + y )
$ ~2 y4 s: U% a9 n           
7 H" O# C- ?! _5 \, v  d9 u             Y! o' T; h( a0 A  i
if (remainder who 5 = 4) [set g who
0 X) u* T* q3 q! T+ V                          set x Wid / 2
# q/ h4 ~! W- U4 r8 r                          set y  Dep / 2 ]
# u  [# {* t# ?# d* `7 J                          set h  int (g / 5) * 5
6 G3 Q5 x" z7 b  H: l4 K. r  setxy   ( xcor-of turtle h + x )9 z( u! G4 Z5 d7 t) J+ }/ X
           (ycor-of turtle h + y ) - e( ?( }7 x5 {& Q+ r" j* f
                          
0 o" }; c: m- O                          & G- b/ D2 Z' |2 X9 x1 z& C
                          ]
# a' H( d# B: Z/ {) n% ]end& O8 r7 V  W0 m" c+ n- y4 V

" b2 T' h& Q( S5 F( [) F( I/ g[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
" R" O) C( }+ s( m5 ]应该是
- d( \9 j( P9 W3 p" p2 y' Z* Jask turtles [
0 N5 v6 u; ~5 x8 g3 v( P/ ?0 i  Z6 `- @4 ?if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
7 {1 [3 A! _9 X& P  P                          set y  Dep / 2 6 ?2 }4 x( T0 r& Q, A0 e# ^
           set b  int (who / 5) * 5
  {6 T8 M7 N# [4 M    setxy ( xcor-of turtle b + x )
1 h% r3 n3 P3 I) H! u          ( ycor-of turtle b + y )]]" S) y. B. D& Q8 q" l4 B
end6 j8 _# o; l4 f1 f' Y+ W- `$ @/ }
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-13 14:40 , Processed in 0.014761 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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