设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8295|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。! j1 u1 w9 R8 p8 d  G' `
0 F: R( \. M2 B
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
5 ?- L: I* {) p( m% g2 p  k2 D3 R8 d" F4 \; l
turtles-own [a b c d k f g h; Y3 t, D% m4 A2 D
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ) Z' m' b9 x$ V- v
]
( m- ^: q: m- h$ B: v1 j4 Vto new! j+ U3 j" F$ v% }
  ca
3 U3 D5 v9 K+ f) S/ j3 c9 Z  crt 5 * num_of_building& k- l  M5 s" `* H2 N7 z1 Z- X
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
* e. G. L% X5 Z! ^9 d! R7 Z! f  scatter     ;;keep center-turtle random positions ( B/ C( b1 q. H, c7 H
  unit_plan   ;;make up the building plan
6 u5 @, Q+ K5 G! b1 nend
6 K7 f4 p7 t# U5 lto scatter
  h+ ~/ |/ z4 z: B/ C& X+ t  c# cask turtles with [remainder who 5 = 0]/ J& W: B. p( O( i( B: C7 L! b
[) Z" C  n" F& e3 S: m
set xcor xcor - 6 + random-float 15* r3 \) Y) H2 m% [$ {* Z
set ycor ycor - 6 + random-float 15
4 R, a1 A. y: c  s; L; v]
  ?/ O# r; o6 ]" Kend1 `; S4 N$ a& D3 F; K. E
to unit_plan 0 y. x& Q* L; a- U$ W
ask turtles [  Z& l. |* L. E$ Z
if (remainder who 5 = 1) [set a who / C3 D+ W+ o9 O( v
                          set x ( 0 - Wid / 2 ) 1 |  S' W# U7 b5 C# `/ Q
                          set y  Dep / 2 ]
" T- p1 I3 q( F0 @/ m           set b  int (a / 5) * 5
3 F: p3 g; ]9 o9 B    setxy ( xcor-of turtle b + x )
: ]3 W: u5 q& ^. c$ D. V, g          ( ycor-of turtle b + y )
$ Z1 V* u) F1 nif (remainder who 5 = 2) [set c who- z, S0 t6 G3 w8 S0 z" x
                          set x ( 0 - Wid / 2 )
, N" ~8 k! i2 _! `6 Z/ z# _                          set y (0 - Dep / 2 )  ]7 N6 H1 h2 N2 N: \. _& D+ g: O: G
                          set d int (c / 5) * 5
- E0 {" ^; D7 f3 u9 ?6 n6 u   setxy   ( xcor-of turtle d + x )* ?$ Z: u# Q0 x. X1 \
           (ycor-of turtle d + y ) , j" q& ^; f6 Z
          ' }$ J) G  t% d' N
            8 ?9 ^" c& ~7 c# E
if (remainder who 5 = 3) [set k who
  h- ?7 _# s3 {7 V: J! t5 J                          set x( Wid / 2)  0 J7 `. ?' U4 `" Y' E( y5 G
                          set y (0 - Dep / 2 ) ]% E9 \% _' ]9 C0 w
                          set f int (k / 5) * 5
5 n9 N! _8 x% t9 q$ x  setxy   ( xcor-of turtle f + x )6 [! p3 }! `" e; b$ }- l# h
           (ycor-of turtle f + y ) ' a2 p2 W* t6 K  ^8 C/ `
           + p3 b; W3 f. J4 L# }; D$ W! y
           
* q4 ]; v* P. k0 y  @9 Z& j. pif (remainder who 5 = 4) [set g who, a8 I2 n  K2 d6 W2 j4 O6 L) b
                          set x Wid / 2
2 |* B# |' D4 w9 V                          set y  Dep / 2 ]
; C7 I8 D; f7 R# w8 H' Q                          set h  int (g / 5) * 5$ f' k6 F3 v( D" j
  setxy   ( xcor-of turtle h + x )! l. V+ `5 c2 P" U' H  o
           (ycor-of turtle h + y )
7 L5 m! v/ u! y3 t* J* _# o$ p                          & H5 C% L: X- V  k7 ^! o8 B; E
                          
" ~+ ~% T' B' O6 U8 y# e                          ]
# m3 U( V* Z; ^! s, H0 l* G* nend
) b5 P# o0 B. ]! f2 Y& E% J
! D) {6 T8 O8 J6 K( T[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,' I: [& n1 ]3 \$ i9 ~$ j
应该是8 Q( a8 J8 m- Y' ^1 w6 |
ask turtles [6 h+ X1 }$ o  `/ Q2 O' s6 |3 P/ h
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) $ c/ j3 I* u* C$ L
                          set y  Dep / 2 * I* V4 m9 T+ L) z( }
           set b  int (who / 5) * 5' c/ m6 w' p9 j! a" ?+ ~  R
    setxy ( xcor-of turtle b + x ). _5 D" {5 S. f4 `" M
          ( ycor-of turtle b + y )]]  @2 F3 X' [4 K+ B4 j+ C
end
& T  k0 Q3 F/ _' E9 n' I之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-2 08:33 , Processed in 0.018387 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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