设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7804|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
" G" [! S1 x! |# e% a; i9 f# D3 t+ `2 o, n! Y
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。/ `9 B/ K. t6 W( o& E5 ~
5 u: i4 {% g5 p: T2 x* J
turtles-own [a b c d k f g h
% S+ S4 t6 H. L& O2 E  m9 Z# O8 h" s  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 1 r* S4 \$ e% L- A0 L) f
]# Y- l6 r3 g/ R0 g8 ~
to new
# ]/ a2 Q  ]* I3 y  ca! e3 w8 a; X2 j  b
  crt 5 * num_of_building+ l+ z& Y' x  U
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]. L' s8 p" c4 r( q2 d- ~
  scatter     ;;keep center-turtle random positions , R/ W0 o3 M0 A1 B! k3 u. k
  unit_plan   ;;make up the building plan
! l) Q8 D/ S; ^5 w8 \end
+ ~3 h! t, u& G5 eto scatter8 v) L- V5 r  g  `9 n2 q
ask turtles with [remainder who 5 = 0]5 R: b1 U2 \  U! T) B4 v) F
[
( V' _, E5 q7 F9 D" s0 X; J8 o' k6 Vset xcor xcor - 6 + random-float 15
  H  X- W# o9 L2 Q1 Lset ycor ycor - 6 + random-float 15, y) q# q* w+ Z5 k
]
  Q5 p  c8 [7 X9 @# S! `end+ u* @" {- L# m: }' R0 A  @
to unit_plan ( C5 U/ ?  K3 W/ R9 t1 ~6 z
ask turtles [& ?% c# t1 `  U) a. F4 ~- Y
if (remainder who 5 = 1) [set a who 2 W, l. k& D; s; `4 U, p3 M
                          set x ( 0 - Wid / 2 )
* u* y& P+ a! @  m+ c- Q                          set y  Dep / 2 ]! ~$ e6 P8 e" U! C0 M  G
           set b  int (a / 5) * 5
1 a9 R7 R6 v5 t# k$ x    setxy ( xcor-of turtle b + x )# e' U% k+ K6 ^
          ( ycor-of turtle b + y )
$ z. M/ b: p0 u* g) \7 z  O5 B9 P) \$ L4 bif (remainder who 5 = 2) [set c who
( c9 P8 w1 e! h9 D                          set x ( 0 - Wid / 2 ) # Z! A' P0 `' H5 Q& K  H6 Z
                          set y (0 - Dep / 2 )  ]$ f) T4 F# z/ H' o, m
                          set d int (c / 5) * 5
/ v' I) u9 J  F   setxy   ( xcor-of turtle d + x )
$ U* T9 r- A# X* W           (ycor-of turtle d + y )
# L) d* d. M% [          / W6 i5 ?" ^  [+ h* {
            / z# A3 K* S8 c0 y: n
if (remainder who 5 = 3) [set k who* _  f2 K1 Q# L7 o- r5 O; G
                          set x( Wid / 2)  * I0 J( S- X3 P  Z' V8 j" c
                          set y (0 - Dep / 2 ) ]& b2 g8 J5 A  B: A" g5 E
                          set f int (k / 5) * 5
; \' K3 X/ l  d5 V; P) E5 Y6 C  `  setxy   ( xcor-of turtle f + x )" K" p2 d2 |  E+ l. [: ?7 N
           (ycor-of turtle f + y ) # B2 Y$ n) y* c  [0 S6 j
           
5 s% j% a8 f3 ^4 h* z+ B- h/ v) a           : B+ M: T; m( q$ u% @' H" S$ ]
if (remainder who 5 = 4) [set g who$ l/ ^; ]8 H# ?; s6 K' o2 s
                          set x Wid / 2
5 y+ N5 _7 }2 V0 X                          set y  Dep / 2 ]
/ B5 Y2 r& z' I7 V4 p4 S" o! k: G7 G$ H                          set h  int (g / 5) * 5
; |! W6 i" b) e" @9 z  setxy   ( xcor-of turtle h + x )
; }0 D  f( y9 S& e1 }8 f           (ycor-of turtle h + y )
  e5 F  v$ q3 i' l5 g                          0 [! |! s' c0 K% e; s8 a, t, b1 G
                          
, Q; _, O) W2 U6 z8 F2 p% \' T                          ]8 j4 b. s  ]6 I" U
end) M9 w5 A* K( W8 h$ ?6 t; Y

  H: [: e6 C' z) E* R[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
$ ]2 m+ ^2 u$ E6 h8 P应该是9 ?3 Y* y  A' ^4 a1 e# s4 p  V- {& G8 U
ask turtles [
9 N3 [. b$ I4 L. Z1 h9 vif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
2 `5 \1 z( I9 [; ^! t                          set y  Dep / 2 2 A% T: I. f% n3 G/ e9 W" F9 r) p  s" e
           set b  int (who / 5) * 5" ^) c/ u8 C- k/ ^; U$ ]2 ^
    setxy ( xcor-of turtle b + x )
6 s1 Y2 f5 b" w6 L+ n6 n; t8 D4 i( Q          ( ycor-of turtle b + y )]]" P6 B% U! B6 }. W9 _5 X- B
end7 f. G: `  k6 n: s
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-3 11:17 , Processed in 0.013669 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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