设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7184|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。9 w3 I  y% |% |6 j; y8 c
/ F9 ^% Q5 A; V6 _) ]1 k: A" ?
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
- e2 ^9 m5 u# L$ j8 C4 L9 N% A8 ^( I6 ]) Z* N+ j  |# {! P5 F$ w& i
turtles-own [a b c d k f g h
) I+ I* o7 S7 Y5 t8 G, K  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
: }$ p# j8 \) i8 W]
) G! _. k6 h9 i0 ^- f' F  e2 L7 n1 ^6 tto new. `. _5 a+ l) r& T1 m; ~* \
  ca
1 W. z6 v$ S% f- |/ x  crt 5 * num_of_building7 ~: o4 o9 k- G* V4 ]) W
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
" I" b! \, a, E8 u: G! t( q  scatter     ;;keep center-turtle random positions ; f5 \6 u. d) {) Z8 t
  unit_plan   ;;make up the building plan& W  H% t# y. k, W" G& u, `
end! `$ A! M1 J! l' b1 V, R1 q2 y
to scatter
6 Z) R, \) b* j. F) ~5 rask turtles with [remainder who 5 = 0]/ s$ |$ a7 _" n; ^9 c6 i# I% s
[/ L  E' L; E9 m$ G6 }
set xcor xcor - 6 + random-float 15+ i' v$ [- x7 `4 B& c" W' N
set ycor ycor - 6 + random-float 15+ l* E3 M, N# \0 J: o6 p
]
0 }* k1 W5 B9 F$ C' H' D: a9 ]2 Y2 Yend, s6 b1 |$ @6 G
to unit_plan
; n# L: d& m; K: u2 Xask turtles [
  k8 Q2 N1 l* t! D6 ~: J( e5 aif (remainder who 5 = 1) [set a who
8 x, e5 ~* b) j                          set x ( 0 - Wid / 2 )
5 u1 w% b/ v/ M8 @% U! ~                          set y  Dep / 2 ]& _+ f. m4 w% h: }; \' g/ @7 f, j
           set b  int (a / 5) * 5
* D+ n& n# C" y& i% @    setxy ( xcor-of turtle b + x )
* e+ O/ g! l9 B          ( ycor-of turtle b + y )( `2 `6 K7 q4 G" t$ i1 L
if (remainder who 5 = 2) [set c who
5 q! a2 a  ?; k                          set x ( 0 - Wid / 2 ) & R- f7 P% e+ e( o' B- o$ O
                          set y (0 - Dep / 2 )  ]0 {+ C- @: a: x" c: u  j/ i
                          set d int (c / 5) * 56 f* n! x$ b+ w+ D( e
   setxy   ( xcor-of turtle d + x )- U1 U9 S8 ~, [/ f% X' T' N
           (ycor-of turtle d + y )
+ b! D- e. @0 e* T1 r% a/ J- ]         
/ J  w) e. W% ^9 j# F$ d' Q            
, o0 b# d3 l, \7 x/ w, Qif (remainder who 5 = 3) [set k who( ]- t& U6 o  @+ L$ q
                          set x( Wid / 2)  + z* c" S  F3 H6 @% }' c
                          set y (0 - Dep / 2 ) ]* r2 Z8 {- n( \
                          set f int (k / 5) * 58 }; i  v2 q  f, V: g& C8 s
  setxy   ( xcor-of turtle f + x )
! k3 f/ {8 s; _: {) J& P0 H" u- g: Q           (ycor-of turtle f + y ) ! A& r- B1 Q, y
           
" Z. ]8 u, p. [0 K8 b1 n4 i           : n% p* V& Z2 D" M7 C
if (remainder who 5 = 4) [set g who% G. _" i6 d5 V! J
                          set x Wid / 2 / V( O4 X* R0 F* V$ p  P
                          set y  Dep / 2 ]/ B# O) O2 k  r  p
                          set h  int (g / 5) * 5) P) q9 j" f) H0 v* M+ w
  setxy   ( xcor-of turtle h + x )
+ f7 B+ l4 @7 v+ m' j" i" h  k4 I           (ycor-of turtle h + y ) ; }! f$ o1 L: _& G/ A
                          
6 h, N- v5 s8 n: V! `                          
' u5 l" G, i: W) _$ i                          ]
$ i2 |2 X. [  cend7 ]- X# E/ C( d1 \1 H

: ~+ e& ?, B5 R8 P: V( U) n; t# C) O[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
- Z# A4 I. \4 [) f7 h  I应该是+ }0 S  n( J$ L" a, P5 ]* `5 T7 s
ask turtles [6 F! s* n8 {6 i. {7 U) B) g
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ) Q$ N$ p% G1 ?+ k. o5 c4 g
                          set y  Dep / 2 ' k; M8 _" v$ M9 U/ l$ {8 r0 d+ W
           set b  int (who / 5) * 5
" }9 ~+ a$ Z5 e$ {2 A1 a    setxy ( xcor-of turtle b + x )0 x& u. B  X5 h6 b$ N! y3 w0 o
          ( ycor-of turtle b + y )]]
. n  h9 B6 K' V  yend/ \) n/ a0 J* U3 `7 w
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-14 15:55 , Processed in 0.014754 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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