设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8294|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
" `% b* ^3 w$ ?2 t' e  {8 ]% O  S& v+ b% U
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
! y8 n; k! s0 a& H8 x+ P6 \
+ Z) R* T( @( p$ ]* E$ O! Aturtles-own [a b c d k f g h4 c! ]; b3 A1 G- t4 z
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle : Q, x2 W5 {1 U9 a
]
; Y1 C* F/ R) b1 _4 U/ s$ lto new8 C# C$ z, w) f  h
  ca
, K2 Y5 r; f+ h9 F7 j- {  crt 5 * num_of_building" }! F7 V! p' c7 m( _+ e" {( ^
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
' n- j  W- M# n3 Y$ g3 i) m  scatter     ;;keep center-turtle random positions , f$ L! o4 Q, _4 s4 W
  unit_plan   ;;make up the building plan
4 `. o4 T" U/ M# b) yend
1 _. c  k4 Q5 n$ qto scatter1 I4 `5 b# n+ Z. R8 D+ V+ E+ K9 D; K
ask turtles with [remainder who 5 = 0]% M% O0 _" C/ E/ I# A. q
[) a$ n3 t, L8 }" R! E3 i1 l
set xcor xcor - 6 + random-float 15
) R) C3 {' k, b& N% l' P% fset ycor ycor - 6 + random-float 15& ~9 v$ o$ f5 Y+ M$ r1 u4 i
]2 R  O( o6 f" o" Y+ h
end
! U) F/ d5 T* ]. \to unit_plan
; b1 `8 @1 w$ W" }ask turtles [
5 @2 ~; h, i+ V$ l0 V% g) vif (remainder who 5 = 1) [set a who ' s& n) n& A8 @+ U/ X5 D% H
                          set x ( 0 - Wid / 2 )
. T2 [  d' |0 U                          set y  Dep / 2 ]& A; B% t- z/ w4 L8 r( X2 @/ I' W
           set b  int (a / 5) * 5
' |. @7 D3 A% c; p' u- q    setxy ( xcor-of turtle b + x )
( j4 D9 P4 A6 {$ K- a          ( ycor-of turtle b + y )
- X; F1 o& \& D, i9 Z2 B) J* @if (remainder who 5 = 2) [set c who
3 e8 O' _$ P8 w, H, ~                          set x ( 0 - Wid / 2 ) ) b! s; s' O2 S3 H& j. L
                          set y (0 - Dep / 2 )  ]' f# I/ K7 w& c( B
                          set d int (c / 5) * 5. ^+ ~1 G5 @3 X' _
   setxy   ( xcor-of turtle d + x )
) B9 t% N" ^  [8 @           (ycor-of turtle d + y ) : z( c- t, @9 o- D
         
  G+ ^; a$ b+ d& p7 F& M$ A            $ R: ]; Q; |+ r
if (remainder who 5 = 3) [set k who
, N1 \) `6 f% l                          set x( Wid / 2)  
0 Z0 g) O  L% M3 L# r                          set y (0 - Dep / 2 ) ]
7 E1 U) n- d$ V* H$ ?& B, v( J                          set f int (k / 5) * 5/ B1 O! m# w9 ^, g+ D
  setxy   ( xcor-of turtle f + x )4 D7 C. r8 ?) q# C% {1 s
           (ycor-of turtle f + y )
1 O- C- E  @2 |6 i9 p" V           4 L( T6 E1 c2 M9 H% y5 m8 N
           
& a/ {- @4 U3 z- j. w& N2 |& ?if (remainder who 5 = 4) [set g who
1 k. Z' q# l- e                          set x Wid / 2 - j2 ]- f% m" b1 @' J- ^% C
                          set y  Dep / 2 ]4 O6 A" B5 s" o
                          set h  int (g / 5) * 5
; ?' F  l# |0 u; u5 w  setxy   ( xcor-of turtle h + x )3 v2 G$ |2 v& U$ s" G9 K+ [; G4 A! \
           (ycor-of turtle h + y ) 0 C* Y1 ]: L3 z% U$ F; p& ?. k" l9 ?+ |
                          
3 K, H" ~2 o) A6 e) ~4 S4 W                          ) i9 U) `8 H. ?# J: M9 t
                          ]  k$ d" N" G* W$ K# u: A+ I
end7 @3 h- g* Q* t" Y3 g; j; d) `
, k7 U! a8 X( E! N
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,, p, F2 Z' k! B5 f" n
应该是
$ }4 Z3 M( t/ p- B: c* ?ask turtles [8 R) T+ v/ }5 x) E
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
2 F, o, a/ L" Y1 A. s+ ^. u  S                          set y  Dep / 2 " K- h) h( G) {! U( T: Q
           set b  int (who / 5) * 58 e0 j9 I6 w& |4 w4 Y$ s8 x8 ~
    setxy ( xcor-of turtle b + x )- S8 R, t' n# f6 V) \* o$ b* x
          ( ycor-of turtle b + y )]]
( E5 ]# [* [9 G7 [" Rend: R) X& x. i* L8 ~7 G( R
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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