设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8676|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
& }" _' A8 f9 h* E: G; P
5 w3 D( }7 T3 ^* }& y但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。" n8 s% D+ R' \: |+ W! j) |

" U3 ^# e" T3 \turtles-own [a b c d k f g h' z  H( G" T6 z
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
3 p6 a  o. X% i3 n6 {, _; u]
5 }  E/ q' j' U# L; t- r- S4 gto new/ N: A" C& w, g+ F
  ca7 l. ]: [. w# F- ]
  crt 5 * num_of_building6 B& Q' Q2 t2 ~9 q6 H
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]9 w9 b4 Y6 O0 d
  scatter     ;;keep center-turtle random positions
) l# F# K/ W2 L, f/ A* s' x  unit_plan   ;;make up the building plan
' Y# W4 s4 q  r" `7 P8 send  W7 k- E' |# l) m
to scatter
* ~/ m: o0 }" g* ?! d# Y  Wask turtles with [remainder who 5 = 0]; C- c7 k% \6 Y# s# a6 A* \0 _5 H1 `4 t
[
& V& a: J$ D  n  ^/ w# g/ fset xcor xcor - 6 + random-float 15, ]9 L$ N; }# c5 F+ E! I" v
set ycor ycor - 6 + random-float 156 p; P: w- J0 t) t) T
]' S/ U/ x1 l7 N2 R- P2 W
end& H  G+ l1 M, x
to unit_plan   O$ P3 X* z( \5 n4 z& ]
ask turtles [
/ _( V, Z1 s6 [. h" z3 X9 O' R/ lif (remainder who 5 = 1) [set a who & l- s; D0 L6 ^& K- S$ h
                          set x ( 0 - Wid / 2 )
- c: l: B3 P2 W                          set y  Dep / 2 ]
  q6 B: G) s+ ]6 M& Q: Y, `           set b  int (a / 5) * 5& q. W/ P' ^3 b! y
    setxy ( xcor-of turtle b + x )% X) a1 h) N/ P% q1 g  S4 Q
          ( ycor-of turtle b + y )& T! G1 a8 p8 g* ?: {+ F
if (remainder who 5 = 2) [set c who5 z$ o8 x3 B) T+ z* h& O  \# l( K
                          set x ( 0 - Wid / 2 )
$ I1 t* n  W7 g- x! t                          set y (0 - Dep / 2 )  ]
; `! X  i& U( z                          set d int (c / 5) * 5
, F0 w) V) V$ }& u7 V   setxy   ( xcor-of turtle d + x )6 g4 d2 C7 ]! I! _7 V0 d
           (ycor-of turtle d + y ) 3 s7 E# f4 g3 j4 R& C9 _
          ( ^* R) S' `$ t- w0 H3 P/ C
            7 T/ u, ^$ {$ ]# P7 X4 V
if (remainder who 5 = 3) [set k who( R- K/ u, m- ^4 Y" u  {
                          set x( Wid / 2)  
+ O( v' V, I/ `                          set y (0 - Dep / 2 ) ]* _, X6 C  y3 b+ q1 c
                          set f int (k / 5) * 5
; M) B% y2 U& Z6 N8 K  setxy   ( xcor-of turtle f + x )
! R) }1 d6 ]+ y$ j( a+ R           (ycor-of turtle f + y ) ( t# p( U0 p" A/ F& m' @! J
           
- `: G' n1 O$ Z% F0 r1 ]" w4 E           
: Y& e% n9 K& s5 S! q: cif (remainder who 5 = 4) [set g who' F- X/ z) J- _% R9 R2 }
                          set x Wid / 2
5 T* f( B. `0 u/ U  B+ G9 h                          set y  Dep / 2 ]5 q+ J& s( Z0 R7 t' U; @
                          set h  int (g / 5) * 5/ _3 `: A: }/ P% u; b
  setxy   ( xcor-of turtle h + x )2 X# i) |5 ]+ h$ b& n
           (ycor-of turtle h + y )
! K1 ?# R0 c5 h) T, G$ f                          
* q5 W. o. U3 O/ B( P3 i4 g9 F                          
7 u# W6 p( }$ c1 T, E9 N* ]- g3 z                          ]
2 T) e  k3 A7 eend4 f8 [" v! n7 D3 v' D, ~

! W4 q, B% {6 _3 o" |1 F[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
! s+ `% t* z6 Z) M0 `+ q+ [应该是
% g4 Q" M' S4 `' R, j; w: Vask turtles [
) r1 k3 k  O$ I8 a8 K2 c6 aif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 5 n0 ^- N+ V2 C$ |4 F" e' W& {
                          set y  Dep / 2 / L5 w( a7 c; s9 W+ \% B7 V
           set b  int (who / 5) * 5
; }! J5 P7 f( j* X* C8 i2 u    setxy ( xcor-of turtle b + x )' `) W) Y% T$ t" c$ x8 j
          ( ycor-of turtle b + y )]]
2 H9 s4 y* q" g: H* ]2 Z) Uend
8 D$ J/ a- D, C* H+ x& i9 o之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-24 21:38 , Processed in 0.016913 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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