设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9007|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
. x( }  _4 I: F) l9 ?% H; X" m: p; o$ k
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
0 L4 b4 ?1 I3 a, s" |
6 q7 w! q$ N: I7 {8 L: bturtles-own [a b c d k f g h
( J% \2 d7 S* x; ^, [  x y     ;; these are the leaf-turtle's offsets relative to center-turtle * J$ j" `% r% G" _
]
- X# {& J: h0 C' l  m9 w4 B$ kto new9 B& [) J6 f$ _! ?7 ]6 Z( h8 ?- t
  ca/ M0 O. s) b4 E! j2 V
  crt 5 * num_of_building" X$ S% q3 {5 V7 V% \( K8 O
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
  {- G3 p/ H$ s+ F, q2 W  scatter     ;;keep center-turtle random positions
% l% ]$ {& y, \4 {, t# N$ t* [  unit_plan   ;;make up the building plan) o" v1 y9 h# l# g4 P2 R
end
0 h. k: o1 j' Z" H* M6 ?# B- X4 uto scatter7 u% I3 I& u& {+ [2 d4 f8 H/ |( ~
ask turtles with [remainder who 5 = 0]: q% H5 W" k1 {0 i1 G* B
[
3 y1 R& L" Y8 V/ d) mset xcor xcor - 6 + random-float 156 w! ^' c: M  X$ M) {
set ycor ycor - 6 + random-float 152 [. F( i4 ^7 x; x
]3 @1 U4 D" x& Z4 _  z) O& @; E8 b
end
' q; F- h% ~* o9 ?: {- [$ hto unit_plan
8 J5 [, L: v0 A+ \1 C4 S1 Eask turtles [
8 U' H5 Y2 c4 iif (remainder who 5 = 1) [set a who % K1 |2 [/ `) b5 M
                          set x ( 0 - Wid / 2 )
; s, j1 T7 {/ g: e                          set y  Dep / 2 ]% v# Z8 W! g$ ~7 l  f+ F: M
           set b  int (a / 5) * 5
2 ^& D' m: A$ B+ p& _9 F    setxy ( xcor-of turtle b + x )
" a7 R1 w3 O; W* w: m          ( ycor-of turtle b + y )0 q# ~' v. P7 B* O& e
if (remainder who 5 = 2) [set c who
! g4 t2 l+ r: X" ]$ Y( }0 q                          set x ( 0 - Wid / 2 ) 6 @. g: J1 ?" F  D
                          set y (0 - Dep / 2 )  ]% L5 W  h, A4 S2 u; `5 [
                          set d int (c / 5) * 5
& V( \/ q6 W; C- `  ^5 R   setxy   ( xcor-of turtle d + x )
/ N$ w& _" e7 R9 A           (ycor-of turtle d + y ) & S4 C' U8 |3 ?
          2 V/ p( L1 t) l6 o$ l
            
7 k& ^5 ?# `! L1 |9 T( _if (remainder who 5 = 3) [set k who
; n* z8 w$ D" L+ z2 [4 b4 l! ^                          set x( Wid / 2)  5 x3 U( F. t* O& B2 m
                          set y (0 - Dep / 2 ) ]
) b( e7 m' `, c% T) H7 e  y                          set f int (k / 5) * 5
" f; D; S  l3 ^7 q. D) c& l9 ?2 s  setxy   ( xcor-of turtle f + x )
, k' q( E' a6 h+ |           (ycor-of turtle f + y ) ( B: N  ~0 p1 G5 c# p; ]- g9 U
           # ?; p0 A& e1 I4 h) a
           " e! h$ F  X6 {6 d' l
if (remainder who 5 = 4) [set g who# {& x' a+ q, ]. {
                          set x Wid / 2 : v' R0 g# H* t! T! V
                          set y  Dep / 2 ]/ q; L6 a: P# b
                          set h  int (g / 5) * 5
6 b( j+ {$ A' L) M1 ~  setxy   ( xcor-of turtle h + x )4 p' F- j; F' Z- o; n7 z
           (ycor-of turtle h + y )
- `5 I/ L$ c" K3 m9 Q                          5 {0 y, D+ F/ u2 z6 ]
                          * D4 v4 h& l6 {( h- A4 k) U/ Q
                          ]
" h, a+ j! g0 c: J  @9 D9 m3 |0 e6 |end
% n( B- Q- J) i! S1 e
$ r$ }6 X( y% \( l; m[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,6 |4 \/ S2 B  }5 W$ e* j( U
应该是- u( c/ r) ^8 j7 S) O. J- X
ask turtles [
: ^+ }3 O) D% I( N1 _7 fif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 1 o( Q' Q8 ^7 ]' ?, _
                          set y  Dep / 2 7 k$ H1 h8 c" e6 b& [! u
           set b  int (who / 5) * 5
. w, n3 b5 P; Q, A# X$ q( M. b    setxy ( xcor-of turtle b + x )$ ]2 A1 U8 K' m; w. |* x/ D! e1 P
          ( ycor-of turtle b + y )]]3 p7 b& j0 h; s, X" w6 L
end4 `: x' E7 O. R) \
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-5 13:38 , Processed in 0.018440 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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