设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8079|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
& V% D* T. o0 G( u
6 \2 D# `, N" @8 n# n& G5 H但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
7 P8 Z& h/ w5 D! c6 A& P/ `* ]" _: q0 l! m" T
turtles-own [a b c d k f g h) L- ?2 j" t5 J8 _4 J/ n
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
& L2 l3 h6 b2 c& M]# H$ J! d# D2 Z. K" l2 W' ~& `% N
to new" j, Z* d$ w* v( K3 K' L: F
  ca' i$ c$ v9 R- u7 r0 \2 D' M- ~- k! ?' E/ {, u
  crt 5 * num_of_building$ `# B4 e! \/ J2 t( k, \; W
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]; \3 [5 N/ d# z: Z0 W- ?0 u% _
  scatter     ;;keep center-turtle random positions
! Q4 g% |- i3 y; D  unit_plan   ;;make up the building plan
+ \4 u5 R( |1 B: ~5 G; k6 Dend8 x2 e2 D3 ]$ n" W
to scatter0 T' z, _$ w1 e0 l9 ^" `; x
ask turtles with [remainder who 5 = 0], u/ L$ K8 }: @; P* o& g* o
[2 v# X' P8 v- y* t" b
set xcor xcor - 6 + random-float 153 _, K) w4 }* @) V$ i% u( Q
set ycor ycor - 6 + random-float 15
3 p# j1 W5 T! P$ B; V]
5 Z& z) w4 a6 i/ [$ p* O* Lend
( m( Y8 |# ?( w+ F+ d* T/ Q& G& dto unit_plan 2 |/ p7 s: o. ?" o
ask turtles [
1 x$ K8 U- X- ~9 P% L2 a1 ^0 Jif (remainder who 5 = 1) [set a who
9 b0 m3 Y& X. }! P; i; ~                          set x ( 0 - Wid / 2 )
+ j5 y! `! t! w5 V# _) [; s                          set y  Dep / 2 ]$ q, E. ^* O/ d3 ^
           set b  int (a / 5) * 5* P; v- b2 r; r( B
    setxy ( xcor-of turtle b + x )
. l" M# C  {# ?0 o          ( ycor-of turtle b + y )  L& Q7 k6 g, f& i
if (remainder who 5 = 2) [set c who' ]9 h( |# n) e; }! S. ^
                          set x ( 0 - Wid / 2 ) 6 R+ {: k' d: {8 u1 N3 |
                          set y (0 - Dep / 2 )  ]( a+ x1 `  o( o3 ~
                          set d int (c / 5) * 5! t. C: u: Y3 e6 T, w+ P( C
   setxy   ( xcor-of turtle d + x )
& {7 \, G( ^9 c/ l; k4 k( o4 p( J           (ycor-of turtle d + y )
! f& t' z  x4 _! D# I2 l, r1 l         
1 `. b9 s3 G3 K% x7 U5 D! M            
' F+ v" K% D4 n" _7 j9 U9 @% [if (remainder who 5 = 3) [set k who! w/ a  d  J& \# c
                          set x( Wid / 2)  2 A- Q* H/ |3 y8 a& T  t
                          set y (0 - Dep / 2 ) ]
9 i* `9 K9 ?- G& Y0 B' P; G                          set f int (k / 5) * 5
7 E( \1 B: m% h  setxy   ( xcor-of turtle f + x )4 H5 v* ~* T4 z! [# C! q0 `
           (ycor-of turtle f + y )
, M- K3 N9 S1 y5 K5 K5 E7 ]           
. _( |* x' L; w( k; m  K           4 A7 S1 I; W0 H/ r. n  y
if (remainder who 5 = 4) [set g who+ ~. I/ X, i/ T2 v& H2 c# b5 a) s
                          set x Wid / 2
) X: S& S: }- o" B                          set y  Dep / 2 ]4 F2 K, F- L  A- c5 s
                          set h  int (g / 5) * 5+ C! c2 ]# k& y$ G- L
  setxy   ( xcor-of turtle h + x )
3 x5 ~" @0 S# e& F, M           (ycor-of turtle h + y ) 7 B- T) M1 u; g% b* V% d2 K
                          # Y% p, F3 Q/ c7 @% Z; {% R5 C/ o
                          
, s+ ^5 [. }! \- C+ w  e0 @) C                          ]
. @" j# E) Z: W: u8 r7 Y$ R5 Iend
* e4 o' a+ D) d; J: F- n# J% O& L5 e+ Z
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
2 a) r, Q$ S% j* f  ^应该是* Y# {% n& w& J$ Y! b$ B: ]; Z
ask turtles [
9 L/ a/ h" N. j% Z8 {* W& v: Q9 n8 d4 Hif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) / o4 k6 @2 z9 a. h: A5 ]- w# [3 ]' ]. u
                          set y  Dep / 2
8 r6 y7 ^. o! y           set b  int (who / 5) * 5
" t+ T& K0 [; T1 Z/ M    setxy ( xcor-of turtle b + x )
: [; L2 N9 v/ b: U. G          ( ycor-of turtle b + y )]]5 V  r# E$ k3 W; y% f" n
end
" C- g7 u) z8 s, E; R/ E之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-4 19:39 , Processed in 0.018474 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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