设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6815|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
3 R" z" M5 a  R6 n2 g7 n
1 t- M8 t9 l  c# R9 ]& t+ }但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。' k/ ?* c, @: \# P4 Y, X0 x
5 k& v. D& ?9 p$ d9 X8 f
turtles-own [a b c d k f g h2 g0 Z6 T, w% W' o
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle - u: r9 A" Z! {5 q; _7 M
]
* ]" z  y; V0 W( ato new
* Q  Z1 z) W0 Q. u5 y7 g; ^' {  ca
2 g& y) V2 n9 G# \  crt 5 * num_of_building  z8 U$ K# _: R% y+ _
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
2 y- T  ]( |! C  scatter     ;;keep center-turtle random positions
5 ~$ F( i' t+ n  J  unit_plan   ;;make up the building plan
7 c, R3 z9 R; {) g- A2 |3 Zend) U# Q# ]9 t6 b; P  D1 _0 `) b3 d. n
to scatter6 s9 f+ [& X# y) i
ask turtles with [remainder who 5 = 0]
+ _+ _& W( ?- h* d) P+ e[. [; @% ]' U7 d# g. L* R
set xcor xcor - 6 + random-float 15. W% h- p, d. d6 F
set ycor ycor - 6 + random-float 15
; R4 D& e- [* ]7 N" ]+ `]$ {8 L/ z- J$ V; a( s8 ?9 b
end4 |8 c5 l. L* V3 g1 `: [
to unit_plan ; q) E8 R) s, V* j4 }
ask turtles [
1 `* t" D0 G# n$ Pif (remainder who 5 = 1) [set a who $ V" s. @( ~- R* D( x6 \/ f# `
                          set x ( 0 - Wid / 2 ) % M' y! k5 \; \6 S# {
                          set y  Dep / 2 ]- S. o) q  I( t4 h) ]" U4 a, G
           set b  int (a / 5) * 5
& b- `  E& P$ r% `/ k( e    setxy ( xcor-of turtle b + x )
0 A6 O* W/ D! }# x" _- s          ( ycor-of turtle b + y )
( g9 d; h) e+ I+ ?4 I7 @3 h- P+ Rif (remainder who 5 = 2) [set c who
: [8 _6 a; s- b1 m  K                          set x ( 0 - Wid / 2 )
2 B" W1 {* a- K& o3 Z. A( {                          set y (0 - Dep / 2 )  ]
( S, S1 j9 A1 X+ O8 M8 R/ F' J                          set d int (c / 5) * 51 T% _6 s' N2 m# O
   setxy   ( xcor-of turtle d + x )" k0 n" m6 Y9 ]# n& D) R& A
           (ycor-of turtle d + y )
0 a& F3 n1 A9 t9 l0 G" W& ]          - x$ n' d- l) }1 |( [9 w) w6 A
            & J# \4 @" N3 H& \$ E
if (remainder who 5 = 3) [set k who
: r' j& ]6 J! k) A- A5 K, J' d                          set x( Wid / 2)  
' R4 J! o6 K! ?% p# q+ W+ g, C8 a                          set y (0 - Dep / 2 ) ]
' Z; A% \7 N2 o" z                          set f int (k / 5) * 52 Q; W4 s2 u4 _  A
  setxy   ( xcor-of turtle f + x )
( l" F# t1 c; n5 n6 X& g  a& o           (ycor-of turtle f + y )
5 r  {" E1 K0 x7 G" W5 `  U  e* R             z. B2 D. h: @* V9 r
           $ e" `. W! Q; U
if (remainder who 5 = 4) [set g who2 N4 ~7 `1 l/ Z/ O
                          set x Wid / 2
/ k1 l  D! S1 j" y! {  E                          set y  Dep / 2 ]
: @, ?0 d- D* W$ S1 M                          set h  int (g / 5) * 5
6 o' [8 j' @2 F+ J  setxy   ( xcor-of turtle h + x )
/ N4 Y1 z1 U1 {6 g* S3 U+ k: ^           (ycor-of turtle h + y ) 9 [7 h& r9 L( H# A: u% r
                          
8 M( O8 i4 d( ]3 d7 Z/ n+ K- D                          
! @! ^' A9 F3 @3 J# a. q) J                          ]
4 `& e( f* Z: {/ Bend
4 |  {& u: o; Z* S$ l3 N) P5 C5 ~% v. d- r. V" W0 ]/ I
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
% [# N- N# E- S# C+ @: p4 c2 q应该是
# D5 Z. {  N9 I9 F1 Lask turtles [
1 C3 X* ?- Q7 o: ~1 Q  Uif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
; O2 J; O% |2 N: p7 [4 I                          set y  Dep / 2 6 Z. L( C* J6 x: l/ z' h
           set b  int (who / 5) * 5: c$ l+ q) }. a% \
    setxy ( xcor-of turtle b + x )
2 W+ Q% n+ N% H  q/ Q* |& _          ( ycor-of turtle b + y )]]
& C* f/ u% v; Xend
1 k: C) r4 ~. H之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-25 20:53 , Processed in 0.018553 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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