设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7985|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。: y1 F1 X# H. Z$ Q2 |# j2 y4 d

9 H. V6 p5 Z% A  B但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
: a) Q7 e, `% P0 p
  B! \- n: b1 V+ w+ _, aturtles-own [a b c d k f g h
2 [6 t2 W  _' p6 A2 B, d  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
- W8 Y8 i3 K9 F9 h: \; c7 G& j]
: d/ N0 V8 `% Ato new
6 O0 L7 j/ S0 ]  ca
4 }4 O. W* E0 p  crt 5 * num_of_building$ ~7 L5 E# m' w: F4 G
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
% J# z) p8 D8 O" c; j. i  scatter     ;;keep center-turtle random positions
& {: f8 Q2 b* E4 {( K# ?9 n  unit_plan   ;;make up the building plan
* L1 [) q$ U/ ~: X& h( Rend* o- o7 U& Y  ~/ P6 T7 Q6 r
to scatter
3 [/ N: f. N/ l" E3 S8 }1 Wask turtles with [remainder who 5 = 0]6 E' j) s+ u+ y9 Z2 A/ e
[
  l& @0 M/ i" }' y/ h) F: uset xcor xcor - 6 + random-float 15
' \8 r. l3 F' G; t$ t; y8 B. F+ I8 Qset ycor ycor - 6 + random-float 15' O3 d- L+ n5 N
]7 e9 ~# ~) R) V8 X1 M, I( @* k5 S
end( S1 ~/ O0 v" @: R  B/ m1 j
to unit_plan
0 D' e& C/ Y! B4 W% oask turtles [+ D8 U. {6 p; N! y
if (remainder who 5 = 1) [set a who
3 x" e" ?+ w& }' B3 `" }& I4 B                          set x ( 0 - Wid / 2 ) ! q6 l: Q2 C% b8 p
                          set y  Dep / 2 ]; M2 V8 O- t, o3 T
           set b  int (a / 5) * 5' Q) T! s9 R, P$ V2 q
    setxy ( xcor-of turtle b + x )3 b7 f5 Q% J7 s
          ( ycor-of turtle b + y )0 h4 l* y, w7 a
if (remainder who 5 = 2) [set c who( j7 [/ ^+ U& C/ K0 R; i4 w
                          set x ( 0 - Wid / 2 )
$ U* j- K" W8 L4 W8 C4 ~                          set y (0 - Dep / 2 )  ]) `2 n# |4 ~9 W
                          set d int (c / 5) * 5
: _8 S, D& r$ k   setxy   ( xcor-of turtle d + x )
5 l7 r, i! Y. U5 ^/ E           (ycor-of turtle d + y )
! X; H+ l- `5 X" @/ @: }$ l         
3 O0 Z2 u* \, ~; _, s            
' Q8 s" y3 s9 ~. l$ I( E! W6 T1 eif (remainder who 5 = 3) [set k who5 s' B+ y0 @) y- O
                          set x( Wid / 2)  $ r" Y3 k) ]5 T# S+ X: l
                          set y (0 - Dep / 2 ) ]7 @1 a; [7 `+ |' j
                          set f int (k / 5) * 5$ m# z5 k6 O- x7 e
  setxy   ( xcor-of turtle f + x )
1 r7 g7 A7 Q1 W, C0 b           (ycor-of turtle f + y ) 9 h5 x" w# J; q
           
7 Q; ]! x* g6 z- z/ [  G6 [           
% J& L$ [! z& E4 Y$ @/ [+ jif (remainder who 5 = 4) [set g who
1 l  z: s9 o! |" m# [* C                          set x Wid / 2
- R5 P; g; T1 G8 g                          set y  Dep / 2 ]
+ v' J4 @! Z2 t  a2 w% I8 w' H* T6 ?1 V                          set h  int (g / 5) * 50 Y/ D' ], v+ S
  setxy   ( xcor-of turtle h + x )0 J$ {& ^8 j3 ~8 x& x
           (ycor-of turtle h + y ) 0 G( g( q, V; T3 B4 q) Y* [
                          
# V7 O* D- Q( G, @                          
2 J* W% k% e+ t! ~                          ]
; Q& x) V+ g, z! k' send8 y2 r6 Z4 ~4 s, u
8 C$ r9 H! X: G# I5 z
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
! v$ r. J! D* e5 [应该是. a7 o0 P2 G6 O6 O
ask turtles [
4 i6 i6 h9 e, a6 O1 `if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
+ Z4 E% e  U$ F4 G- e                          set y  Dep / 2
1 V3 w% d, C6 v# T$ L$ }7 O           set b  int (who / 5) * 51 b+ U' O; l0 P0 p5 h2 ^& `3 L
    setxy ( xcor-of turtle b + x )& a& A) f& ^3 N8 H0 Z3 a% Y
          ( ycor-of turtle b + y )]]0 d; P% G' D/ Y: y/ b
end
( u( A3 s& v3 R; {之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-24 22:15 , Processed in 0.017039 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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