设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8633|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。' L8 g7 ?/ k$ ]5 L$ g* V: i

* ^- ]4 j7 Q6 @$ s" R4 N# [0 X% V9 g6 k& C但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。; x6 w( \2 r7 e# E. O& q- f; T9 i
  T( ~7 U+ Q' {7 s# ?- j
turtles-own [a b c d k f g h3 x, T8 N- n0 x
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
0 y# O# h4 X2 G  M! P]
; Y1 k9 B! f* G. z0 M* H% @* sto new, R# B, n- n/ W, Z. Y4 G
  ca
0 Y6 L( Y1 r  _  crt 5 * num_of_building1 p7 D) D/ S2 U1 n! `) t; p
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]9 e: S) d- f) b; `8 @9 m, s
  scatter     ;;keep center-turtle random positions
8 c- V) j  K; Z; _! @  unit_plan   ;;make up the building plan
9 B, f% G( `. W" hend
- D/ R5 i- |. P1 G* rto scatter+ w7 R7 B' Q# C, H$ _+ y
ask turtles with [remainder who 5 = 0]+ b5 `9 `: u" L% z0 S! X
[
1 t7 t' C" V, x4 Xset xcor xcor - 6 + random-float 15
: p! b( d* b! |: L, n  l  m2 h( s; \set ycor ycor - 6 + random-float 15
/ c) a! u: E, b# D$ }, b- p]! j2 p" P. f# n7 a( W
end6 G  \" ^3 I. Z, N1 \- g
to unit_plan
/ _6 {7 C/ L2 s& K+ Bask turtles [/ ^9 h( A0 k4 m3 f8 b( r
if (remainder who 5 = 1) [set a who
- w$ t) Y8 G' _1 w                          set x ( 0 - Wid / 2 )
) E& z. v, K1 @/ m; s                          set y  Dep / 2 ]
/ F' V$ O0 ?4 n* G7 F- y3 N           set b  int (a / 5) * 5
5 t0 \7 z7 c, b& }    setxy ( xcor-of turtle b + x )
3 N" Y( s% L: Y          ( ycor-of turtle b + y )% y+ G, E' S- f4 d$ _5 ^. h. ~
if (remainder who 5 = 2) [set c who1 V/ d  Q  O1 v* s: a1 w
                          set x ( 0 - Wid / 2 ) . q6 `5 T& ]. I9 x4 ?
                          set y (0 - Dep / 2 )  ]1 k2 W- X: Q/ W" A8 N
                          set d int (c / 5) * 5; B& g% S/ ^, x" }
   setxy   ( xcor-of turtle d + x )
; Q+ M6 X! H- z2 e           (ycor-of turtle d + y ) $ g. r9 a/ _8 x9 _7 d4 }; p
          1 |7 B2 N$ i3 t0 E
              l" d2 e% v' S& U7 u- M
if (remainder who 5 = 3) [set k who
5 f6 w3 U8 ]& \* n( |                          set x( Wid / 2)  : f/ m1 L$ F0 V! X
                          set y (0 - Dep / 2 ) ]
3 o) `' P0 W& A% A                          set f int (k / 5) * 5+ }0 c- W7 A  k
  setxy   ( xcor-of turtle f + x )& [4 I# m) Y% }0 j* A" C+ L
           (ycor-of turtle f + y )
( w0 N* p# g. M/ [7 x9 G           
: K, _1 s5 i* v* w; \4 V           
6 ?/ i( m  N4 M& iif (remainder who 5 = 4) [set g who; i$ W. Y# L3 q& z3 T/ E+ J" [
                          set x Wid / 2
: J- X; B# k/ \% t' r& h                          set y  Dep / 2 ]
7 }% P4 N, W2 s6 r                          set h  int (g / 5) * 5
1 d" B4 c7 s2 F( m6 ~  setxy   ( xcor-of turtle h + x )
& u# q4 ]8 g0 P' V5 x6 i           (ycor-of turtle h + y )
7 ]7 B$ @4 i6 t, R' B0 d                          + ]3 Z' X) M5 D; e( G, T8 b
                          * {0 A/ Y6 z6 b/ I0 k- b
                          ]
  @( W/ a  y' Z7 I8 U8 D: kend
: C' g- _4 V* L: i1 o1 V$ n$ R
% r1 B  a; [8 R& h( z[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
/ t2 L$ D# [% T5 C/ m. H1 D应该是# m% X; a5 B0 e' D1 E+ p# c" L, c
ask turtles [
" D! ^9 @( Z. M' yif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 7 E$ C- h% u  c: R
                          set y  Dep / 2 3 e1 [. N6 h* e+ y  ^
           set b  int (who / 5) * 5
- n! M8 E8 J0 [    setxy ( xcor-of turtle b + x )
) i% c! {5 `: d          ( ycor-of turtle b + y )]]* o  L3 c. N% z3 U
end! E* S3 x% f1 V2 B5 C. h$ c
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-18 18:01 , Processed in 0.015096 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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