设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8235|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
- E, Q& j0 a. E! c, \8 \6 m7 }7 M5 G) t5 g' {8 q1 s. b
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
  i. f6 L% F4 y# [' t3 }$ T" T3 W1 ^5 e5 _% E# r% t
turtles-own [a b c d k f g h
7 h4 B; B' [% u2 e( i) J3 i" g  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
1 _. w( J3 b, Y]
" ~: A( ^3 n, \" Dto new. c9 M+ m& r/ x' y
  ca" K" l! R2 i+ G4 S" f
  crt 5 * num_of_building' c, ~8 F7 y! l$ m1 n1 p' ~" q
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]  g: `$ |" Z. |. y& t
  scatter     ;;keep center-turtle random positions 3 v. H( D! U  Q& [* R5 \, q
  unit_plan   ;;make up the building plan
% L% i& V7 p( X9 F+ d$ ]! Zend# ^2 e# I, ]) b& v' P
to scatter7 f% v/ ]' ]+ x
ask turtles with [remainder who 5 = 0]- N. f! R" \" N3 }% P
[: z, l/ k- H/ `& J! a% p
set xcor xcor - 6 + random-float 152 }( [' I8 |: V& n" N, `1 a
set ycor ycor - 6 + random-float 15
6 {+ b9 H$ h( a]
8 I' I# \; |# S' Kend4 f, q+ t: a5 C/ n7 _( v
to unit_plan
4 R! f# g/ s' r4 U  I* Pask turtles [
4 a) i: E) K1 |4 n# L* W: H! ?if (remainder who 5 = 1) [set a who . U1 Q* G! U. O2 R8 e! R* B- Q, r
                          set x ( 0 - Wid / 2 ) 1 T' J+ s7 e+ Y- I) \# Z8 G6 F+ U3 \
                          set y  Dep / 2 ]3 ^4 H7 [  ^; Z3 J, d4 M3 G
           set b  int (a / 5) * 5* {" v. F; t& e
    setxy ( xcor-of turtle b + x )2 |- q. |5 H7 p- ~& C3 n
          ( ycor-of turtle b + y )- ~, w" S% s. u5 c) {
if (remainder who 5 = 2) [set c who
4 C% e# \2 v4 z5 t; @* k0 q                          set x ( 0 - Wid / 2 )
& ^. d# {2 m6 r7 F. M                          set y (0 - Dep / 2 )  ]
! l* Y" H6 ^* s! k' ?  z                          set d int (c / 5) * 5) |) f  Z7 B8 t- s0 I) Y
   setxy   ( xcor-of turtle d + x )% o  n; W! Y6 [$ s0 n
           (ycor-of turtle d + y )
! A5 M; p9 k8 g/ b  s8 h          3 p2 \' M1 ]# I' r$ t
            / F0 f$ F0 n  w% q
if (remainder who 5 = 3) [set k who- e# X. ]/ |" {: Q7 v% J) Y% W
                          set x( Wid / 2)  ; P4 H& T' E& H: X' C8 ^
                          set y (0 - Dep / 2 ) ]
: m: W$ d! B' R8 G0 V, n3 T$ a3 Y1 [                          set f int (k / 5) * 5
6 p: h6 d& J1 p  setxy   ( xcor-of turtle f + x )
1 h) S  \; b0 R* c, k$ t* p           (ycor-of turtle f + y )
0 Y1 S5 A: L. i$ U: O, [           
: a0 Z$ \) C- f           
7 n) K# H. t  U1 gif (remainder who 5 = 4) [set g who
, F( Y7 K3 ]/ x. h, @6 J                          set x Wid / 2
/ Q6 S# J; x5 ]6 c8 B                          set y  Dep / 2 ]* P- f* x) P" `! W
                          set h  int (g / 5) * 5
* j3 y  M) Y1 j5 o2 u, e" F1 ~2 v  setxy   ( xcor-of turtle h + x ): m! D- S+ B- Y6 o
           (ycor-of turtle h + y )   m, i3 V6 f: K; F7 [& B
                          
" ~+ E, b( h* T- [                          
6 \; i5 p4 [4 `; @. r3 \4 c" Y  w                          ]0 o# s. ?1 {* W0 z9 G4 K: W
end  @1 i1 ]0 N5 n  Q4 Z

2 y* {: t$ d. @$ z5 \2 y$ ?[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,' d) |; ^" d1 }  h# @7 ^
应该是, h# {; \% X3 i$ H
ask turtles [
) |" Y% v' w( O1 F. p# Z9 X# @% Zif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 0 c. A) W/ d: w
                          set y  Dep / 2 , `2 c7 b2 l  G6 i% `  t7 M
           set b  int (who / 5) * 5
$ @( h, v9 t; Z, Z& O9 G5 l    setxy ( xcor-of turtle b + x )  k3 F# y, ]0 V6 \7 {
          ( ycor-of turtle b + y )]]; g, v0 d' v7 K& G# n7 H' _
end. w4 e6 x: o8 G% ~, h
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-22 15:26 , Processed in 0.014885 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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