设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6844|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
0 E. ?4 Z5 {! n! j
/ {4 m" [. C9 G2 q$ s7 q% g# H) j" U但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
$ h* J0 P5 i; C1 p
' ^* w5 W7 ^# l3 ~turtles-own [a b c d k f g h. y3 M( [' w  `2 J& d9 i
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ) m6 J2 L4 @2 g
], K- r$ C( y$ K* G) Y
to new0 Z% @) n; j  \. ]: y# T0 q
  ca% y5 j! ?$ @* }  K; J% \  k+ |
  crt 5 * num_of_building
, p  m, Q1 W" z) }  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]+ x* A! w; A+ A8 A+ e" m
  scatter     ;;keep center-turtle random positions 3 b+ K, v5 V5 Y+ a
  unit_plan   ;;make up the building plan
4 m* G3 }# R0 H+ a  I. ^* r  Wend2 p5 N" ~% `, Y1 B; l2 a
to scatter
) E+ Y" i0 J, b+ e9 M: Gask turtles with [remainder who 5 = 0]( T0 {0 N, f8 r% m  E
[2 ^+ y2 U1 G. g8 [7 ]9 f
set xcor xcor - 6 + random-float 15/ f5 T' y; v* w/ N9 t1 o, f
set ycor ycor - 6 + random-float 15
1 p) U+ J' p" R$ x$ y9 X]
- V8 v# F4 \5 B* A& @4 Vend
- n2 L% |4 K% C6 Pto unit_plan 6 x: Q/ _4 m: V; P6 z) |5 a- ^
ask turtles [1 ~. e8 q! D* W. O- H4 a
if (remainder who 5 = 1) [set a who ! l) ]# K( `- }7 D$ P' ?
                          set x ( 0 - Wid / 2 ) , e( t: x# b" s9 D
                          set y  Dep / 2 ]4 A( E1 l) P$ j6 Y6 n
           set b  int (a / 5) * 5/ w) X7 E* @" Q$ \7 z! k
    setxy ( xcor-of turtle b + x )
" ~: H5 Q$ \4 S# ~& f: b9 S* x          ( ycor-of turtle b + y )) i! s8 n; d* E) G& [! c. o
if (remainder who 5 = 2) [set c who3 M" x; L5 p2 q! Z0 [
                          set x ( 0 - Wid / 2 )
! T) Q. M. W8 X2 v4 B5 r/ `                          set y (0 - Dep / 2 )  ]" S4 k! `5 `& ]4 k3 }& Z
                          set d int (c / 5) * 5
5 U5 w- f% w$ k   setxy   ( xcor-of turtle d + x )! w/ J) i0 ]) ~3 y. ^
           (ycor-of turtle d + y )
8 o& ?  _  X7 b) y: P! r          1 \  ~) e9 a" D) w* k0 p; [
            
, y( t( ]: o3 W7 fif (remainder who 5 = 3) [set k who* a' ~+ N; @1 Y$ N
                          set x( Wid / 2)  
$ n3 i- _* ]; f3 ^" W1 X% U( ], ^                          set y (0 - Dep / 2 ) ]
- u8 i, N3 n8 V                          set f int (k / 5) * 5/ ]- R8 \* O8 W( z; Y
  setxy   ( xcor-of turtle f + x )
: l1 i" }5 G9 @0 n3 s& m2 H1 M           (ycor-of turtle f + y )
4 M* e. T  n( ^, e           6 X  k4 w: T% @% E
           
% Y6 k* k( p: F2 b0 \& s1 k9 U- gif (remainder who 5 = 4) [set g who9 g, q* e) I( C' l- C# }
                          set x Wid / 2   W) c2 f8 d2 w, ^5 w
                          set y  Dep / 2 ]
  t$ }( @$ M" T) U  y( P% C                          set h  int (g / 5) * 5
9 D% m/ G; V7 r4 B9 ?9 w6 P$ k  setxy   ( xcor-of turtle h + x )9 R+ u3 L5 o* v! ]' l! K$ L/ j
           (ycor-of turtle h + y ) 4 l7 X6 K3 n3 B! U
                          
# P! q6 e) G4 N6 b. W                          1 ]% N) u4 Z5 I7 e; n# ~: M
                          ]% Y- l# n& R, g2 M+ P, c
end
! g% ^# [7 R$ W3 k' O# \4 b4 C- [3 q  Q; |# Y* N
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,  `2 `) r9 ]9 F$ j
应该是
- B& Z6 l1 O: Q$ h0 \6 Cask turtles [
0 d6 {6 [( f" W# Cif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ' w! c8 v/ J( I5 V
                          set y  Dep / 2
1 E1 B2 b! _6 Z) F# r           set b  int (who / 5) * 5
' j1 Q! d: |2 T" D! |. p    setxy ( xcor-of turtle b + x )
* T8 r3 W0 k% G2 o" n          ( ycor-of turtle b + y )]]$ J% @) g- ?" K: j& D8 `, c
end5 w3 |; M# {; s
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-29 01:35 , Processed in 0.022304 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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