设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6653|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
# @5 K# v6 c- a( @
2 W& B. @+ e. K9 S$ e但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。' U/ G2 M' D6 b9 g- a0 U
5 F  ~# _8 j' `1 y8 w; L8 |4 E9 o0 M# _
turtles-own [a b c d k f g h" |3 c2 y8 f" k1 n0 C6 Y
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 7 l9 t$ m9 \3 B
]
! M, T; h! Y7 v" C8 ]5 @to new" K- u: n, L4 N& V  W) c) ]
  ca5 u: Z0 G! o* H/ z; W% @3 ]
  crt 5 * num_of_building
) G7 a8 d; S! N, V' W, \  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
, Q. k4 N' v. }% H( |  scatter     ;;keep center-turtle random positions
, d7 A6 k" X4 J" j: ?  unit_plan   ;;make up the building plan
2 e" K- J% t: G" w& i" ], @. m% pend/ v8 D3 B! {% Z0 n
to scatter  z: Y, x0 n3 V. d9 ?
ask turtles with [remainder who 5 = 0]' i  p2 L) J/ ?% U1 X5 u/ r
[! ~9 x# e3 o0 u+ s
set xcor xcor - 6 + random-float 15" [& S) H' b0 V
set ycor ycor - 6 + random-float 15
5 O% d# g* G8 r2 Y3 G+ o& Y9 ^]0 r$ x! q( D% w, x+ b
end  s: q' B5 H. R3 z; k
to unit_plan / N3 v6 a# ^! M
ask turtles [! H6 a( w6 c- j% j  T
if (remainder who 5 = 1) [set a who
& |8 n# S3 D0 K& t& L5 V$ t2 {                          set x ( 0 - Wid / 2 ) 6 X, y2 m9 x/ i  U2 o! W' b
                          set y  Dep / 2 ]1 }1 j2 K* w5 _- w
           set b  int (a / 5) * 5
" x* \) g+ t' @& ^& S2 o6 r( ~! A    setxy ( xcor-of turtle b + x )
- m: H7 D( q4 C- T, I4 Z          ( ycor-of turtle b + y )
4 B7 M' I) ~- `- W1 }0 Cif (remainder who 5 = 2) [set c who# r! g) F9 L9 X3 t: e* E- S
                          set x ( 0 - Wid / 2 ) + _4 w( H3 A5 Q( J
                          set y (0 - Dep / 2 )  ]& w" Y1 }* U: D
                          set d int (c / 5) * 58 g% [4 h9 @6 J$ F
   setxy   ( xcor-of turtle d + x )
" w7 `+ D- X8 s; v" |           (ycor-of turtle d + y )
% ^6 p0 Y% X0 W5 A* g( R; v3 B         
) r/ l+ `* t( a  _" H/ U: O            0 n/ d# {+ s3 V" h: F4 i$ |
if (remainder who 5 = 3) [set k who
1 l$ t' V' @$ ]# @7 ^                          set x( Wid / 2)  ( x# {$ @/ j" ~: c; N& `- o8 T9 ]
                          set y (0 - Dep / 2 ) ]
( R& {& u9 r. P) c4 X                          set f int (k / 5) * 5) l& M% R' ?/ R
  setxy   ( xcor-of turtle f + x )
, C' h, S: G3 `3 p. P# m/ q- \           (ycor-of turtle f + y )
$ R, Q* g( `6 ?: q5 E/ Q( L           9 I# z+ W: Q1 B8 w# k
           
6 V, N- g& x! H: W* m+ lif (remainder who 5 = 4) [set g who" z4 @' n# B2 E5 ^& C4 \6 ^* W
                          set x Wid / 2 : |/ z4 O" ~/ F& ~) g; c; Q
                          set y  Dep / 2 ]
# g& ^# p: G6 i/ z, X                          set h  int (g / 5) * 5: m9 c/ }) W4 W& Q2 E. j
  setxy   ( xcor-of turtle h + x )
, t3 Y0 ~2 K$ b           (ycor-of turtle h + y ) , X$ Y6 A& S. w, s1 c2 o
                          
, i  S' l4 y* o4 e5 o                          ! x+ `2 J5 Z+ q# U0 I0 l$ z/ N, C
                          ]
# v% S0 D6 n: |! y+ ~. S0 Lend
# d  ^* A3 ~9 y/ I8 S& Y: y# e+ F0 T
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
) E9 S: `0 A! P应该是
: N  [' W* A  l! dask turtles [
- w- I" ?* v4 P( M' zif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
% G& S# B% P# l3 \/ {5 u2 ^* ]3 D                          set y  Dep / 2
$ [$ b  x6 w8 x" ~& |- j           set b  int (who / 5) * 5
2 G3 ^% K6 K& J: ?8 s& Y5 C, ?    setxy ( xcor-of turtle b + x )
9 n+ ^6 P: J4 \          ( ycor-of turtle b + y )]]
- u3 w' z, F( B" ?; _3 [. ]. s0 aend
3 B( ?" K) {) N! N) b之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-8 08:43 , Processed in 0.019746 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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