设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8839|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
5 \6 w8 D/ Q. E2 Q5 b7 a6 X4 ]4 P1 U" R+ m" A' |
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。* Z) A  `8 H. B- U: o
- b+ y8 d4 }( R6 A
turtles-own [a b c d k f g h
. n  p% o& G9 N1 z  x y     ;; these are the leaf-turtle's offsets relative to center-turtle : N; w0 a( U. J
]6 z1 c# \, w, Z! |# n
to new7 `1 V+ N9 i; r4 \' t
  ca
9 L% e& J- ], ?8 [) e  crt 5 * num_of_building
. p2 ^( H& b4 l" g4 f  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
) [- `3 I; ~+ R# k' M# L9 W" S  scatter     ;;keep center-turtle random positions 2 K& ?5 c1 R0 C8 `" W( T4 U) U
  unit_plan   ;;make up the building plan$ m! o1 W. O1 y6 d. K- Q! y% o
end
8 s& L7 p$ a& z1 s+ Z! P% Eto scatter! H6 n9 g3 U% p) @
ask turtles with [remainder who 5 = 0]
7 S* t& [. Z" }[
: U: v$ l3 k" y( Z$ |! W4 ~set xcor xcor - 6 + random-float 15
' z0 [) b" O$ g6 @, T. j" h2 Tset ycor ycor - 6 + random-float 15
8 ]% Y9 J# F1 V( G]
+ [( X. s  u( g8 |end0 v3 O1 w9 m* g. r% l
to unit_plan * L5 W) {( n) X4 s% ?: N0 D7 |' l
ask turtles [- M/ ~/ _' c8 y( f
if (remainder who 5 = 1) [set a who
! w/ @3 I' J  P                          set x ( 0 - Wid / 2 )
* b+ y, \: \( }+ X# Z: b                          set y  Dep / 2 ]/ Z- z2 X; J4 [
           set b  int (a / 5) * 5
# [1 U1 ?* O0 I! H. U+ q    setxy ( xcor-of turtle b + x )
$ ]  r* D: F' I2 O' a; G9 s: s          ( ycor-of turtle b + y )% y0 B6 e2 f: w  I# x* Y. s# j5 p
if (remainder who 5 = 2) [set c who1 B3 h2 y9 h, T( W5 z0 R( c
                          set x ( 0 - Wid / 2 ) * n) E# o8 w  |, d, L
                          set y (0 - Dep / 2 )  ]
, q) z% p  S  V2 z5 y$ V                          set d int (c / 5) * 5
. a: N- s* P* M+ l, x' ]+ m7 ^   setxy   ( xcor-of turtle d + x )7 n5 Q7 B, H' l
           (ycor-of turtle d + y )
/ Y8 S0 C$ f3 v- @4 V) R         
& T' w$ Y$ d2 x! M/ V# @6 ?            1 v) |+ }" @. m0 \
if (remainder who 5 = 3) [set k who
! B$ t4 m# G6 L8 z7 E6 e1 i5 u                          set x( Wid / 2)  
: d$ B" W; l& ]' \                          set y (0 - Dep / 2 ) ]
, k/ M& ^+ J% ~; t                          set f int (k / 5) * 5
9 w) h! `, p" O, m2 s+ S8 O8 R4 x  setxy   ( xcor-of turtle f + x )
% _8 N: L! t& B6 q& r1 U$ u6 X           (ycor-of turtle f + y )
  c9 L) Y" h; g1 M+ z: k           
$ Y" e& n& i8 A/ q8 c4 R           + T) j$ v3 k! ]+ `- i
if (remainder who 5 = 4) [set g who
% i/ m3 I' l8 `6 E/ B                          set x Wid / 2 ( z& Q" t6 Y. W- o, J) X7 i
                          set y  Dep / 2 ]7 \  _3 R+ N, t2 {* `* l
                          set h  int (g / 5) * 5+ i: _. k* p% }* n* u$ ]
  setxy   ( xcor-of turtle h + x )
) G- y: t3 Y8 k, B2 G" L/ B           (ycor-of turtle h + y ) 5 a% d! t( H) i! ~0 d: X6 S( |
                          
% E: @2 R3 c' Y6 i& U7 X                          
; Q$ z* ?  j/ y                          ]
8 {1 x7 Q" b7 z  ^1 C8 A6 Send
+ D% g3 g/ Y/ j$ l
# y0 {/ h8 l# ~0 w: O[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,$ ?) O( a/ h" r( [
应该是& u) ]3 g8 ~1 I# R
ask turtles [  p- t8 p7 ^4 t+ N
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 9 g( k; {) N  B, ]3 Y4 P
                          set y  Dep / 2 7 |5 L- d) y2 m+ r3 q+ W0 r6 _) D
           set b  int (who / 5) * 5
( _+ F- l' C- T( M0 t4 d    setxy ( xcor-of turtle b + x )
* q( [: S' s+ e0 D, a          ( ycor-of turtle b + y )]]
- W6 T) I) x1 Eend' |! e& [: r6 ~3 S7 }% C
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-10 18:35 , Processed in 0.018202 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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