设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7860|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
0 N5 w# k2 a  ]3 [, n9 X8 j! |0 O
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
: `# ^3 O$ K7 j& U2 i" ]" Y: S
6 n8 U5 @# u3 L( Mturtles-own [a b c d k f g h1 f( |6 a, J' _$ g' h  V/ M+ _
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
1 i6 l2 H; ~% T0 `]  Z0 b& K( ?1 F6 Z
to new$ T9 a6 V& x8 |
  ca
# \* a. R) [2 p) f$ F  crt 5 * num_of_building+ |- W1 T2 _5 _/ B: u) S7 E
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]1 ^- U8 N- p' E, g
  scatter     ;;keep center-turtle random positions
0 `* _: h1 L2 t  L0 [  unit_plan   ;;make up the building plan
- W* c1 a) r, I; ?  i3 h/ n; Dend
' O5 P( s# _" v$ Gto scatter3 o: V0 z" @. M, N# T
ask turtles with [remainder who 5 = 0]
0 ?4 L8 O( P. b$ K[5 c7 u* Q9 Z1 o# ~" w: l: U
set xcor xcor - 6 + random-float 15
! O" N; ]( R' F# O- r3 [8 ?set ycor ycor - 6 + random-float 15! o+ \( E* ^/ p5 D
]
) x- q8 M  d, k8 _5 S  E+ V7 f& Dend; Y5 Y( W/ q+ n7 M8 o. R, t  X7 ~
to unit_plan
0 J3 j, C, X6 z: [2 e' @# [- hask turtles [
2 b0 l7 E5 u3 f: |3 fif (remainder who 5 = 1) [set a who
( ?  @- G) t3 @) a$ j' Q                          set x ( 0 - Wid / 2 )
8 j2 z  F# n0 x) X                          set y  Dep / 2 ]
: k, d  d& M! r           set b  int (a / 5) * 5
  P; L1 Z. G4 M6 S7 d( m1 D% r    setxy ( xcor-of turtle b + x )% l) D1 m3 D4 e) g: H1 m( E6 l
          ( ycor-of turtle b + y )
5 I+ d. e' B3 ?if (remainder who 5 = 2) [set c who5 K% k+ `8 A9 @4 F7 m
                          set x ( 0 - Wid / 2 )   w- B  l. I# F
                          set y (0 - Dep / 2 )  ]
! ^8 v: _3 u+ O- S) }, Q/ X) _                          set d int (c / 5) * 5# H% C0 @8 W+ U* ~$ n  m2 v
   setxy   ( xcor-of turtle d + x )$ `; }1 z6 K- i) i* A- k5 }
           (ycor-of turtle d + y )
! Y! n6 b2 N+ A3 q3 i         
7 F1 I; s9 d7 j5 U( ~3 `            
& d' d# ^1 E0 B9 w3 rif (remainder who 5 = 3) [set k who: ]& Y9 F- J+ A1 p) @' \& b& G( ~) N
                          set x( Wid / 2)  
& f9 M+ J+ @6 y: G& c                          set y (0 - Dep / 2 ) ]& P" [8 G1 {6 _
                          set f int (k / 5) * 5
7 t0 Q! T/ U% i' o7 s  setxy   ( xcor-of turtle f + x )# _1 X' c2 |5 s$ V
           (ycor-of turtle f + y ) . @% E' f2 L- Y5 i% N
           
' B, t$ r/ P( X# t. b# |; x  v           
( N5 s- N! H' |+ l* ]- E( {if (remainder who 5 = 4) [set g who; z) k0 M: B: h8 Y8 n1 F
                          set x Wid / 2
. O9 W* F8 S3 Z( [8 {: j                          set y  Dep / 2 ]
8 ~3 N) s( w! D: @                          set h  int (g / 5) * 55 j  u& b* T1 F( h. c# I5 [
  setxy   ( xcor-of turtle h + x ): E0 a; u- V8 j$ ]1 [* u$ u
           (ycor-of turtle h + y )
7 D' s! h+ ^) h, P- C+ P                          7 R0 d+ j  b/ E6 [4 a
                          
, F' D, M+ r% b, Y! t                          ]
; Z) @9 P9 F1 N5 d5 Cend( _5 |; a# W9 u) H0 b4 s

/ k" k$ S7 ]! `$ k! e[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,6 W2 e. B$ j: q" {- [
应该是
; C1 r$ B+ x( J1 dask turtles [
4 W* O7 u7 o: u/ o6 b# g  mif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
# j9 \! F; ?; d                          set y  Dep / 2
& K0 `9 |& C/ x  t0 J! m7 [           set b  int (who / 5) * 5
5 X+ P! a# s0 W! F; B0 T' I    setxy ( xcor-of turtle b + x )% @- ]8 {- q! {: c, x) Z% Q
          ( ycor-of turtle b + y )]]/ T" v1 D' P; u5 o( R  |
end
# y4 e: {( @7 F8 z5 d- m( w之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-11 21:34 , Processed in 0.019252 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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