设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8134|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
) S7 Z+ E5 r. U* A8 L
1 c6 N. w2 v$ w! u7 l: I1 O但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。1 u6 _( c% @" V# m- n8 j2 I

4 D! N7 {' I; z/ L$ Cturtles-own [a b c d k f g h* ], x$ e0 ^, v. [
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
1 P" c! M5 B5 a: f  V]
' \8 n* }4 O/ X: ^) g8 Nto new
1 w6 X2 f( t' H+ @  ca% Y4 M5 Y6 D/ H( t7 y+ a5 m6 `
  crt 5 * num_of_building
# X/ D2 r+ B" h5 s7 D* F& w$ W, ^3 M  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]5 _+ N7 N7 G1 a7 _) Y9 h9 u+ M
  scatter     ;;keep center-turtle random positions 0 G! _# V  j/ f  s
  unit_plan   ;;make up the building plan$ J  z2 @% g8 @8 m8 A. `9 g2 c
end
. _( b8 \+ V; v$ E( w5 vto scatter
+ m8 `- G" w, a( ?# oask turtles with [remainder who 5 = 0]
; J3 ]/ [  V( N+ g$ _7 Q, t- k4 P[' A% s! z+ I* l8 D* R4 L
set xcor xcor - 6 + random-float 15, O- |* C8 }5 r0 e2 N5 D2 p
set ycor ycor - 6 + random-float 15
1 ~9 F  G: \+ K% J1 i$ R8 D]
; w( D% _$ z; s% l3 {" `end6 h$ m5 ~. D) @* m' d
to unit_plan
" A* _+ t2 P4 I! nask turtles [
( K! Z! t5 R  H9 c# Y# p. l) @if (remainder who 5 = 1) [set a who
3 C; [% R. J1 C: p& ~1 T1 }                          set x ( 0 - Wid / 2 ) ) e* T  w" U- _1 v
                          set y  Dep / 2 ]
4 g9 e" d! C5 _; Q           set b  int (a / 5) * 5
2 V- M+ T" o' B, M( J& \    setxy ( xcor-of turtle b + x )3 T: a/ i6 A" Y, j- ^
          ( ycor-of turtle b + y )
& @; T) z5 c1 K& E, s7 ~if (remainder who 5 = 2) [set c who
. E  N9 ^# b1 q$ L                          set x ( 0 - Wid / 2 ) * E) |  z+ q; q% ]) R* O# ]$ S
                          set y (0 - Dep / 2 )  ]
' X. f, e! T$ t: V. _) e/ o7 Z1 B                          set d int (c / 5) * 5
6 F5 d7 f! ~6 |- V2 e6 p3 }   setxy   ( xcor-of turtle d + x )
6 q; M  P% l: Z$ ^0 f           (ycor-of turtle d + y )
6 G; D. A) E2 t/ f+ U5 ]) h5 O* ?  r, j8 k         
+ O7 j* y2 w5 V2 R- N6 k# O            
1 D: p$ G; u3 ^( s+ d  i4 Vif (remainder who 5 = 3) [set k who
9 |+ q& j/ c- _4 q9 Y8 S7 j                          set x( Wid / 2)  ; p* Q4 H0 x9 W  m" Z% N, H
                          set y (0 - Dep / 2 ) ]
) |1 ?9 a4 \! p                          set f int (k / 5) * 5# @1 p* x! h: r/ {* Y4 y9 [: W, z6 [
  setxy   ( xcor-of turtle f + x )
5 r' E9 H( N0 `+ \) o6 I, C* V           (ycor-of turtle f + y )
8 b1 N, ]: r9 y( {, x  S           
( J, y" }' \( V: S% g           / V  U  I% @8 C$ S# Z
if (remainder who 5 = 4) [set g who
% Q* C9 i# T2 F% k3 G% ?. x                          set x Wid / 2
4 D+ y+ m* T0 r: n0 a9 B  A+ H                          set y  Dep / 2 ]
$ b. |3 ^8 o3 ~# H                          set h  int (g / 5) * 5) R! _! r' \7 R7 L
  setxy   ( xcor-of turtle h + x )
' ^$ s. J% }: U           (ycor-of turtle h + y )
5 W& r9 T% Z9 I2 Q                          
6 g* ]) v7 i# a; |3 X1 A- V                          0 `. L$ [# m4 U' {; g- L
                          ]$ B) @3 m6 M2 J# t
end2 V- c6 j2 G' z. o/ G
, Y" ?: W5 w7 }. g. z7 N, Q
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,& S6 p, G1 @' v! V# J9 G
应该是5 C: l2 X9 o) m( \: b/ {
ask turtles [" y/ a% J, R0 P/ e5 T" N4 a' ?& I
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 2 j# W3 q$ M) E( n' l# c/ f. G
                          set y  Dep / 2 5 _; u. ~- [& t  Z
           set b  int (who / 5) * 5
& S# d+ f9 ~* @: K4 D0 A8 W    setxy ( xcor-of turtle b + x )8 C0 B, g- u8 ]! R7 p
          ( ycor-of turtle b + y )]]8 q( ]! R9 A& E2 j: _
end
, h$ a5 m6 M  @, X7 ?* N之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-10 06:41 , Processed in 0.019437 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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