设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8517|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
6 q7 I: a8 g* d6 |1 ]
3 @; C( p  T& y' l0 M: r9 U4 n但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。" N% Z: i/ i& h

' Z, _" |9 U: h, S. V& y8 U, ?+ Aturtles-own [a b c d k f g h9 O9 c, y5 f$ l
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
- P7 I! A( _4 t" m! X/ i; R" {3 a]& o# o; V: w4 w
to new" a6 o% N' t7 g& a6 T. L  c
  ca' q1 h3 O7 e' L7 z1 {
  crt 5 * num_of_building
. j1 s4 k! R; a  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]4 D7 `  B" J# X
  scatter     ;;keep center-turtle random positions 5 n) x  V  u' ^( K
  unit_plan   ;;make up the building plan" t$ Q+ b/ }) I$ p, p
end
1 L) G/ T: C0 ]3 f# }  H  g8 ]to scatter" h: D4 Y- ~9 r) f
ask turtles with [remainder who 5 = 0], Q" `' R. w) _, s! U
[
- |7 \- n* J* `# |* w; s* }set xcor xcor - 6 + random-float 15& L. c" V! g& ?2 v! i; L* `- j
set ycor ycor - 6 + random-float 15
, q% V  _$ q5 @3 u4 V* o5 S]. @/ T. R# K0 T  ^6 B. Y: ^
end
6 U; S+ e, V1 A- c# Lto unit_plan
; x1 T8 W$ M5 @3 mask turtles [  w% b' N% t5 c- k3 o& r( d
if (remainder who 5 = 1) [set a who 0 e; v0 ~$ o1 v: ~$ ~0 I$ v+ [% ^
                          set x ( 0 - Wid / 2 )
( B, M% B% l% d/ M                          set y  Dep / 2 ]
" J; R7 l& f( D8 |) @9 A# D0 p, @% c2 ?           set b  int (a / 5) * 56 f' N8 o! l+ p( ^
    setxy ( xcor-of turtle b + x )$ v) Z# E9 z# {* m
          ( ycor-of turtle b + y )
9 e4 ~7 ?$ F3 dif (remainder who 5 = 2) [set c who
& F9 t& V$ k" V                          set x ( 0 - Wid / 2 ) 7 y+ W: c, J, ?; ^1 b- X
                          set y (0 - Dep / 2 )  ], D8 ?( ^- s. m* }+ z
                          set d int (c / 5) * 5
  J8 p! F* S- G) [  R   setxy   ( xcor-of turtle d + x )
* `" Z8 W' B1 d, X. E# W           (ycor-of turtle d + y )
0 K1 U" m) S6 P  o! I7 W1 H: H         
" Q0 U- k) A( ~, k            
0 F& V2 l! M0 N# n/ N7 hif (remainder who 5 = 3) [set k who
. F6 ^4 Q6 p9 Y$ x+ W4 O( `/ h% [  ~, \                          set x( Wid / 2)  
* k6 d- h, `) e* z$ w% B# ?                          set y (0 - Dep / 2 ) ]) x- j$ v4 R7 K( _, B
                          set f int (k / 5) * 5
- s7 K5 ~( b3 J4 L3 Q7 d3 D  setxy   ( xcor-of turtle f + x )
, @8 D8 s$ h& _& j- C           (ycor-of turtle f + y ) + g4 H) Y' c5 C! H
           
9 V  G1 s/ c0 O) n& T           ( f& f- }1 r" q3 p( s7 D) p
if (remainder who 5 = 4) [set g who% |& B, D. S' T+ p. o% z7 H' y
                          set x Wid / 2
( H2 O/ S  h6 E5 f                          set y  Dep / 2 ]
. P) M( j8 f. r; E+ [4 E3 g                          set h  int (g / 5) * 5$ j- y. v2 Y8 g% {+ T5 I/ O
  setxy   ( xcor-of turtle h + x )
: J9 s9 w# `: m% c2 C           (ycor-of turtle h + y )
* ~0 n4 Y* A% I4 m! ~+ z                          5 U& |5 t( R% h# z$ v
                          % k2 _# L' l$ E/ S- n) _" u
                          ]5 B6 `2 T% a9 L9 ?; K$ P
end
0 C! i- U+ K2 g( {1 M# i6 v) }
( Q( J* \8 A  l  {0 G* C[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,! i7 l2 u) f- I; J
应该是0 @" K3 `" l- C3 {! v
ask turtles [
( _8 N3 x: }7 X7 h; I' s- Yif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 4 U& g0 h4 O: x! \6 D
                          set y  Dep / 2
* B9 O. o# \  [$ f" M" \$ `           set b  int (who / 5) * 5- A: s1 {# q5 ~' J/ _% B  c: J, h
    setxy ( xcor-of turtle b + x )
  r8 e3 G7 e* L; ~, m          ( ycor-of turtle b + y )]]- m' q* H; g# C+ i; l
end$ d0 f7 `% U# z% e- q6 D& j( k
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-9 06:10 , Processed in 0.016861 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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