设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6959|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。) e/ _; T$ [- E5 a

3 p2 v% z6 J* [7 Y4 r但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。) S7 l% D0 k8 R( ~: N

& Z" }1 S. b4 v) cturtles-own [a b c d k f g h$ W/ ?1 L6 [9 g# P3 R" N
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle / h1 x/ C+ v; |2 A
]
2 M4 S* J$ i* M6 M0 j, w# A: o& w* O& nto new
( [8 a4 `2 K* m  C' n2 L7 [  ca
% J5 K+ k1 O" p  d2 e2 G# \  crt 5 * num_of_building5 a9 }0 H2 p9 s8 z* I
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
% ^+ F3 w* w6 w. ~  scatter     ;;keep center-turtle random positions
9 T( Z- Z) Y/ v3 C# Q. Z- t- F  unit_plan   ;;make up the building plan3 x1 ?7 f& ~" S+ c6 L& ~. ]
end
$ Z7 d3 u: M+ c' M8 ^; O3 mto scatter+ M: H  B+ M/ L% r- U3 V
ask turtles with [remainder who 5 = 0]' `3 e+ W  E" F  ]) R
[
& V( s# J- [8 w" ]3 P( _3 Mset xcor xcor - 6 + random-float 157 \- j' L: _+ g- X( S1 |& a
set ycor ycor - 6 + random-float 15
+ n1 e9 i1 [, x. H: ~]
1 j7 L4 T$ p# b" o& g- `end
5 L3 t5 u3 D% j9 D5 l' _to unit_plan
: Z; V' L1 ?6 Q7 d! aask turtles [
2 L) }& t2 R4 X- E5 D$ Yif (remainder who 5 = 1) [set a who
9 Z& A. m3 u7 Y8 U) E                          set x ( 0 - Wid / 2 )
7 X: E' p$ k$ C& }1 N                          set y  Dep / 2 ]
( G/ d9 r2 Z7 M7 G! h; G9 T           set b  int (a / 5) * 5
% l. H. J0 T- O' i" y" Y7 N. ?    setxy ( xcor-of turtle b + x ). @8 K' S6 i2 d' A7 M5 ~
          ( ycor-of turtle b + y )
) O2 n. }( Q3 L% ^' Vif (remainder who 5 = 2) [set c who
% H; ~$ J7 p+ J+ Q                          set x ( 0 - Wid / 2 )
# A7 l5 Y  ?+ C                          set y (0 - Dep / 2 )  ]
2 e- U$ k! P# N- d/ Z                          set d int (c / 5) * 5
- D; O' e9 Y; L1 z/ y   setxy   ( xcor-of turtle d + x )
- [' p8 [( I& N4 j& K! T           (ycor-of turtle d + y ) 9 E- q+ E9 k6 I6 `
          5 _: w( X) [: e$ M
            
" e" p, P% g& T' [% b8 \& N; i5 G8 Bif (remainder who 5 = 3) [set k who
' ~; V7 r" M- e; j. T1 f- {9 Y& [                          set x( Wid / 2)  $ j1 c- t) G3 q- p7 r; s$ S
                          set y (0 - Dep / 2 ) ]
% p! ?6 y. B# m, j9 p% E8 V, B                          set f int (k / 5) * 5+ ]4 B3 q5 p6 Z8 k! S& X7 f
  setxy   ( xcor-of turtle f + x )
1 M" n' S" W& O" ]+ V           (ycor-of turtle f + y ) ( V9 p  U$ n2 _* a
           $ L: X/ G( ?4 `8 p8 Q: T
           
  q' u  i9 I2 d/ c4 Zif (remainder who 5 = 4) [set g who8 F5 O0 a# N+ n
                          set x Wid / 2
$ ^- o/ h* P4 n                          set y  Dep / 2 ]( ]; r7 Z9 \) d4 A
                          set h  int (g / 5) * 5
; Y  I- n7 Z  w( M: U  setxy   ( xcor-of turtle h + x )
: W3 @5 Y1 o/ Z+ b/ j           (ycor-of turtle h + y ) ; d8 D8 _! T  _' X7 ]* Q" `6 J
                          
3 }  R' C1 b  M- C                          ; F0 b# y% L6 f! N
                          ]& {  _, {# p6 d
end
& v/ a- e% B/ x/ Y
3 C$ D$ p& L  k, {$ V- i/ }6 s[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,8 q( ?& n- q. w* @9 H! B; h
应该是3 n+ I  W5 \$ w- T0 v! l/ ?! ]
ask turtles [% X0 K& N. C4 B
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 4 A4 h" U* T- n% |3 R
                          set y  Dep / 2 - O# e4 C6 m* E8 V$ h: g' N
           set b  int (who / 5) * 5& y0 m( L( W/ F
    setxy ( xcor-of turtle b + x )3 ~$ H7 ?5 K% d$ U6 Y% g
          ( ycor-of turtle b + y )]]
$ @. l- C# V+ b/ Xend. Z2 ~# x% y, r9 x5 j9 M
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-14 09:46 , Processed in 0.016778 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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