设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7556|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
/ I3 H4 ?5 b# q* M% x; m
+ l" G5 {) [2 B* |0 z但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
3 ~2 o# m( l% n# H* ^, N, E  I  G! Z
turtles-own [a b c d k f g h4 b9 p# n9 u, j4 d' }$ |# {
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ' s3 }. Y) d3 v/ u# I2 B4 r
]
( R. M: v1 b2 F5 l, t  K; ^* cto new* W( _2 K) T; r1 H" k% W
  ca
, ~, X$ F  A% X3 i, A  crt 5 * num_of_building7 n  }! u5 V8 W: z3 W& Q, e
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
7 s( _: {5 `; l  scatter     ;;keep center-turtle random positions
. I& O0 p" w% y: n- [* Z. F: T  unit_plan   ;;make up the building plan
/ X0 `7 g9 ?4 u1 \* S7 eend5 j0 L5 q% Q: g$ l
to scatter. R( Z! L$ L/ g
ask turtles with [remainder who 5 = 0]
* U% ~  ?4 ~' Y: x+ V& l/ X3 T+ t! w$ d[; [4 e8 M: M1 E( K3 w
set xcor xcor - 6 + random-float 15
2 C* M2 V  a, |" e& iset ycor ycor - 6 + random-float 15" E+ I, ~) I  L/ O
]0 S$ o6 m) g' I/ L" w* |
end9 H- @1 K3 J  F" K
to unit_plan
  B% ~* J" t: y' |7 T. B/ y1 n2 X3 \ask turtles [
8 v( b$ c; b( z: _+ [9 g5 wif (remainder who 5 = 1) [set a who + [4 M& |0 {0 S0 N2 S
                          set x ( 0 - Wid / 2 ) ' E! V' C: N/ M/ b# k- }: h, k
                          set y  Dep / 2 ]) k6 X2 |5 e2 u& i# x5 c
           set b  int (a / 5) * 5
$ H5 r" s/ v' q+ c2 e' }    setxy ( xcor-of turtle b + x )
% N2 i7 i, b# B$ ]. r4 a          ( ycor-of turtle b + y )9 e, s' T9 d# G0 M5 _
if (remainder who 5 = 2) [set c who; x- F! }, t# q/ a1 I5 `8 A1 E- R
                          set x ( 0 - Wid / 2 )
' z& c* E0 Q* }% ^6 w% T                          set y (0 - Dep / 2 )  ]
* s9 y+ v; z5 z                          set d int (c / 5) * 5
% T" v9 S2 J  H   setxy   ( xcor-of turtle d + x ); Z% g: u( r+ Q( \+ V! `1 P" u
           (ycor-of turtle d + y )
7 S7 b- C$ H$ v          . W+ g* h+ p4 F/ A8 R" |1 M
            
4 O4 i& P' P7 h. K, @: J0 [: rif (remainder who 5 = 3) [set k who( O, E/ Q! G5 O  N: `. _5 E8 S* ^7 Y) \
                          set x( Wid / 2)  * S' |$ b2 C* K, H" G
                          set y (0 - Dep / 2 ) ]$ ]& k; @; x2 R( Z' j# ?. o
                          set f int (k / 5) * 5
7 N% j0 g) U- @* J  setxy   ( xcor-of turtle f + x )4 V% k; D: f! r2 t4 O
           (ycor-of turtle f + y )
* O; t5 Y3 \! j6 N           + P4 c$ D2 [* E7 u5 t
           
7 _% A% U. p! U- A2 ]& kif (remainder who 5 = 4) [set g who
6 R6 M( Z% W0 e7 I% j                          set x Wid / 2
6 X. b% b, B, J* L. q. ?                          set y  Dep / 2 ]
2 x2 s( T. D# t0 y! S5 ^9 X                          set h  int (g / 5) * 5$ K" P/ U; s2 e' ?
  setxy   ( xcor-of turtle h + x )8 z0 H4 \5 e$ _% h* {# `' P/ ?
           (ycor-of turtle h + y )
9 U, d6 m6 b0 @6 [0 n, M( p                          7 G3 ~% p4 K7 l+ p
                          1 m6 z/ a; G7 [  c5 R$ w
                          ]
% ?1 F9 s7 W' }; pend
; M- ^' h) S/ L
7 Q" _$ O4 g+ C# [# M: a[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
  h/ o7 w) \+ g1 O) u8 J应该是7 ~9 C8 U6 }; `: J
ask turtles [
2 p2 P$ y3 L0 D/ t, Gif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) & `5 r7 |1 O8 k% @/ ?+ J
                          set y  Dep / 2 + M3 U* j7 {5 z' J" x+ |& S. g
           set b  int (who / 5) * 5$ [1 J" g5 f! `" l7 D
    setxy ( xcor-of turtle b + x )6 o2 z$ Y3 x# S" s0 |) x* ]9 T
          ( ycor-of turtle b + y )]]
. J+ c) y. r& z: O" bend$ j+ e9 z' `0 `
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-26 06:34 , Processed in 0.016018 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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