设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6925|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。1 s* ]- ~+ O9 I; [
3 |  M. X4 \0 B# T* G9 B
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
( Z: V8 C/ \. k# [
  K1 B( w; ^; }0 M9 H! oturtles-own [a b c d k f g h
/ S3 r8 Z, ?9 V- y  f- G* H2 X  x y     ;; these are the leaf-turtle's offsets relative to center-turtle / s1 V7 G; U8 f( D
]
# T" [/ n. W. Uto new$ V( m: g5 ]( U% J5 ?
  ca( I+ I# z1 n8 N5 d; r, H& }  @0 t
  crt 5 * num_of_building/ R4 d) M5 [3 T! s
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]], {2 \7 ~4 Y) M1 A1 f
  scatter     ;;keep center-turtle random positions
! H, k+ Y2 X( C  unit_plan   ;;make up the building plan, V, E6 r1 f, n- k  s) p
end1 Z9 \; I! K# |7 Q& e( B0 r6 }
to scatter
& k* N  j0 I' h; i, Bask turtles with [remainder who 5 = 0]
; D4 _" i( p7 C, X4 d/ P- ?[
/ `' L' Z$ h; H8 M( Eset xcor xcor - 6 + random-float 15% m; f$ H" {7 Y
set ycor ycor - 6 + random-float 15
4 J. A0 G* J3 D! E& s/ e& r$ q]0 U- ^7 I9 \  s) t* B/ j) C& u: e
end
$ @" Z; u6 H4 [1 d6 s5 Vto unit_plan
- i' O1 n- \6 M) Z$ L$ D; f. Aask turtles [
  ?  W2 P+ q6 i* Eif (remainder who 5 = 1) [set a who ! K7 a+ n2 V+ {' t2 ]# {; M  G
                          set x ( 0 - Wid / 2 ) ) W5 k! U. p3 n
                          set y  Dep / 2 ]7 i5 @4 s& T/ I4 J9 W
           set b  int (a / 5) * 5
7 v! h) ~9 D0 L- R    setxy ( xcor-of turtle b + x )
( o7 z6 r+ K& d* Y8 n9 K7 C          ( ycor-of turtle b + y )1 x$ U& M5 }4 F8 O4 g9 `
if (remainder who 5 = 2) [set c who+ T1 N' D/ F* w
                          set x ( 0 - Wid / 2 ) ) _2 C2 o8 n/ O) g5 {& m6 u
                          set y (0 - Dep / 2 )  ]
! U+ ?8 q( X; s. P5 M                          set d int (c / 5) * 5
. F% ]$ u* ?3 l5 M2 q' g: g   setxy   ( xcor-of turtle d + x )
; h& c+ g& K2 c; k2 u           (ycor-of turtle d + y ) 6 \9 z8 ], v* C% C
          - y0 H9 K. x, b' Q6 H
            
& j: B5 T0 c) h% Pif (remainder who 5 = 3) [set k who5 |" |3 ?3 f. \& P3 \
                          set x( Wid / 2)  & s5 @: B# H+ `
                          set y (0 - Dep / 2 ) ]
5 i4 L- B- z  o& R* g: v3 I# C                          set f int (k / 5) * 5
! X+ X  Z6 \  Y* t$ l/ b& e  setxy   ( xcor-of turtle f + x )
6 O1 r- P7 F2 G& |, l           (ycor-of turtle f + y )
: l; U: j7 U6 @' |% }           
0 ~2 L' t  s7 e4 D9 F           
% M4 _8 J( h6 W% l/ q  |if (remainder who 5 = 4) [set g who- w: x9 t5 {8 Z5 F$ L( a
                          set x Wid / 2
! f0 H& G# N' m0 @' g# y. B                          set y  Dep / 2 ]+ h0 {$ Q1 S8 {, M7 D
                          set h  int (g / 5) * 5
" i2 F% }& r: h1 q, r7 P* f2 O  setxy   ( xcor-of turtle h + x )
' n. y# e) v: F' I% u% O           (ycor-of turtle h + y ) 7 B/ y* C/ ?; ?0 H' X5 G) P
                          & M: X6 l' O$ E+ M9 y- U
                          
5 C/ a& S6 D  b# D/ e  O                          ]- X# q8 d. \6 l' F5 o& ?3 I8 s/ }
end6 R: l4 Y4 K0 ^2 d

* Y3 J9 d# e4 v0 U2 J[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,- {. P0 {  Z7 B  y; v% P. b) `
应该是
) T! P; M9 J: Z$ |; }- ?0 hask turtles [
  [9 d$ E1 |8 {if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
2 H  S8 N5 |* h" J8 _% m' ?' c4 n                          set y  Dep / 2
, m' V8 }- x; R# e( z2 o7 q           set b  int (who / 5) * 53 u: |' Z4 a# `" H8 x8 ^1 o' i
    setxy ( xcor-of turtle b + x )& Y: Q8 @/ `6 F8 @
          ( ycor-of turtle b + y )]]
9 V0 S2 x6 \! g* q2 cend
$ Z9 Q! K8 c7 Y3 t2 E- z2 n$ q之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-10 18:24 , Processed in 0.016191 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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