设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8168|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。! r$ d! g1 a  }+ f/ b1 f# _

- O" K4 k) \0 p% p) ]1 `% t但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。3 w  s$ u# n& @1 f  z0 J
: k6 [/ C3 H/ c) }6 N$ Z
turtles-own [a b c d k f g h
$ O8 v$ u1 N/ l% p  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ) u# {( H6 o7 Y% ~$ L7 u
]' c9 W1 W% i  X  a. B
to new
1 M- z5 }6 K$ \2 W. c  ca
0 K6 e: f( ]  [) `6 Q  crt 5 * num_of_building
& ^4 f) M7 S* g: o' v. D  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]+ o- {! Y8 @" A2 i4 ?, y
  scatter     ;;keep center-turtle random positions
+ _  t( L$ K6 O* E+ b  unit_plan   ;;make up the building plan
* `7 D2 J. {3 O* W! f  V, lend/ g4 `" q) {* {9 P6 d
to scatter
7 k7 z! D9 u% k6 b% _* e" Bask turtles with [remainder who 5 = 0]! v! Q7 [! h# {; s6 L( i( z
[$ E  x2 Q5 M+ z8 ?3 d5 W2 t" ^
set xcor xcor - 6 + random-float 15$ Y9 `, I9 S5 ^* S( v
set ycor ycor - 6 + random-float 15
7 t0 T( o4 J- ^7 O, y- g]* o( o- f! @) x4 U) [$ N
end
- o# q. j5 x6 Q' nto unit_plan 2 s6 u4 a3 v, @- ~3 s
ask turtles [
# a7 J8 @* P% s' kif (remainder who 5 = 1) [set a who $ W+ W. R7 c$ J, G' j$ g' s- \
                          set x ( 0 - Wid / 2 ) , w9 i0 {5 L" }' b# K& n
                          set y  Dep / 2 ]) o* ^" Z4 S' G4 ?% T1 L
           set b  int (a / 5) * 5
( P/ [( W. k/ d* p9 r, d/ a; z    setxy ( xcor-of turtle b + x )0 U0 U) S9 W$ T) o/ k
          ( ycor-of turtle b + y )
! y1 X6 a% `7 c: Iif (remainder who 5 = 2) [set c who! d3 r7 k& _, V/ D% A
                          set x ( 0 - Wid / 2 )
% v% q9 k* B& ?. A) F( c                          set y (0 - Dep / 2 )  ]
! R: k; j! p$ o  J1 y% f                          set d int (c / 5) * 5
. R, A' g3 ~% A. `   setxy   ( xcor-of turtle d + x )
3 c7 Y) b% f- l9 }+ H- s- l& a* i! q( g           (ycor-of turtle d + y )
3 V9 U/ S1 D0 q! [0 [! m          # o& t9 o7 m, L5 @8 i2 u
            ( Q: R1 _& O' o. Y* T
if (remainder who 5 = 3) [set k who
6 U, K9 @. w# ]; p                          set x( Wid / 2)  ; \4 D6 h, f7 M2 V: M- A  ~0 G
                          set y (0 - Dep / 2 ) ]
% g! y5 G3 n0 ?4 ^6 o                          set f int (k / 5) * 5
9 G# m" C0 c; z8 f2 ~  setxy   ( xcor-of turtle f + x )
  \' e% h  ?7 c: W! p; U           (ycor-of turtle f + y )
  R$ G! P* b! O; e           " }- N; g% F' N0 ^' ^" k
           . f! x/ a9 z- @. Y# x6 Z! P  H
if (remainder who 5 = 4) [set g who) u. [! `, g) ^( n+ e
                          set x Wid / 2   |# [* j' M. q
                          set y  Dep / 2 ]6 B3 F6 i) }* v6 @+ z& x$ J
                          set h  int (g / 5) * 52 w5 g4 U* w0 j( F0 _5 u1 _+ G
  setxy   ( xcor-of turtle h + x ), h) i( _9 f0 Y+ D# j
           (ycor-of turtle h + y )   f: H6 ?1 V9 U7 @4 K
                          " F: K  _+ X* M4 Y7 L9 C% q
                          
8 X# d( e% Y  I" B                          ]
* F* q! |/ x4 f" N) ?4 zend" D2 v. t+ k/ M, W$ x1 Q
; ]# ?" c) w0 K7 `2 G5 W0 T8 k$ |
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,/ l1 p* R* F" Z) B/ X
应该是
$ S& o# L) f$ N" G: y: wask turtles [7 T9 j$ x+ y+ |. d! X9 B
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) : b, s# I# z/ e
                          set y  Dep / 2
" \5 h% l2 s: h9 \           set b  int (who / 5) * 5
- v( @9 c4 y7 Y3 {( g1 x    setxy ( xcor-of turtle b + x )
4 R" W# _7 A  N! P          ( ycor-of turtle b + y )]]
, y) ?0 d- d" x4 {end: j' a/ A) M$ K& Z! a4 G
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-14 09:44 , Processed in 0.016893 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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