设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7695|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
) o" ^2 `+ s; v* i& K) H5 W8 `0 \% k6 T( o/ h  C
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
) K! t! U5 ]9 [$ ^7 }; z0 R, ^  v: S$ E, A! n3 {& {5 t' Y1 \& p
turtles-own [a b c d k f g h
# B8 h9 ^7 R0 I" h! I% i0 G  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
+ F5 ^( C+ w, x+ ~, f" D/ F]
9 O7 t2 g) G" |& V) h% lto new: [4 Z& O! i7 M% {+ Q) v9 B* A
  ca
0 f  U" d& i2 T9 |/ [# T  crt 5 * num_of_building6 D' ^# M; B# n5 F+ o
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]! _; t( o1 D9 Q" i4 x7 [9 d
  scatter     ;;keep center-turtle random positions " {& _  X" F- S6 ~
  unit_plan   ;;make up the building plan8 e# g% s/ C9 k* P7 q
end
  Y+ Q, j/ `4 z0 g. H% F# a9 Rto scatter+ u  b: [/ s$ }: f+ T
ask turtles with [remainder who 5 = 0]
/ [- ?$ P" B9 J" D1 M[
7 C( W2 F7 n1 r; U" z9 oset xcor xcor - 6 + random-float 15& e( B% f5 n* s+ r7 V  B
set ycor ycor - 6 + random-float 15
+ w: {. g0 V5 ]4 J) d]
, a$ ?7 f# w, r9 ]( ?8 ~end
* i, O- j. W+ f1 P$ ~0 Bto unit_plan
$ t+ p8 j- I. G1 O3 b2 jask turtles [
1 C# n$ Z, v2 R' C5 `, s3 b' Uif (remainder who 5 = 1) [set a who
6 e3 W0 _/ w% y* \: z                          set x ( 0 - Wid / 2 ) 8 X9 i  A% ^7 r" y# _; X
                          set y  Dep / 2 ]
' g6 L/ W8 {: x9 ]           set b  int (a / 5) * 5
( |! H% n1 D8 @. w    setxy ( xcor-of turtle b + x )7 h: U' w# e0 L/ \+ ^- Y9 q
          ( ycor-of turtle b + y )
8 W  r6 x1 |/ g4 V1 y% v& w( Kif (remainder who 5 = 2) [set c who
" K; e- `( `8 H# D. f  h                          set x ( 0 - Wid / 2 ) $ i5 R( |9 O0 E4 @0 z$ a- S
                          set y (0 - Dep / 2 )  ]7 [8 Z6 H( V4 e
                          set d int (c / 5) * 5  _; s* k) |9 f8 w/ j6 }4 J
   setxy   ( xcor-of turtle d + x )
6 k; ]; u  t. |( t           (ycor-of turtle d + y ) 3 V% q7 J3 D. t* M7 t& W( m
          $ c/ k2 @3 I( N& ^- ?
            8 b! t6 l0 V' d
if (remainder who 5 = 3) [set k who
8 C0 r$ a: o7 b& [) S- Y0 i                          set x( Wid / 2)  / Q) e; S7 _# l! [# Q3 D
                          set y (0 - Dep / 2 ) ]. h. }0 P4 X$ [, A" C5 A* `
                          set f int (k / 5) * 5
9 r0 d# K% Y7 ?' N  setxy   ( xcor-of turtle f + x )8 S2 U9 ~7 H2 ^: U
           (ycor-of turtle f + y )
' T8 A9 L' c5 E* c           
+ J: r8 ~! w2 _1 R1 j           ' D7 Q7 l: f. G0 K
if (remainder who 5 = 4) [set g who9 S$ s4 p$ K1 n- W
                          set x Wid / 2 7 Q) U1 v) H0 B; A/ o# P
                          set y  Dep / 2 ]
8 N  V9 W0 e2 h) f% F                          set h  int (g / 5) * 57 Y0 c1 W+ I. Z5 Z5 s
  setxy   ( xcor-of turtle h + x )9 \/ G0 q# f+ o% Q( Q) C7 h* O
           (ycor-of turtle h + y ) 2 C5 z# h3 [( i
                          3 A7 a4 b/ k& G' I% h, n5 i
                          8 P6 U2 Y9 ]" F9 J4 R
                          ]
8 J* h" J& T" C: U; e. bend* o. n$ [6 h: N" n% ]/ a
* c8 S% y0 T  U# ~9 ?" `
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
5 j2 P/ }) o5 [; T7 M7 V8 R应该是
! e$ E6 B  [3 B1 |ask turtles [& Z, }$ o8 l' |! C
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 0 D8 ^6 T$ }2 a% q, ^$ j4 j2 e
                          set y  Dep / 2 . Z1 t! ]5 q: J% ~4 G# y( X' {
           set b  int (who / 5) * 57 B; Z) p& m9 l8 K) P4 C9 B
    setxy ( xcor-of turtle b + x )
! s* c8 f9 l" r  m          ( ycor-of turtle b + y )]]
) t7 g, }- Y9 Wend
& o3 n( {; ^# S" k之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-16 19:56 , Processed in 0.019290 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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