设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8162|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。' E! j! I  m2 k5 o7 J: B/ J

- _& T; _- W' E但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
2 c4 ]4 e/ S, D3 F# f5 a5 l9 v- p% ^  J9 U0 e
turtles-own [a b c d k f g h+ J8 s9 h0 A% o' [' Y5 O9 M$ h+ s+ A
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
% q0 V9 N$ B+ n/ `8 l' `( X]( u2 p$ D, r/ G9 Q5 h3 @
to new
/ e9 y0 ^3 w; l6 r2 d. e5 B$ H  ca
2 j6 z  i8 P% o  crt 5 * num_of_building
1 d7 B- s0 G; L- }  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
+ R" X  v0 K% P) @1 _  scatter     ;;keep center-turtle random positions
: D+ S( i6 C) n+ |8 n( \  unit_plan   ;;make up the building plan3 T. |0 H+ T- ^8 c0 i5 Y. o
end+ R& J3 ^3 c2 q! A% U  q
to scatter% x3 ]/ G1 ~( L+ g  j+ c$ v& F2 B
ask turtles with [remainder who 5 = 0]' J. H  Y: t8 X$ r: _& R! ?  R' I
[. ?! u) [) z5 m$ w& v6 ?- X0 R8 a  ^
set xcor xcor - 6 + random-float 15, B+ q0 S; s! ~6 `: E8 a. z) C0 H
set ycor ycor - 6 + random-float 154 E6 x/ ^, G  v& R
]: S# y! J! L9 Z  }4 {1 `
end
3 o: W+ d/ T0 H6 K4 n9 nto unit_plan % ?2 t6 Y, U4 Z( w; ?' \
ask turtles [
0 k$ l8 i5 P; ~4 w( u$ u6 }" [if (remainder who 5 = 1) [set a who & \! w4 d$ ]3 ?! a  o
                          set x ( 0 - Wid / 2 )
) P; n0 k1 W0 N) T% j0 `' D- L- L                          set y  Dep / 2 ]
9 O& L2 A1 A, F/ b           set b  int (a / 5) * 5
6 \( s' Y$ M/ u- o' j" z, L; K% f    setxy ( xcor-of turtle b + x )/ B8 }5 S6 j8 |0 [
          ( ycor-of turtle b + y )6 G0 f! G$ D$ |; n& e
if (remainder who 5 = 2) [set c who
! ^7 V0 k3 R& p" X) q0 T  i                          set x ( 0 - Wid / 2 ) 7 L% M2 W( N2 z2 e1 E
                          set y (0 - Dep / 2 )  ]
+ m% Z4 Q4 x4 V9 y0 k& {6 Z" Y                          set d int (c / 5) * 5
; n& T1 J/ \& ^: h   setxy   ( xcor-of turtle d + x )
& T' V0 m1 G6 V9 Y/ h$ i5 m6 E4 j           (ycor-of turtle d + y )
5 @% c( m& Q& c- J2 S          / X7 D2 G% P* Q7 i  N: v: {
            : T. ]. `+ V% I! k/ L
if (remainder who 5 = 3) [set k who1 a' @' H- r% T- _8 `7 {7 p
                          set x( Wid / 2)  7 a# `8 b% R0 x* p2 Z; V
                          set y (0 - Dep / 2 ) ]. l! t3 i0 m+ e2 `* E
                          set f int (k / 5) * 5& S2 O4 R3 f: v
  setxy   ( xcor-of turtle f + x )! }6 j% m' {/ W. y$ x
           (ycor-of turtle f + y )
6 b, h4 A" u/ d3 \# `) f           . ^4 {0 u: U" Y5 U$ e
             V; c$ o7 B8 O: S# Y! L; W: e' @
if (remainder who 5 = 4) [set g who
. c& v; N  z. l+ o- y9 t" E: q                          set x Wid / 2
# o6 c- b( I0 A" h( j- I                          set y  Dep / 2 ]5 }" h+ |# P, f( L' S/ _
                          set h  int (g / 5) * 5* j" w. C) J* m9 |$ P7 i; ]0 \
  setxy   ( xcor-of turtle h + x ), \9 \" @# T7 M& |( W0 o8 z2 G0 V4 c
           (ycor-of turtle h + y ) $ V( Z8 E( r& p* @$ M  R+ v- [
                          
4 l% J3 y( c6 {4 O; V                          
7 P! S+ [  r3 H7 [8 X' n                          ]
$ D+ }4 ]  h0 Aend
! ^8 I* A5 G) h+ Z: x' W; k6 {/ V4 J/ a& O' H7 |7 z
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,6 R  P0 y: G5 s3 n
应该是
/ ~* Z2 G6 m! R, c9 dask turtles [/ h- O+ F4 A. O1 L8 P$ ]" c
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
1 }  ]* {, X6 n4 s) ~6 ^" L% Q                          set y  Dep / 2
8 A* Q+ B: ^' S           set b  int (who / 5) * 5
9 s; E4 a+ }! ]8 [# V. C& E    setxy ( xcor-of turtle b + x )
$ o' z, J% y: c6 Z$ M0 y          ( ycor-of turtle b + y )]]
* Y  E- k3 p2 m5 Vend
/ t% i3 c" F- V+ J1 n之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-13 15:01 , Processed in 0.019492 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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