设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9032|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。; |! Z" `' S( ?9 I/ l8 A+ t4 I

% D5 P5 f7 t5 ?9 b  J7 ]但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。6 \0 d* T% G4 H( N+ D& u- }+ t5 H0 e

, V' E- [. X7 k" M6 M: yturtles-own [a b c d k f g h) @6 r5 `5 h! T6 l! z
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ; u# m# M$ }+ J- H0 J8 `
]
* J# o$ e! R  mto new4 u! h3 r! T+ A
  ca# r* q( g- Q/ s" e( A) s* G
  crt 5 * num_of_building. t" q7 [* I7 u: W$ Z+ y" r8 Y
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
5 K9 o8 @% U, w; H+ l  scatter     ;;keep center-turtle random positions 6 ]9 ~4 G' H0 i+ \
  unit_plan   ;;make up the building plan6 W0 g$ h' k- H; x0 c
end$ V/ E; _+ e8 e- i
to scatter2 U: s+ b  u- i* E
ask turtles with [remainder who 5 = 0]
4 J9 b! ]1 y' T# j7 k: l% w[
7 l: ?& v5 U0 z0 gset xcor xcor - 6 + random-float 15
7 d  A0 f9 g$ [) ~6 Tset ycor ycor - 6 + random-float 15' e+ T% B* {7 x/ Z6 \( ?3 c
]+ r4 }! S1 L7 p1 e3 i
end; }! R7 c" ?. g6 \2 c) F( l0 K
to unit_plan
& `7 Z2 P. L) mask turtles [  r; T; @6 S" L( V
if (remainder who 5 = 1) [set a who ! i- i5 v# p2 ^
                          set x ( 0 - Wid / 2 ) + Z+ ^( H3 K1 D) \
                          set y  Dep / 2 ]$ G* E% d3 o% N) J) c1 M  G4 N1 Q0 {. @
           set b  int (a / 5) * 54 x* x, B1 A- i+ i+ o
    setxy ( xcor-of turtle b + x )6 R9 a- D" w4 k# a+ s1 }# {
          ( ycor-of turtle b + y )# z) z0 `5 U# c! z. o1 p
if (remainder who 5 = 2) [set c who% R" u) d5 Q; t  J
                          set x ( 0 - Wid / 2 )
2 @& O0 n- e2 r: J4 c                          set y (0 - Dep / 2 )  ]! G  q1 Y5 Y$ `8 I
                          set d int (c / 5) * 52 A: W" E' D( C. Q3 j' D- n
   setxy   ( xcor-of turtle d + x )
  v/ T2 ]' J7 B/ R# A           (ycor-of turtle d + y ) & N" u0 f0 i" N
          ( G" n6 N- |5 {1 Y4 D+ d4 _9 Z/ Y
            
+ w3 ?6 |4 P; e: z8 E1 X/ c# R1 aif (remainder who 5 = 3) [set k who3 y' T1 h6 W9 T/ Q/ A  n
                          set x( Wid / 2)  , |- d/ d$ U6 P. I8 g1 c
                          set y (0 - Dep / 2 ) ]" ]* ?4 M8 k. N+ A, e
                          set f int (k / 5) * 5
' k! h" g+ L7 x! b9 e, Z+ R  setxy   ( xcor-of turtle f + x )
# D1 @' ^* H/ O* b9 b; E2 a* x, K# g2 \           (ycor-of turtle f + y )
2 q5 ^4 M' @% V( ~; d  O           ' T; [4 i5 q2 y9 x9 w( C
             U2 M- F, m4 r+ s# a4 D
if (remainder who 5 = 4) [set g who
+ U/ M- o( U, ^; X% P                          set x Wid / 2 & n" u& H2 k! p. t3 S' D
                          set y  Dep / 2 ]1 {  y7 M5 k9 {7 C; `" ^, q
                          set h  int (g / 5) * 54 v, @1 v1 t- [; E
  setxy   ( xcor-of turtle h + x )
) u* N4 L$ _! F  Z% t           (ycor-of turtle h + y ) & y* K, r+ ^1 Q+ F
                          ( D! _7 @2 ]+ r$ d
                          % J0 A% p* i. Y; R
                          ]
9 a/ L8 w2 Q0 T$ N- M5 mend9 k% |, o) M# x6 y) H: l

2 d0 e) ~2 q& F! C" }[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,- G) Z  l  ?5 `( V. i
应该是
3 g- P% e/ @2 D! bask turtles [5 J! T! s! ~% |
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) / a& G7 a$ \* I
                          set y  Dep / 2 ! M( ?8 E9 ~# J; G2 R5 _
           set b  int (who / 5) * 51 d; ^" ~+ S1 x0 k4 U5 z! K3 \
    setxy ( xcor-of turtle b + x )
2 l$ L: D+ l7 \, m6 T6 w          ( ycor-of turtle b + y )]]1 @2 \) ^0 r& D) c
end
, @( Y3 z# V' U) @( |1 S# N之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-10 07:57 , Processed in 0.017936 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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