设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7289|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。5 P- P. M; v) ?+ Z9 h
% p8 M6 N( O9 L3 S! q
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
* n+ z) E& ~, ~
' {9 \8 |: \: j$ e; @7 yturtles-own [a b c d k f g h8 g' T% q6 E" G* P5 p
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
: _' g! i1 F% B: k% P2 O]3 x; y5 E/ A# f# A" X9 O3 |& l1 U
to new6 F$ Q% t" Z% `9 t3 g
  ca
0 i) S- W6 a- \9 H  crt 5 * num_of_building
; z3 l8 K' m: ~4 X  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]5 T( ^- L9 Q( ?. P9 A
  scatter     ;;keep center-turtle random positions
# k6 @) a3 A8 g7 [' d) u! d  unit_plan   ;;make up the building plan
$ W3 ]; P  {) X: Y& Xend
6 I1 G( l- A' @1 \5 D! Gto scatter: r& C1 F  `/ H) d% m$ D; T( n
ask turtles with [remainder who 5 = 0]
& t* S% M3 V; N  F( L2 `8 B[
. J$ m( u/ }4 i( Q6 x4 zset xcor xcor - 6 + random-float 152 l; S1 x: x2 H8 J3 i' E+ f
set ycor ycor - 6 + random-float 15: ?( Y$ j5 Y1 K  ~2 Q! |
]5 r3 F( ]  a, z# e' c: C
end
5 }  O( x, q  I! u$ v$ p+ k5 I( Qto unit_plan
( ?, g# T1 d4 X  z4 x4 Iask turtles [
! M: q* l9 c& e1 H$ r( tif (remainder who 5 = 1) [set a who
5 L9 u( r  e4 G! F3 s* U# _& l                          set x ( 0 - Wid / 2 )
+ Q) o# D$ q+ j, D6 z6 x- }                          set y  Dep / 2 ], ^* A  W3 a3 `6 c' O
           set b  int (a / 5) * 5
9 O- u9 K% j0 `! D0 a* q    setxy ( xcor-of turtle b + x )
; u1 c+ I2 _' Q1 F; q1 _1 H          ( ycor-of turtle b + y )
3 k$ N& H, C6 }  I# l5 |& \. i% Bif (remainder who 5 = 2) [set c who0 {/ o: y2 o2 r1 N6 h/ X3 d) X
                          set x ( 0 - Wid / 2 ) - `$ [$ c5 M7 V/ t" V/ R
                          set y (0 - Dep / 2 )  ]8 l( A! ]) ^& p: Q6 \
                          set d int (c / 5) * 5( D0 d3 d' a$ {+ U' {% B
   setxy   ( xcor-of turtle d + x )
$ h3 J8 W% q# |. t           (ycor-of turtle d + y )
  [. b7 T, ~8 a          0 n0 w2 Y+ G% J$ ?0 V4 b/ J
            
1 D# [9 ?0 c) q4 k- Cif (remainder who 5 = 3) [set k who5 @6 A% L" q4 w7 u* t+ Z
                          set x( Wid / 2)  ( E2 k( c3 a+ L+ O) d6 N- r
                          set y (0 - Dep / 2 ) ], A2 i9 e( T% N# w4 Z# @
                          set f int (k / 5) * 5( ]* @/ V7 y$ Z. W* |, O5 n6 S3 x: a, i* E
  setxy   ( xcor-of turtle f + x )
+ ^5 Z4 \# U3 Q9 P! ?1 u           (ycor-of turtle f + y )
8 R6 N- g5 m& F           
5 l6 M5 w- s$ D* B: @9 R- a0 b1 C           ; q9 q  O! L. W& x- U( w+ E
if (remainder who 5 = 4) [set g who
9 [8 N" \. [, |- F                          set x Wid / 2 + P! K# x1 n& P7 p4 ^3 l6 e
                          set y  Dep / 2 ]
' w* G5 c' k, f                          set h  int (g / 5) * 56 ~; g3 P5 q4 @- W: ]
  setxy   ( xcor-of turtle h + x )
( |' X& y  b) W# |           (ycor-of turtle h + y )
& o& R; D# c7 f! s4 a6 P3 q  g                          
, ?4 [. m% `( _6 U9 h1 w- E                          
0 c. s* l  f+ d! Q% B                          ]
8 j) l8 y& U' y2 B; B# o' N! P! |end
. e8 w  G$ u+ X. J2 x, e
" [0 v2 @# q  c8 j& r[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
+ x- g$ i, T/ C! ?应该是* ?, `' w, g& K. C( T: t
ask turtles [
9 w0 E( Y# o3 T5 s. `9 Wif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
2 J3 _7 w8 j6 R                          set y  Dep / 2
+ N/ P& q8 |# e, u* j           set b  int (who / 5) * 5
$ M8 d( u" I# w, X/ ?9 Y    setxy ( xcor-of turtle b + x )
* u, f1 }' f" d$ p6 o          ( ycor-of turtle b + y )]]
$ x! [0 a" q) P! T0 ^- e  Uend: Y& y" ]7 P! X8 k) \  x% q
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-25 18:06 , Processed in 0.016088 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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