设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7637|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。6 Q+ O& d' {7 W

9 c/ V6 m4 d& T/ m& l但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
$ c) I- `6 O* O( [4 P
/ O1 ^+ G2 H0 Y; N* e8 z% Pturtles-own [a b c d k f g h3 V$ L0 L$ }' Q( [
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle , B- y: I9 |- H+ x1 y4 [# B
]
' L. E2 a: A' s9 u& e4 U( vto new3 A" N4 y' O) d/ ?8 @* x! G
  ca- r( o6 \; u  @4 Z! ?0 O3 D% U
  crt 5 * num_of_building+ S+ ~" P6 O  ?) V  U& m
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]( x. {1 `/ s; B" B8 Q, G
  scatter     ;;keep center-turtle random positions
& u  p1 @, r6 F$ X6 s. c  unit_plan   ;;make up the building plan
8 Q0 ?. @! x% \8 K/ J3 k: ^4 hend
* S' O2 Q! Q" U: l6 f- |to scatter8 ?  {5 B7 v6 K
ask turtles with [remainder who 5 = 0]7 E0 i! I0 c& m; \! i( K
[
! T7 r& A: o  S1 Dset xcor xcor - 6 + random-float 155 x4 d; @# R: }( w  u) r$ E
set ycor ycor - 6 + random-float 15( v  s7 k8 w  [
]/ u' i# C/ Z. }' h& J# S6 ^
end+ e9 z8 U" E+ l  H$ E, s: c% W
to unit_plan
4 m5 f  l) B/ o. [; `ask turtles [7 y5 `/ H0 N+ N  x, t, q! O; B7 f
if (remainder who 5 = 1) [set a who
. Q* U* P! B) [' [" q                          set x ( 0 - Wid / 2 )
$ d6 B. o" z; }3 M( {$ x; z5 `                          set y  Dep / 2 ]) b, v* S1 B: b+ t
           set b  int (a / 5) * 5
8 p- }9 I4 O, \$ l    setxy ( xcor-of turtle b + x ); l( h5 G% l7 q+ ^* O
          ( ycor-of turtle b + y )
. i$ O$ @6 R6 Z2 }" D1 [* g- H& Lif (remainder who 5 = 2) [set c who
! u5 M3 p9 ^0 D2 D" [' p7 S; o                          set x ( 0 - Wid / 2 ) 5 E5 e: V* k7 @
                          set y (0 - Dep / 2 )  ]9 T/ y& g  I, g! {4 l
                          set d int (c / 5) * 5# G0 m0 D( T6 _5 f
   setxy   ( xcor-of turtle d + x )
6 {2 U; Q6 L$ w  ?           (ycor-of turtle d + y ) 2 \" A( x2 ^3 x' E/ L- Q3 U+ r
          * @& S3 S9 i9 }; q% ^* V9 y
            
4 L1 X# e8 V- zif (remainder who 5 = 3) [set k who8 A! @! Y& l8 m* T: u
                          set x( Wid / 2)  $ g( e) x) {5 D, o7 U3 E
                          set y (0 - Dep / 2 ) ]0 D( o3 W  X$ M; {6 W* u
                          set f int (k / 5) * 5
, X8 B5 a+ {0 Y  setxy   ( xcor-of turtle f + x )
5 `3 B9 ]& y+ {) G           (ycor-of turtle f + y )
8 v3 e: p; S, m- ~0 h7 U0 o           
+ }2 l  b' W  c% O( D' U- ?           6 z$ d8 o. X" F& c* x
if (remainder who 5 = 4) [set g who/ {3 s9 y' E  y+ o, D9 j7 r! G6 \4 Y
                          set x Wid / 2 2 J4 w. R* i" d, V4 m" q/ `
                          set y  Dep / 2 ]8 a; ~. f& g1 A0 \/ T
                          set h  int (g / 5) * 53 @# U. M1 x' F! V
  setxy   ( xcor-of turtle h + x )  R% Q2 J! T8 @: C
           (ycor-of turtle h + y )
8 V+ H. ]$ R/ _+ J6 U. N: R3 I                          # r$ e9 E* ?: R7 F' _9 Q5 E
                          
! |% o/ t4 y9 K! c                          ], i1 M  W2 z5 r# U
end! ]. {. T/ L( p. D6 e: x& s

% n, l, t6 j$ n$ B$ Y[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
; |3 g3 {! h: t( Z: W* ^+ _应该是
  |" q" V8 [/ C8 b  q# oask turtles [1 A- m3 }- O, e. n
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 0 C* p  b" o  v( @* D2 x
                          set y  Dep / 2
3 j. u: E# z7 e0 A5 g8 Q           set b  int (who / 5) * 5: ]4 a* V! S) g8 |& L( y
    setxy ( xcor-of turtle b + x )/ F. p: u+ [, }2 \, x
          ( ycor-of turtle b + y )]]' H2 z) M! _7 l) H- J0 z
end
' G& `) h6 @( R+ E& B3 l& L之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-9 22:58 , Processed in 0.020689 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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