设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7880|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。% x& o) X7 i7 z) c1 g* W
" }# C9 N! H) h. ?5 k
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。8 }; {/ M% E+ B! j7 A4 F

2 ^( B6 ~" T5 Y0 v7 {* `9 jturtles-own [a b c d k f g h
9 m- U! L5 s( n0 N: r, B: j2 i  x y     ;; these are the leaf-turtle's offsets relative to center-turtle * m; J) C" L* z  ]& [' L
]
# Y6 c: u3 Z+ M' q( Eto new7 P& M- L9 w, i6 v
  ca
, s; B' }% v0 j  {# ]  crt 5 * num_of_building
* I% Q; k+ _. j: ^  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]0 x! {- l! K. X' Y3 P$ k; n
  scatter     ;;keep center-turtle random positions
) C7 ]1 R' y* e  M7 P. D" F  unit_plan   ;;make up the building plan$ Z" p0 @* W: f+ o* N$ l' b& r9 O4 |+ J
end
* _/ B" U0 t2 ^4 j' o$ l1 tto scatter
( [  A+ G' [6 [+ b* i9 l( Pask turtles with [remainder who 5 = 0]) k" {6 z8 g3 X1 b
[
5 ^! z7 s# O, g' c) t8 C, c# L/ Mset xcor xcor - 6 + random-float 15
4 \- P9 n: J! k  N/ Bset ycor ycor - 6 + random-float 153 a% ]" W& f3 A
]6 [* g( p* M3 r2 h- o
end; H# L' ?1 b; R4 o
to unit_plan $ A) j& i, C) s+ V& U4 j0 g
ask turtles [
5 ^0 ~- S$ A$ h$ i! _if (remainder who 5 = 1) [set a who ! Y, L' H' K7 A
                          set x ( 0 - Wid / 2 ) % x0 {; u, K8 T8 j- t
                          set y  Dep / 2 ]9 s/ m. `% [! G$ J- M5 v8 _- a( X8 L
           set b  int (a / 5) * 5
. y+ d. G; I9 N# {% d2 W0 g2 `# }( k    setxy ( xcor-of turtle b + x )6 h. i/ A2 U7 L4 g- c
          ( ycor-of turtle b + y )
* S0 ]6 p% k- }0 ?; Yif (remainder who 5 = 2) [set c who
. n# c6 ]! T1 W" X# ]5 @                          set x ( 0 - Wid / 2 ) / E' L3 b1 V( J- D# K, C
                          set y (0 - Dep / 2 )  ]
* y0 ~6 F5 E1 V5 X% e                          set d int (c / 5) * 5* @) y+ d8 `. w& [
   setxy   ( xcor-of turtle d + x )
" m- X9 S7 ^2 X" l4 w8 k+ E           (ycor-of turtle d + y )
! l6 Q+ A. k! w; [  L' I          3 ~; I% R. O: d" ^4 |" l7 \7 s
            
8 g2 h/ J& ]8 j5 c; K4 g/ o- `8 j6 Aif (remainder who 5 = 3) [set k who4 \2 o: _0 S) Y, w7 |& s. j% c
                          set x( Wid / 2)  
& Z7 H0 Q6 j' G* f% c                          set y (0 - Dep / 2 ) ]
: p* y, C  g, t5 S% B- \( {                          set f int (k / 5) * 5
3 m/ ^' \' d+ A! r$ h4 j/ f  setxy   ( xcor-of turtle f + x )
; s2 y0 Y  t; j) m8 i. f- K) ]0 S! ~) l           (ycor-of turtle f + y )
7 H0 z+ h" |) h+ R! ?, m5 l           / G+ m7 L% i5 @' L) o8 }$ r4 T
           
9 I) N$ o0 }( a9 J; V9 ?& uif (remainder who 5 = 4) [set g who2 k8 [7 N: V* T- i5 m" ]
                          set x Wid / 2
" A- g$ q9 p! ], @                          set y  Dep / 2 ]
# b" V% h3 V5 `. m% Q                          set h  int (g / 5) * 5
; D0 q6 b) ], h5 o# {  setxy   ( xcor-of turtle h + x )
; @* T" g, V: |/ \/ |           (ycor-of turtle h + y )
: A3 Y  T! ^& h: @0 q                          
  x; g+ r. \. U1 s" V$ t                          
# S3 Q4 M& r- C  L* T) {( x                          ]
1 g, l# l' E; n1 Qend" R2 N# z, K- q! ?- \

2 v3 u  O/ ?: I: @5 h[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,& E; h9 P. N2 r0 N
应该是
3 b1 K3 }4 S( gask turtles [8 k" G7 [1 f7 z& M
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
9 f4 i! V8 n* I                          set y  Dep / 2 1 m* L5 z0 B1 S: H9 f
           set b  int (who / 5) * 5
5 f+ x$ x* J% v1 I1 J' ~  q3 {  w% P" Q    setxy ( xcor-of turtle b + x )2 z# |* ]! B7 E/ \  ^6 ]; R5 z
          ( ycor-of turtle b + y )]]
7 P" B6 H/ a. w# M( L. aend
$ z' b; f. C( j4 J0 \之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-14 15:06 , Processed in 0.020161 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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