设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8242|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。$ Z1 c/ Q/ Q) @7 I+ N( U

3 i7 q5 k8 T& ?0 s6 [, G但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。, Z& S# Y  V% `1 ~5 _
2 O- e" b5 l9 L  X6 t- Z
turtles-own [a b c d k f g h1 S" b7 Q, o' V" `& q9 y
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle : u+ T% T. H  h/ g
]
" `9 p# C% F5 X* v- E' ^. pto new  T3 X5 g8 A# @  _, ~! u' g# d- e# @0 H
  ca% E( z; ~' R4 P" ~
  crt 5 * num_of_building
6 J; T% ]2 m2 H2 F  l: o  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
# I; j: E# P; _# L8 n- I  scatter     ;;keep center-turtle random positions 5 S" g& h" d" \8 Z5 Q
  unit_plan   ;;make up the building plan& M4 o+ H. G# j( X, \( O2 h
end/ Z' F' S; T, V
to scatter' W$ E# n: r# t* w7 B- }; S
ask turtles with [remainder who 5 = 0]" n/ {# G0 P  o; |4 e
[
9 e) Q% Y4 A' _- n7 O& `set xcor xcor - 6 + random-float 15
& }* P; @# k4 T. M. z1 Oset ycor ycor - 6 + random-float 158 v7 d$ n2 ]/ X, a7 y% @1 M6 A/ y
]
/ k9 h% r2 N. o8 Q* }5 H. r0 Kend
" b. Y1 l9 {: _; V7 j5 V' Bto unit_plan
; a& ^- u3 ?0 I; j2 A- Sask turtles [; A* E" S6 ]7 K# z+ u; L: x% c' {; N
if (remainder who 5 = 1) [set a who ) r: S4 N! W( P% g* N
                          set x ( 0 - Wid / 2 ) & k$ G9 |1 n8 `  a# ~2 Y; r
                          set y  Dep / 2 ]
% L  f0 w2 _; x# S7 H           set b  int (a / 5) * 5
5 G5 ?  Q" v( K% F; ?    setxy ( xcor-of turtle b + x )
3 g: z, z& }3 s* v1 C' X          ( ycor-of turtle b + y )
+ p9 e2 _- |5 y- C$ oif (remainder who 5 = 2) [set c who1 P0 D! V0 Q8 z% q3 @9 P$ w
                          set x ( 0 - Wid / 2 )
: v8 s/ _, s: c                          set y (0 - Dep / 2 )  ]5 o$ }3 l0 @  y' e
                          set d int (c / 5) * 5
' z+ Y% ?3 {# n1 N# S5 P. E/ N   setxy   ( xcor-of turtle d + x )
* }1 g+ M3 ?) h; L+ _  P$ z           (ycor-of turtle d + y ) * ~0 ^# |4 r8 I- i8 Q
         
' D4 j- {' ^# P: V  D" L) f' f            , u2 _) L* c* V9 Y* _$ X
if (remainder who 5 = 3) [set k who
, v4 A9 T: W) E5 d                          set x( Wid / 2)  1 F2 d3 E3 S2 s0 d! w
                          set y (0 - Dep / 2 ) ]
% a; ~( o/ C, s) c! l5 W                          set f int (k / 5) * 5
+ {5 `- o7 w" ]) B+ x: H  setxy   ( xcor-of turtle f + x )
2 j9 A3 s6 T8 r           (ycor-of turtle f + y )
8 G# l1 b# [, H, x5 R* `           1 ^6 u2 O, v* ~) ]9 s% B
           
( I8 o- l. m: y2 aif (remainder who 5 = 4) [set g who
, I* o& ~) |5 c( t" F; K                          set x Wid / 2
6 X, x9 h9 B( d7 ^+ ]/ R+ K                          set y  Dep / 2 ]
# b$ |3 N0 |7 E# A$ e* ~3 j  a* [                          set h  int (g / 5) * 5
' p( V( b+ W  F% T  setxy   ( xcor-of turtle h + x )7 ?& z# O! s6 R1 o8 L. Z& F8 ~
           (ycor-of turtle h + y ) 7 V$ t9 R9 \7 @# V. a. K0 j$ @
                          
5 r, a: l. @, E) E                          : y, G5 r! `4 _# x' \, Q$ s
                          ]( G8 s) T* q$ M; ^3 l: P
end
. D  o$ K: i  s+ t6 R# B% o( p
) D  ?  u. ]% }# \7 F* u* X[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
  k5 `: \* G- h; \! M7 c- J& P9 C应该是
, P& N0 t* F7 N8 ^' r5 Oask turtles [& y9 U0 d  H. _$ x' _" K4 }( w& t
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
6 _) ^/ l& }# Z0 e# R0 y: b: V! J                          set y  Dep / 2
4 R7 I9 l# q8 j: x2 [           set b  int (who / 5) * 50 F& N$ v2 X4 F9 |+ U0 ^# [. B3 a
    setxy ( xcor-of turtle b + x )( p2 Q4 ~  C& J( r6 s3 b, P
          ( ycor-of turtle b + y )]]
, |+ F3 D. H  W3 v2 L& a+ d  _end
6 G+ B+ h3 H1 ^: d- Y1 V0 z之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-23 15:44 , Processed in 0.019649 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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