设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8490|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
# w0 Y2 j/ \* n0 h2 D/ F9 m$ m) M/ F. V2 Q, j  B9 q- d( T2 v. _
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
+ K+ V& M) e; y& T5 F$ [) {- u& h* v( U( f% I4 J' R
turtles-own [a b c d k f g h
; N. ~: v; t6 I3 M& Y. B  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 6 L: E& p+ b0 z6 h
]  r$ [" e* B; c6 ~0 w& \
to new
/ l' [) t. z' x! _4 G  ca5 r/ Z0 A) a/ l" ?2 z* u# e
  crt 5 * num_of_building9 C* @) l& \/ r
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]1 j/ O& {# f7 j% i+ a
  scatter     ;;keep center-turtle random positions
7 A4 k* [2 O- K2 P  unit_plan   ;;make up the building plan2 @/ b* u7 r+ _) k/ {7 K7 v0 N& b
end  R! E8 r0 M# J, h9 B2 Z0 O
to scatter( w: [( D5 c6 H7 P
ask turtles with [remainder who 5 = 0]) |+ W( t& V8 s+ ~, n
[" T" l, V" G' i) L. u
set xcor xcor - 6 + random-float 15* i' `2 `4 T3 Z& Z* D
set ycor ycor - 6 + random-float 15
, _+ O8 B- I! N2 p# j0 Y: R0 ]7 `+ N]" c- {* q4 m$ ?% z; S: _# L
end+ ~4 C$ J( z' O, X
to unit_plan 5 b. s: X! g  V$ k9 E
ask turtles [0 q9 F2 k. n' i4 F
if (remainder who 5 = 1) [set a who
  p: a! z# u; u2 C2 u5 ~                          set x ( 0 - Wid / 2 )
- \5 ^* R6 a2 f2 ~                          set y  Dep / 2 ]
. j6 ?" x. h" n; Z" Y0 K           set b  int (a / 5) * 5' \1 `: I6 Y* g: [% V: Y. o6 N' K& t
    setxy ( xcor-of turtle b + x ). J- m4 H; X- K" O
          ( ycor-of turtle b + y )5 r7 b$ v8 X% D6 F
if (remainder who 5 = 2) [set c who1 l% A( ~7 w! @6 i9 G% w3 [
                          set x ( 0 - Wid / 2 )
+ p, U7 g5 j; v( a: m9 p+ R                          set y (0 - Dep / 2 )  ]4 A3 X: I  V2 X& P
                          set d int (c / 5) * 5
% I  g$ `' ?! v: u# G! [+ d! f7 K   setxy   ( xcor-of turtle d + x )
' z  e- W9 r$ G) M           (ycor-of turtle d + y ) 4 I5 I& V: Q+ I; w
          % J9 v6 O# }1 H1 h) D  `
            
8 g8 F$ L5 H' |  P+ M% o5 ]if (remainder who 5 = 3) [set k who
" @7 N1 b9 F0 \5 `% p- w                          set x( Wid / 2)  : o6 J  K( _& v$ X
                          set y (0 - Dep / 2 ) ]
$ v6 S* h1 M( O7 e* f& D                          set f int (k / 5) * 5
1 f/ {! @  l3 c* D5 m5 z8 F5 |  setxy   ( xcor-of turtle f + x )
) k( ^9 c5 N5 D8 J( c1 [. u           (ycor-of turtle f + y )
, B, t; H2 \4 P9 _           
8 z  N8 O) u: b  v1 P           4 L$ e8 L3 }% y, K- B
if (remainder who 5 = 4) [set g who
) D* }: [" a! C# D, l1 M; l: n                          set x Wid / 2 $ \6 P! d, A, o% U( e; f$ {% t7 i
                          set y  Dep / 2 ]
* q% w  g: T3 _) A- I% ^                          set h  int (g / 5) * 5* T) |! i% Z+ X0 f2 \* s
  setxy   ( xcor-of turtle h + x )1 n- O9 O- q* O* R% q" p( q) s
           (ycor-of turtle h + y )   O% P, q  H8 N; W/ N; _
                          2 @  o" H5 u+ G' f. j# t7 e- t4 U
                          
! t" Y4 p% U* N' u) k! ?                          ]
9 s: _% v- D( p' V( Q& Jend  |3 a! b3 G+ l# N. G7 R
$ y5 f# v3 L% B# X6 G7 v
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,8 t* Z: ]! o7 m+ @! G$ E+ b6 K& O$ Z3 a
应该是
; a! O8 O2 k% E7 N4 }* qask turtles [
! R5 s; M6 R7 vif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
/ O4 U7 i8 Y9 o. E5 U+ j/ I                          set y  Dep / 2 # k) T" s; A1 V
           set b  int (who / 5) * 5
1 a$ X+ C8 t4 j9 v. m( n, z2 V& w    setxy ( xcor-of turtle b + x )
4 O7 c9 ], K: \% t. G          ( ycor-of turtle b + y )]]
  G$ _# u* b# o: |$ O" p9 eend
" G5 @" B5 }$ m2 b% z之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-4 02:22 , Processed in 0.027364 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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