设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6812|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
) R6 E- f& @! w* c5 Q' b0 y1 p# i3 l2 J' Z0 k
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
+ t7 x. J; _7 O7 B$ B3 Q0 G1 M" r$ s2 M$ `
turtles-own [a b c d k f g h
0 M9 a+ x$ u4 ]5 ^- l! @2 \  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
# ]+ h+ c" A2 Q( g1 h& T]  U+ ^7 p5 G9 L! r+ ^/ {5 J
to new8 D8 ~% m2 v. D, n  @5 Z
  ca
  N% \* K$ Q, s6 M# P" X2 Y  crt 5 * num_of_building
/ K# F5 E8 R5 K$ U& m! x  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]+ G7 O: L6 H6 l) e; S( m) o
  scatter     ;;keep center-turtle random positions
$ v0 O4 `5 G( @$ `6 W; b  unit_plan   ;;make up the building plan& c  A; L" Q; b/ B( p: q- f# s# Q
end
3 E4 U! h+ }6 `0 `5 uto scatter
8 A4 a3 ^( p2 M6 ^ask turtles with [remainder who 5 = 0]: s8 }5 y& m1 K; g+ _' k: O, k
[, F) ]5 e6 y; G# f, m( w( o' z
set xcor xcor - 6 + random-float 15& y! ~& K/ Y$ F# u
set ycor ycor - 6 + random-float 15
& Y% {% [$ y2 l3 D  e3 J- G]
. L% c- O$ F6 A2 Vend0 _0 k, m& s) t+ E& u
to unit_plan . ^* \+ x2 E0 L( \
ask turtles [5 t2 C+ r% C9 P, u9 c3 i$ a+ t5 P
if (remainder who 5 = 1) [set a who 2 ]7 z" r4 w. J& u6 ]7 i
                          set x ( 0 - Wid / 2 )   e8 Y. s2 L) {
                          set y  Dep / 2 ]
1 W! _7 S" z9 ?; d           set b  int (a / 5) * 5
9 l: o' y2 z' B3 ^7 Q# a$ O* n7 k    setxy ( xcor-of turtle b + x )
" g( R3 V, u# W( F% A          ( ycor-of turtle b + y )
8 e( b% V+ M+ q: c( Cif (remainder who 5 = 2) [set c who
% \" Q; I1 f, e/ a5 h' O                          set x ( 0 - Wid / 2 ) # G( c5 F. A: M: b( {& L
                          set y (0 - Dep / 2 )  ]
9 `8 N& t8 j  b8 {1 j4 i6 e- d                          set d int (c / 5) * 55 V+ L; x. B$ c8 c: y2 h
   setxy   ( xcor-of turtle d + x )$ L. c- Y2 H" S# r8 q+ M& F/ v
           (ycor-of turtle d + y )
) C! Z& o7 f& ~  S          / A; ]) s# f$ [, P: r! h/ j
            
# r2 e) T9 I, M, uif (remainder who 5 = 3) [set k who. }8 K) A# ^8 [' C( P; M
                          set x( Wid / 2)  9 B- y% Y. R" e7 `- ^) A) O
                          set y (0 - Dep / 2 ) ]
: Q2 q% X' `* i' A, S' x* C                          set f int (k / 5) * 5
( D* X1 }! ^/ o7 q4 ?3 v  setxy   ( xcor-of turtle f + x )2 o( `. a5 _/ a3 w. p' Y. G
           (ycor-of turtle f + y )
8 |3 X: M' Y& [) O9 \           - i8 a5 I3 l( }" t
           
3 E! c# d2 s2 ]0 L) Gif (remainder who 5 = 4) [set g who
0 F/ U& U3 n/ _5 j( B                          set x Wid / 2 # i/ j  p! r3 h6 s" k' A
                          set y  Dep / 2 ]3 }8 L6 H6 [9 _# Y% o1 m
                          set h  int (g / 5) * 5
! N9 P* k9 y) v; [  setxy   ( xcor-of turtle h + x )
* l' V3 l! K" B# e) x           (ycor-of turtle h + y )
/ S8 b% j( Q' d                          ; T* g. {- ^6 S6 g' ^
                          
, e* Q: x: @5 x( _, F                          ]6 }8 d/ a4 y% N' r6 {7 Y1 ^' t% Q& t
end
9 s' t. C- a* h- ^$ b0 i2 f
8 J3 J/ |- S- |5 l' h0 E+ G[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,* z1 Q; j( K2 g3 W2 ?2 r
应该是$ J2 O/ F- K. B5 z+ t# A* s# F$ W
ask turtles [
$ F# f" G6 h$ ]if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ) Y& U. q  N2 I# w2 e+ s
                          set y  Dep / 2 ( f% ?0 Y# z1 E' q
           set b  int (who / 5) * 5# m% V/ L3 J0 c8 h8 z8 Q- F' D, W
    setxy ( xcor-of turtle b + x )1 b2 d- ]+ R* M' K# i, a
          ( ycor-of turtle b + y )]]5 ]( z; ^+ F# `/ x# L
end2 H' s5 N1 |# [4 k0 [
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-25 14:21 , Processed in 0.016180 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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