设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7282|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。' I8 i0 S5 V0 U6 H+ u

7 j. o; N% x. q4 ]但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
8 E1 j3 I$ b7 y7 K2 g; p: f# |" g
5 g7 }' |$ H* Wturtles-own [a b c d k f g h# ]; q8 W1 r, e: U5 p" t
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ' U! W5 R7 J9 M0 S
]& y; n/ j5 i8 y6 V  S. T  l/ f' }, l
to new8 o( y/ r, e) h1 K! d4 t0 X
  ca: i1 f, U# `! c5 r: v
  crt 5 * num_of_building2 n6 a) U; k" K  e$ I  R( M: u
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
6 ]' |1 B) T! _4 D9 j$ Q0 Z  scatter     ;;keep center-turtle random positions
3 w. }) @, l& K% ~1 ^. V# ~5 u  unit_plan   ;;make up the building plan
; ]6 V, i0 {3 e$ |! x0 vend
8 Z3 g9 ]  m- H9 X  Bto scatter
- l; @) n3 C% k( ^2 E+ Q+ eask turtles with [remainder who 5 = 0]" y2 j7 c$ o# A/ E; j
[& j) V( L5 [9 W8 u! B
set xcor xcor - 6 + random-float 15
  k2 v; r1 c/ \# @" dset ycor ycor - 6 + random-float 15
& B% q2 o8 L/ g0 _/ M4 a! }]  c; ?$ a7 p& h
end' t( s( V; u+ H' [
to unit_plan
" X. o& ]/ a0 M$ g9 y, l5 Z1 Lask turtles [
/ V/ B! F0 C3 t/ o( K2 h( |* nif (remainder who 5 = 1) [set a who : v1 h3 m" [- B
                          set x ( 0 - Wid / 2 )
% ^4 {2 {! S  R5 U. j                          set y  Dep / 2 ]7 O, O' `6 @9 \+ ?4 f& ]1 W
           set b  int (a / 5) * 59 h0 X/ ~9 K$ o+ B
    setxy ( xcor-of turtle b + x ). x* J+ t3 r$ G5 F) N5 w
          ( ycor-of turtle b + y )
. Z' L, k' t1 u% r) {if (remainder who 5 = 2) [set c who
; F4 p" J- a7 u; j  F) }4 Q9 i                          set x ( 0 - Wid / 2 )
% L+ M; x6 s( x' Y                          set y (0 - Dep / 2 )  ]$ b6 p) C+ C' R; E/ w7 E( W4 E
                          set d int (c / 5) * 5
* O, M* B1 l& w6 d  o1 J   setxy   ( xcor-of turtle d + x )
" n. }# z# u7 ~) E, a: a( ~           (ycor-of turtle d + y ) + F. |* r* x# C, G  R" m
          5 {4 W/ I2 t+ c! E- c3 `
            
( {# i$ u& T2 wif (remainder who 5 = 3) [set k who8 Y% _8 h# l! b7 B6 }. P% s
                          set x( Wid / 2)  / J. ?! ^0 D& `1 H6 u8 {' H' j! @+ n
                          set y (0 - Dep / 2 ) ]5 o4 K  _# V# f
                          set f int (k / 5) * 5% J9 T) n, K" H  k& v; N
  setxy   ( xcor-of turtle f + x )( B$ m& Z( h4 s! J, m: r
           (ycor-of turtle f + y ) 2 @8 I8 Y6 K; ?% P( P
           6 x: n; A, Z- g6 Y( f- U
           
( W5 b0 d& ~' c* I- xif (remainder who 5 = 4) [set g who
# F' g  L! D! W( g$ S5 N                          set x Wid / 2 , f6 E& C' |. C/ x  j
                          set y  Dep / 2 ]4 q* H' L3 V) b
                          set h  int (g / 5) * 5. z: j  ^- |* P( o5 C* V0 E2 A, I4 H
  setxy   ( xcor-of turtle h + x )4 d; M* Z  K+ F# N* W' q/ Z4 d+ n
           (ycor-of turtle h + y ) # E- v3 J$ Q1 K& m3 O9 r
                          & g1 n& c) O/ \- E; o4 z8 @- s
                          
/ m1 |' ^& \; E0 _) u' B: P                          ]
$ ]# H1 F( E" S3 W( t8 N1 \end% S/ a6 O* t6 S1 Z$ p8 V4 ?2 A! E
+ p% r& o: T$ W# r& A9 J
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
6 C7 n5 r7 L% F6 D" o7 t9 k, y应该是
( ]' x. S% b9 V; c* r4 u9 w( Z- `+ aask turtles [
) `6 V7 Z1 ?8 ^& u/ b2 w  pif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
( W: m) u3 F3 r9 n# @- g  O- D                          set y  Dep / 2
4 n7 e; ^0 D$ L' D           set b  int (who / 5) * 5
) m. H+ J6 z  I8 d    setxy ( xcor-of turtle b + x )4 v4 j. A7 }1 f
          ( ycor-of turtle b + y )]]8 P6 Y3 s. l, [; m5 G1 |. K
end; v$ W  U% e, z# S; t8 b6 s& y# i' F
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-25 04:37 , Processed in 0.023047 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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