设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8025|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
9 E* o! G% f9 l* b2 Q9 n( s' r! b* E' Z8 `5 |
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。1 f0 S6 g7 e8 [2 N6 ~4 D
3 V/ H1 G0 {  e% x; x
turtles-own [a b c d k f g h
6 Y" d- \. W" d, L  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
- Z/ ?% `5 w. w/ Y& u/ h( x]; c5 f5 D' J3 L4 {
to new
$ g* \8 E7 ?+ {) M. l  ca
8 h; O  r% I2 Y2 G# o  crt 5 * num_of_building6 ?) ^* r) P3 v6 G9 z; ^
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
7 i7 _2 F- b, B0 G/ S) ^% \  scatter     ;;keep center-turtle random positions
. f; Y5 f! M; ~* k1 R1 e6 h  unit_plan   ;;make up the building plan6 T& }, j5 u$ h7 I2 |" b4 r
end  Z5 Y$ o. s% O( ]/ ~9 t* P3 m
to scatter
- R" ?4 X- L& Z! [ask turtles with [remainder who 5 = 0]
, e* p0 n* a8 |+ [2 }  o[5 l* O2 w6 n7 a: Q% X& {# A$ v6 f& ~
set xcor xcor - 6 + random-float 15/ A8 K! L3 B' M% ?
set ycor ycor - 6 + random-float 154 x# m, N( Y1 h% N, T0 L$ o% x
]
4 d- u+ l. P8 r% P2 ^2 Q/ o) E+ z: Z8 ^end: p0 u& `+ E  x$ I- \9 q) V9 D
to unit_plan / a$ Z2 [% b2 y- a% D4 g+ [
ask turtles [
: N# Z2 X0 v- S+ l1 P* jif (remainder who 5 = 1) [set a who
. ?0 M2 B. ]2 o# q; E                          set x ( 0 - Wid / 2 )
8 {6 ?6 p& h/ L; W0 _$ b9 N  u* ~                          set y  Dep / 2 ]* S1 Y; ?# h4 u0 w! t" `% q
           set b  int (a / 5) * 5  I3 g1 [& _* ], l# b
    setxy ( xcor-of turtle b + x )
  D$ C+ |" w! Q. r          ( ycor-of turtle b + y )
% W& d. n! c9 A6 |% Z0 e  oif (remainder who 5 = 2) [set c who. s. X/ a; `/ m" m! S7 j
                          set x ( 0 - Wid / 2 ) / Z& M& l( u! q5 Q  V
                          set y (0 - Dep / 2 )  ]& u8 L  r; F* a9 D+ P" |
                          set d int (c / 5) * 5/ ?4 M( x3 E! e; t; z2 ?
   setxy   ( xcor-of turtle d + x )
8 R! i+ V. n; D, K/ D( Z$ _           (ycor-of turtle d + y ) ( a2 ]" B0 L7 R- d) u7 ~
          / e. I( i  S: ~- c  O; p0 L
            " C5 s# j; h! F! @$ x
if (remainder who 5 = 3) [set k who
3 ?# h$ C- P, ]- D2 s                          set x( Wid / 2)  & R1 P1 J% m2 Y
                          set y (0 - Dep / 2 ) ]
2 \& \$ |+ ]  a                          set f int (k / 5) * 5
) a  x9 g" G  e$ \  setxy   ( xcor-of turtle f + x )
+ w: V6 u7 P! i# O7 T8 S           (ycor-of turtle f + y ) % N! w# Z! o# d7 Z& R2 }2 B* F
           ) l  D+ z" H, ]# \0 {0 m
           
( f/ p5 @. J9 t& w3 Fif (remainder who 5 = 4) [set g who: q* p  u  m- j# @
                          set x Wid / 2 $ l. q6 V  ?3 ~' w4 V+ A
                          set y  Dep / 2 ]  y" h. l/ q" a) D
                          set h  int (g / 5) * 50 i) D; O! v! z! Q3 y# i1 T
  setxy   ( xcor-of turtle h + x )
1 I9 A) E8 d3 ], J1 h           (ycor-of turtle h + y )
6 B0 B2 p( @3 X" _* G7 ?                          
# T8 k& B) a& ^3 b$ q( a& @5 h                          
) ]' l7 G! _! t0 t0 _+ P9 c$ h6 B                          ]" r9 Q0 v* m5 n/ ^0 I- B7 z; ^: \$ S
end6 E" ]; z, [! [5 J4 f) p3 W* O2 _

' [% e3 H0 W+ j' l: }( A5 L' B[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,8 l1 g- g4 r* o9 l0 e% K( T* n
应该是$ \" [2 s" Y* L$ k
ask turtles [
5 C7 {) o9 q* Q7 e; `. ?if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) , p7 J7 X" w# Q* Z9 {4 U3 b
                          set y  Dep / 2 - t5 U, ?8 [, Z5 g) P
           set b  int (who / 5) * 5* i4 o+ Q. k& X: S' c! L% ?$ _; g
    setxy ( xcor-of turtle b + x )
+ @' B8 s$ U. b& Z          ( ycor-of turtle b + y )]]
4 ]& i2 Z4 b' ^8 Q2 ?9 s9 Q$ f  zend
0 A* d4 ~' Q6 o% t3 e$ d之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-29 16:49 , Processed in 0.018835 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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