设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6568|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。9 |1 U& r# t0 [4 S/ c: J3 a
5 w3 N# S; G) c  Y* L
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。0 y0 o% W5 J3 Q! n( L9 c
( N3 b, n5 \* y1 V+ U  P, H2 n
turtles-own [a b c d k f g h: Q2 |7 U% b5 b( i/ c
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
+ V% o/ ]4 h9 g]
6 E; n, k0 Y, @- ]to new. \) s/ l8 L( N& q1 G
  ca6 Q: j" W  z  F" h
  crt 5 * num_of_building
# G* ]( k% A8 Z# ^: }( ?' k* q& C' t# T) o  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]% N; I% s& o- W- o4 Y& Z
  scatter     ;;keep center-turtle random positions 5 \3 _# b2 g, V
  unit_plan   ;;make up the building plan1 Q! N( d9 G0 l+ v
end2 G8 J, O8 Q4 m; j( j) u/ Q  [0 z. h
to scatter
: B/ c) \4 {/ p1 e- O' s, Sask turtles with [remainder who 5 = 0]
( F3 P0 ^; l  E$ U( t( |[' @. o2 s9 \7 Y. V( s& p. @
set xcor xcor - 6 + random-float 155 u8 I- T8 l5 G9 l6 G  W% G/ [3 ~
set ycor ycor - 6 + random-float 15
) P! K, E' f6 w3 V2 \! k9 N]
5 W( s; W, H+ N7 k3 r7 Dend. W( o9 x; f& a8 C+ f
to unit_plan
* y* g2 J! v" Xask turtles [
6 }% c( D8 ^) z* n) u( Aif (remainder who 5 = 1) [set a who & T' \1 l5 L/ j- m8 b1 Q9 q
                          set x ( 0 - Wid / 2 ) 0 b/ r" K0 L# M/ U9 f
                          set y  Dep / 2 ]3 w& Q/ L& ^7 v4 J/ i- o7 f! d; W0 Y
           set b  int (a / 5) * 5
; Q5 U4 I/ f, q8 E9 R5 L% U    setxy ( xcor-of turtle b + x )
/ X- U& q6 m% A# I) @8 @          ( ycor-of turtle b + y )
- A4 n% r" W5 w$ {. P! H7 Cif (remainder who 5 = 2) [set c who
: M; v6 r- H% j0 ?& w                          set x ( 0 - Wid / 2 ) : r- s" Z; |4 x" j5 ^
                          set y (0 - Dep / 2 )  ]
* ?& X2 ]1 T9 F# a7 w0 Z2 r' ?                          set d int (c / 5) * 56 x2 B$ m& L, ]1 u9 ?% g, @
   setxy   ( xcor-of turtle d + x )' a4 Z: ]! V* E3 \; _
           (ycor-of turtle d + y )
) g- [0 Q: o3 ?) ?) N! g! M5 F         
' h! C; P/ g; n            ; d* A6 m6 O( o" L! K  W- S
if (remainder who 5 = 3) [set k who4 d/ [% S, P( z! [
                          set x( Wid / 2)  ( V9 U: `3 l5 k9 L
                          set y (0 - Dep / 2 ) ]) ^  e3 l" R( |: J: z7 d3 i
                          set f int (k / 5) * 5. X5 X$ L( b7 W8 r/ l0 f
  setxy   ( xcor-of turtle f + x )
& p  S7 V: U) o1 O$ d: P1 L' H           (ycor-of turtle f + y )
2 Q7 F' D* W1 t7 s% S" H           
% m* b3 G$ j2 G% S* w  U9 ]           # n2 D6 h% M/ ^# ]7 H. c
if (remainder who 5 = 4) [set g who
; k$ r/ i# R4 p: M                          set x Wid / 2
& u  Q# X  i4 i, w! k2 T                          set y  Dep / 2 ]$ i4 e, o0 x3 k4 i
                          set h  int (g / 5) * 5% y# K" y: f$ W
  setxy   ( xcor-of turtle h + x )1 C: d3 _! G( Z% g
           (ycor-of turtle h + y )
, \5 g) G+ z5 r9 f( T                          
9 v5 d% r- }  z4 t) L  G6 f& n                          & U6 L* a: S( t0 x5 k
                          ]
1 g" s9 q+ ?# B/ T' L4 W5 gend+ H9 j5 b: r$ {, w6 e" v

* f0 ]* a# z- C3 \  b, c2 a[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
! W* ^3 t# [! n/ v; {应该是
9 b- N5 s4 Y  d$ c- Pask turtles [
" O* _$ v7 x1 x9 j1 D) v  n: y" @if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
# G. D0 s% O. a5 Z4 V# r! h$ O9 p7 i                          set y  Dep / 2 * ~/ k4 Y& p& ~/ W+ o
           set b  int (who / 5) * 5
. ]4 i1 w3 x4 n% d4 u/ ?- M7 g    setxy ( xcor-of turtle b + x )
* B' l7 Q; F% u3 G$ \0 I  d. G9 U          ( ycor-of turtle b + y )]], i! W$ Q+ {. l% P: \% G& [% S! E
end
+ H7 Q* U9 e, s* m- A; S9 t之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-10-29 13:22 , Processed in 0.016815 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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