设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8758|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。, ]8 D. f( V1 E: x( E

, q1 W; n  e4 Q/ a但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
/ ?7 b% i# Y* a4 n1 U# _0 J: w
% `5 L, w4 T3 T" Bturtles-own [a b c d k f g h% m/ Y4 Z2 {5 V( O0 G
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
2 k" E1 m8 g, A% L6 V$ B9 b6 \' S]
% O% P6 A% F, u3 y' J$ f9 V4 W, Z" Bto new2 N3 U; Z6 V: f$ P; J$ F
  ca
$ `* U3 g- |' _0 N+ @( ~1 f. B  crt 5 * num_of_building
4 g  D8 W* P& M. K" n/ U) j, O  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]9 O  @- t: _' w' V3 ]6 z
  scatter     ;;keep center-turtle random positions % o: A  y& {% k9 {) k0 F6 I2 p9 t1 g
  unit_plan   ;;make up the building plan0 I/ c. q* Y7 @# B" N  p' e6 M& l$ M
end
1 V8 ]9 j8 [! A# z+ Ato scatter; k- v9 C/ {% V
ask turtles with [remainder who 5 = 0]
; {, L+ t) Z9 z8 K2 I[; R0 e  L, q. B8 e. _
set xcor xcor - 6 + random-float 15
! `( u8 A' p1 o8 _set ycor ycor - 6 + random-float 152 N4 e1 V8 s2 q  y, Q" w& L
]
8 {5 h! m5 F2 u* Pend5 _% I8 g5 M6 J/ @& k( ~! C
to unit_plan
. D4 [! i1 d  i; m- {" D, y0 G. E" Oask turtles [
: X0 m; x8 {) Lif (remainder who 5 = 1) [set a who
1 u& V  g4 y, U, R$ O1 w& r: O# b                          set x ( 0 - Wid / 2 ) 4 |! B  O8 t) ?3 F0 S
                          set y  Dep / 2 ]; {/ V* _$ u) r
           set b  int (a / 5) * 5
7 e9 i# f+ |9 g) t/ N' o' U    setxy ( xcor-of turtle b + x )) l( a3 w0 \$ m8 u
          ( ycor-of turtle b + y )1 a3 p5 T5 l% a; H- [, l) o& s
if (remainder who 5 = 2) [set c who
2 G/ B9 a7 r' o8 d                          set x ( 0 - Wid / 2 )   ?, n2 S6 z' ]& _7 a6 z& }: e, \
                          set y (0 - Dep / 2 )  ]
& |1 }6 K$ [& C+ F                          set d int (c / 5) * 54 [* }% N- U' h( X
   setxy   ( xcor-of turtle d + x )
: j$ \& w( y; K3 p6 j9 T           (ycor-of turtle d + y )
: e2 H5 B: |/ G) g         
1 a$ p7 N% b9 f            7 ]& A. r0 D& l- {" X
if (remainder who 5 = 3) [set k who
+ b9 G6 g- p" {: T0 e6 J/ X7 {                          set x( Wid / 2)  
" v; e1 s% R# ~% Z                          set y (0 - Dep / 2 ) ]
3 [8 @, H3 M$ \; \                          set f int (k / 5) * 5
; o8 J  ?9 D7 |+ B8 {  setxy   ( xcor-of turtle f + x )
, h" |7 j, W6 R' c# T% a           (ycor-of turtle f + y )
" R" x* G$ q, u" m9 Y' d  T% K$ b           3 \- H1 p$ D5 I8 F
           2 i% z0 j: }" {5 S# J7 H
if (remainder who 5 = 4) [set g who4 d7 c$ H2 z! L0 [7 U" z
                          set x Wid / 2 0 m: z2 W" S& T& u# P
                          set y  Dep / 2 ]
6 h5 B! ]0 H" P$ ~/ g                          set h  int (g / 5) * 5, {1 [, [8 ?6 t
  setxy   ( xcor-of turtle h + x )
$ o9 |; t6 t, I% M: l. H6 `5 {           (ycor-of turtle h + y ) ( a- q+ j( h; E2 S) z5 k
                          4 S$ e$ W4 u7 S* Q1 R) z- @+ d# A2 U
                          4 v; ?0 S* d) _9 g& o
                          ]. o6 s+ k' {  ~  x/ ]% f, j. U6 E
end0 f3 n4 f; J% j4 `6 E! J
+ a$ p( q; V# S% q) D- D
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
+ ?3 F* g& r) [% i应该是
* [! u& T' k% {3 v6 {% Pask turtles [
5 Z* V0 E+ I0 tif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ( n) X( B7 l* O7 p3 a5 s# w3 p
                          set y  Dep / 2
% R/ L# z; q' F           set b  int (who / 5) * 5
0 x/ U' p7 ]4 d5 L    setxy ( xcor-of turtle b + x )
- G1 c0 [4 q( A  q. q. Q          ( ycor-of turtle b + y )]]/ |4 t7 N- p7 X% n2 R4 _, E' j
end& x, J) r7 G8 f0 Y
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-1 07:28 , Processed in 0.014725 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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