设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7687|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
7 {* u+ Q- Y' ^9 s, Y* \/ j4 b; i9 q, b& M0 o. l8 s3 M
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
0 p, W1 ?+ P' S9 S/ W. }7 A7 n1 i2 C; S7 A, ~
turtles-own [a b c d k f g h& f$ {0 f8 c" h# y$ J
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
8 q3 i+ S% R  ]4 B* {( ^]# s, F3 _9 g% x7 r2 T* i; V7 P6 x
to new
! c6 w. m& m6 g7 o8 D- B  ca
* N! w8 |- O; ^/ `4 _  crt 5 * num_of_building
# n' R# d$ `1 I1 w  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]' X# i' g( Y* x' N& O
  scatter     ;;keep center-turtle random positions $ k6 F8 q& }' Q$ r+ d
  unit_plan   ;;make up the building plan
0 @) j9 P7 i( V. ~6 Fend& \5 q, P/ E( p$ |, O1 s
to scatter
0 Q/ S5 B0 }. i# E* xask turtles with [remainder who 5 = 0]" i" |1 `9 H1 \, h2 ^9 m9 b
[' W0 @4 I% L- `- l- S5 U
set xcor xcor - 6 + random-float 15) t& C2 v6 \* b' D8 W2 c
set ycor ycor - 6 + random-float 15
; X; ^' A. {( D5 ~- L  m]9 U+ I3 U2 x* S9 n3 d0 r
end$ Q: T" a/ S) @. _& {3 r6 R' g7 Y
to unit_plan ' |3 c- Q2 ~: P! v$ w
ask turtles [3 U3 Y  s' |" U8 O# E8 U
if (remainder who 5 = 1) [set a who
, ]7 y$ x# K) r: d3 X- m5 [                          set x ( 0 - Wid / 2 )
9 a4 V7 l# [3 L8 g6 N3 o3 ]                          set y  Dep / 2 ]
7 b- |6 K$ ]2 m0 R0 s2 `! ?. K           set b  int (a / 5) * 5% r1 p% E5 i3 H. D1 y/ ?
    setxy ( xcor-of turtle b + x )
. Q1 n- o: S) |8 _          ( ycor-of turtle b + y )
9 K; H  t! O6 l* p; p# U! Yif (remainder who 5 = 2) [set c who1 G- g! w) c6 [0 P* j% e) o
                          set x ( 0 - Wid / 2 )
4 J1 M% q$ _( ^, b" `+ ?, k                          set y (0 - Dep / 2 )  ]
! G1 T& }6 x0 c8 i# l                          set d int (c / 5) * 5
  q$ A' h& b  _, k7 K$ r  V( i   setxy   ( xcor-of turtle d + x ), S& ?; ]- ?: }4 }! Y: L0 W0 D3 J; p
           (ycor-of turtle d + y ) ! S  f* K& G2 E5 f' |. K9 y/ z
          8 _  r5 s0 q8 T, Q+ W+ [
            ) D4 I3 M1 q/ {7 X3 f1 Z
if (remainder who 5 = 3) [set k who
, n3 j/ G- ^! h, J$ A* u                          set x( Wid / 2)  . j- r# P: L( t6 M1 w  K- W0 W
                          set y (0 - Dep / 2 ) ]( ^, X: Q% l  W$ a& o1 B7 l
                          set f int (k / 5) * 5! ^1 a# |( O1 j. L3 u9 `6 N# B
  setxy   ( xcor-of turtle f + x )
8 b) p7 {% ^, d0 o1 n. L' M" S( q           (ycor-of turtle f + y ) * z9 X! b" Z3 b' B' X) ]
           ( s7 E! c2 p. a9 I) E4 D. ~: `
           
* @9 I0 `0 n' f/ q- B# H1 ^) N* Gif (remainder who 5 = 4) [set g who
" T& o) c6 V) Y4 q                          set x Wid / 2 * j6 M( q8 K% D1 k  _- K+ U
                          set y  Dep / 2 ]2 N) r8 T! Y  A$ t
                          set h  int (g / 5) * 5
7 c4 F; q0 C9 ?- ~! \5 y9 g1 _0 c/ y  setxy   ( xcor-of turtle h + x )( O& I  N' w+ b$ B# ?
           (ycor-of turtle h + y ) / x* O2 [. z. U' E
                          9 E* Z: S+ E$ X1 W) @4 [
                          
1 {# @2 q6 y7 }                          ]0 D' N2 a4 G1 f3 {' a8 f8 }
end6 [9 B7 x' X9 Q4 v5 R

% b5 ?# @8 P4 u. \, M7 P/ e4 `5 j[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
  Y4 n# L  }, a% F# T应该是: N7 m6 I* e1 [; m/ P+ p0 z, U, M& v
ask turtles [
$ k2 w* B% y% D6 G, a* i% {if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
( c! y0 f% n# S) Q* w  S5 R                          set y  Dep / 2
; f$ p$ n, P) Y: z           set b  int (who / 5) * 5
8 v) N. `4 O; w4 H+ r" q( e    setxy ( xcor-of turtle b + x )! S' L& N5 \* U& j* D  ?" P
          ( ycor-of turtle b + y )]]- L- E" |% f5 M' n- R, n7 u
end
9 x) s2 p- o: O2 E$ e之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-14 12:40 , Processed in 0.028557 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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