设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4106|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
) u( c) P3 v- ]+ k
9 N! H" |- @% u8 D5 z/ m但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
$ ?- ?; }3 G$ P% G) n
% ^$ A/ H* v2 W( c* h' Tturtles-own [a b c d k f g h, J; s0 b1 U, r0 d  z5 [" @; h& E3 R
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
/ x7 X0 c9 b" l4 ]* X/ g0 x]
) B6 l. r: K6 P( d$ I# Q6 _to new
2 j5 K; h' J, X- y  ca
! G2 L$ x6 ~# z6 ~( ^  crt 5 * num_of_building
3 D) y/ u4 n; g3 V" [  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
+ @, e3 B4 d6 Y+ H; a8 ]  scatter     ;;keep center-turtle random positions . t! h4 I  B$ P' @/ _" p4 k
  unit_plan   ;;make up the building plan
; f/ O* ?& Y& x7 V7 f4 X+ e1 Vend+ I* h" E$ t/ e, V3 U0 g' u5 N
to scatter
7 U1 |8 x, {) p! ~. r) I0 Bask turtles with [remainder who 5 = 0]
/ d) O) E" ]/ H1 m* z3 }[
' ^, n5 C' r) h  m' I7 @/ zset xcor xcor - 6 + random-float 15
) v% k! C- z( b" E% Iset ycor ycor - 6 + random-float 151 Q/ S" ]/ ]6 g9 ?. u
]+ [; m' h0 ?! T, J1 w, m
end1 V  k5 F5 F8 b
to unit_plan ; {4 [- q& x2 O' i
ask turtles [9 j6 R, q8 t* k. z# A
if (remainder who 5 = 1) [set a who 2 V% N( j% u+ k& X+ {: N$ p4 u
                          set x ( 0 - Wid / 2 )
+ I9 G+ G# {3 k                          set y  Dep / 2 ]8 P" O4 \  n- F/ n( t
           set b  int (a / 5) * 5& B2 }8 e" @( H- V8 Y$ X
    setxy ( xcor-of turtle b + x )
( B2 U/ f- q" _% e  e3 Z          ( ycor-of turtle b + y )
! B* I1 F7 M7 Z9 d& pif (remainder who 5 = 2) [set c who# M. ^  n0 m, {
                          set x ( 0 - Wid / 2 ) 0 P- V$ |8 O& C( ^' s+ P
                          set y (0 - Dep / 2 )  ]; D1 @) L6 @  T+ G
                          set d int (c / 5) * 5# M& y% j9 ?* ]: q) M& n) ~
   setxy   ( xcor-of turtle d + x )) V, ?" d8 S$ a- U* p
           (ycor-of turtle d + y )
; R" m) y5 h1 Q4 U( {  Y( I          % f* g, O- B& B' h
            . ~  h! Z4 S& j
if (remainder who 5 = 3) [set k who- A7 k2 e" x& v5 E5 q
                          set x( Wid / 2)  
3 R) v6 c$ T% u/ T% k5 c                          set y (0 - Dep / 2 ) ]
. q% [( E3 w6 x8 W1 l; x                          set f int (k / 5) * 5
7 g+ Q$ `6 l, C$ j- J( u) n+ n  setxy   ( xcor-of turtle f + x )2 r% B5 _$ ?: i( r
           (ycor-of turtle f + y ) : ]# Z/ y; L4 V6 j
           
% j' ?# {. J2 H* ?           
" [  t) o- \9 H2 M7 ^9 L9 oif (remainder who 5 = 4) [set g who- V2 y& {* J: q8 r! x
                          set x Wid / 2   N) n9 Z/ @6 {/ O5 d
                          set y  Dep / 2 ]& I& o# K' N0 p& c6 j. n
                          set h  int (g / 5) * 5% N: N7 r1 E# Z: X
  setxy   ( xcor-of turtle h + x ): X  n  F  `' K* r2 M1 _) s
           (ycor-of turtle h + y ) * w: G+ h. Z- m* e. t' k
                          
% l* e6 L( @: {% U                          9 c9 b' N. a! _4 m
                          ]
9 g7 _; W3 ]. i( U% z/ Y- cend
7 i3 \- l& {* g. _9 z  K% R9 T5 n" e$ V8 d9 Y5 D& b( N4 S# R
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,# V( v  S8 `2 c. T+ n$ a
应该是5 u: U* b' g8 Z9 `
ask turtles [
0 Z+ f; U( l' ~if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 3 u+ d. [( h# b/ V* X
                          set y  Dep / 2
) P) [# @. ], R3 I% N           set b  int (who / 5) * 5
) _  m( p& |* t0 M  h0 u$ g    setxy ( xcor-of turtle b + x )0 u1 b' N3 \5 S; r
          ( ycor-of turtle b + y )]]8 V2 D$ s2 G( V; s- C
end
9 |8 _$ q6 w9 o1 e' I5 |  v3 q之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-4-28 07:04 , Processed in 0.015587 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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