设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5955|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
8 u7 o: M& g# ]$ }( d. U
* D" L5 ~8 [3 M8 \但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
2 }: _0 \* Q# S# v' C1 v* e: `" A# H: i( s& _/ Y7 m
turtles-own [a b c d k f g h
% V& X6 I3 m9 h/ X9 o% `  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
# S0 E  o: p) i$ f]. }, `6 H6 u6 K6 |4 f' l8 j
to new; F8 S$ p! U" w( D
  ca
4 q5 y4 J) n1 q* S" i7 b  crt 5 * num_of_building
9 G3 p4 }. `8 C" J; ^$ h5 r$ N  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]" |' J$ i' L, p6 E
  scatter     ;;keep center-turtle random positions , k) t5 z+ X+ O5 i
  unit_plan   ;;make up the building plan" y" J/ N) \8 g9 J: q, ?1 `
end
* ~( o1 Y3 P, t* h7 j+ r. yto scatter
1 Z& ^; @; a% Z, ~, V" ~+ ^ask turtles with [remainder who 5 = 0]1 j3 B, Q$ @% A# a9 v! A
[6 k# g1 b! z$ A
set xcor xcor - 6 + random-float 15
! d" R( g* k" a" \6 N1 Fset ycor ycor - 6 + random-float 15  c) ~. H! v# ?: u- @- L3 s% Z7 L9 Y
]
6 D* n0 i/ N+ S3 r4 }, @end' S; [" A' }( O5 u# V  _
to unit_plan
  N4 N) w4 h) z+ Z- s6 Y. dask turtles [1 x# k0 O( k0 K+ _3 C
if (remainder who 5 = 1) [set a who
/ T! M2 l8 K- {: d# y: k; u                          set x ( 0 - Wid / 2 )
2 ~1 p* W! P' Y# k6 J: j+ @                          set y  Dep / 2 ]1 r: z) A+ ~8 N0 N/ A7 l# Z
           set b  int (a / 5) * 5
) ^( W- [8 j2 m    setxy ( xcor-of turtle b + x )
, j& M0 P. {5 E          ( ycor-of turtle b + y )2 U! c4 [7 j7 B) q0 S
if (remainder who 5 = 2) [set c who# P1 o" L% `' I8 L: \( o
                          set x ( 0 - Wid / 2 ) + {# E* _, ~9 M
                          set y (0 - Dep / 2 )  ]
" x; W( s0 f, P; D- r: ^! [                          set d int (c / 5) * 50 q4 b( Q- z- e6 r8 O% r% j# R9 a
   setxy   ( xcor-of turtle d + x )7 H3 q% r4 d# |: q
           (ycor-of turtle d + y )
2 P7 r9 g& v; L          5 y/ {0 _+ c- F- c. {
            
6 Y: M' }5 _# uif (remainder who 5 = 3) [set k who
. w6 X) T1 V* v& I) ]                          set x( Wid / 2)  $ R5 U0 \% u" f# s3 n) m6 j
                          set y (0 - Dep / 2 ) ]0 T1 a4 @& ], D. D. i; w1 P3 N9 Z
                          set f int (k / 5) * 5
0 T) V! b- Z' N: V3 `" f& ]  setxy   ( xcor-of turtle f + x )& l0 B7 i8 t5 z% M+ c
           (ycor-of turtle f + y )
5 ~) ~/ x* A. H+ F4 p           ' E6 c# o7 H$ o( t
           ) a1 \" ?4 m1 p7 z" a1 p9 q
if (remainder who 5 = 4) [set g who
  j: C0 f# R& N3 C' H- z! @                          set x Wid / 2 ) s8 Y0 [- s2 e
                          set y  Dep / 2 ]
% k  Q: _# A4 ]2 u5 Z+ J% K2 N                          set h  int (g / 5) * 5
$ _0 V& D7 X' }+ w. H6 w- o  setxy   ( xcor-of turtle h + x )! r% r1 h: |8 A  P0 f/ `2 P1 `$ c# V
           (ycor-of turtle h + y ) ! o$ W1 K2 K6 ^# h, a/ Z) c; Q: X- @
                          
' W* _6 x; J  }% i                          - E: z" j( T# @# C
                          ]6 L9 g7 g/ G( T# y
end# W' }% F6 c, l, b9 m' g# y& ^

$ v' s( W7 X% n8 H7 Q8 c[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
) B0 {% j  x8 a' W; y应该是
7 ^, R( y2 s+ Y4 @+ v/ pask turtles [
+ Q: ?, @( h# @; M! s# A. |if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
( p2 [9 M: ^: @7 M7 `9 i                          set y  Dep / 2 + x  s! B' V- k9 Y" I: w. D" D8 q
           set b  int (who / 5) * 5
" ?3 [& v; n9 s- D+ A    setxy ( xcor-of turtle b + x )
2 D1 a2 F- i5 \6 k          ( ycor-of turtle b + y )]]
+ c: j. z- F5 j$ \$ W, Wend
" P4 E4 Y( L" \# b( m. N; s之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-11 21:34 , Processed in 2.373521 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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