设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8286|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。" x# O  i, C9 |* O
" L$ }! D& c- |( P' U) [1 U& k
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
$ k. {  J3 A3 S# n& U( n# {9 ?/ e+ Q& [2 x) v3 N8 _5 {/ u
turtles-own [a b c d k f g h# h8 J4 C9 u  e; h' n& g1 G
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
- H; z& }% G! V& Y# P$ N( `9 z]) O! N0 O0 O4 L; I
to new6 k5 Y! A7 W! p, Z2 \
  ca: L# w" I# I; X% ~1 Q, W
  crt 5 * num_of_building. q9 O; O. e7 @- L; }0 a4 M
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
% W0 h! r3 z+ T' ]  scatter     ;;keep center-turtle random positions " e! [" W4 b8 s- Z
  unit_plan   ;;make up the building plan7 o/ d5 }5 D9 T" F1 E7 _
end# g' k" ^* f/ i; G. j2 P
to scatter/ H& H5 g, ~  O7 `- g9 e" ~0 E$ y
ask turtles with [remainder who 5 = 0]
$ z' _" q( e8 v/ r0 y[: h# w  W; k7 D* a0 [
set xcor xcor - 6 + random-float 15
$ W6 h* ?+ p) S5 ]1 bset ycor ycor - 6 + random-float 15# Z9 x! }, L7 {5 ~4 j+ L( E
]6 S% R. k- v' }& n
end- f. I! y6 v( Q) Q
to unit_plan
% {0 {  a4 G; gask turtles [
% [% `8 F0 g# V6 I6 [# Wif (remainder who 5 = 1) [set a who
8 @% b6 W, U* w/ c" b, `7 R                          set x ( 0 - Wid / 2 )   P# b0 q/ f4 b$ z
                          set y  Dep / 2 ]( b- U& {5 H& _; f  G- ^
           set b  int (a / 5) * 5
0 L. M) F2 c6 b" ^" |  z    setxy ( xcor-of turtle b + x )
4 Q0 K" D" U# W# v# |$ z4 {% q          ( ycor-of turtle b + y )
( z" i0 L2 s# e5 h4 Y. @3 k* mif (remainder who 5 = 2) [set c who9 r# `/ x  O5 Y9 Q& O0 m8 q- t3 B2 c
                          set x ( 0 - Wid / 2 )
5 M9 [  D; q. }                          set y (0 - Dep / 2 )  ]
. H- p1 v( g6 b7 [. i5 ]9 b                          set d int (c / 5) * 5' D4 E! H, t3 \7 u0 f
   setxy   ( xcor-of turtle d + x )8 P8 S& i+ e8 S' r: d# f
           (ycor-of turtle d + y ) ( _' L! b3 b. Y: ~& }
         
& Y0 e0 R3 ]1 G" G! T8 g4 ?            
4 r# [& a5 C+ s( Y& S; U$ Z5 Kif (remainder who 5 = 3) [set k who
" x2 L/ \* G) ~, y  n3 a                          set x( Wid / 2)  ( d5 }( w; }" k1 L/ }. z
                          set y (0 - Dep / 2 ) ]
4 P' R) `  Y# U% Z: }                          set f int (k / 5) * 5( ?( ^+ i) O% ]9 V/ b0 K
  setxy   ( xcor-of turtle f + x )
# K6 g' H/ H' R; E           (ycor-of turtle f + y )
: U+ ~  Y# ]. w& r! B           4 |; H5 T9 H+ ]5 C
           9 n  q' n8 y. J. Z$ C- \
if (remainder who 5 = 4) [set g who
2 f( b9 M" z8 {                          set x Wid / 2
) b5 t# }# V2 b3 @% O( ?+ ^/ y8 G5 p                          set y  Dep / 2 ]0 }7 k: T* |3 p; n
                          set h  int (g / 5) * 5
! K* q# Q% U$ w" M! ~/ G: k5 `# ^9 g! [  setxy   ( xcor-of turtle h + x )
2 A7 m- U/ n: g3 P, ^- w/ o           (ycor-of turtle h + y ) 3 B: L4 M' H, @% e; ]9 j, }
                          & x  A0 Q# W$ D+ B2 |3 B6 k2 _
                          $ k) V/ |0 O  t) r( ?  j) F+ W( ~
                          ]
, h2 o" y( d" o2 `6 dend7 ]/ H4 n, t# E9 B* B$ a
. M9 R3 L+ _) f
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
$ g6 E* R, T) L+ Z! e% Y应该是+ N4 ], n1 r. R5 Z3 E/ T
ask turtles [
* u: Y) m2 r; xif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 9 V, l" J' U; C4 {, A9 x  |
                          set y  Dep / 2 - Y& x& d1 p+ K' x8 p
           set b  int (who / 5) * 5/ N- x  _. @# i, x+ g
    setxy ( xcor-of turtle b + x )( q3 r7 z/ T' }9 H% r
          ( ycor-of turtle b + y )]]
  N7 d: O: j  Kend
8 f- m1 g; s, L' N* L9 n- L* {; K之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-31 07:35 , Processed in 0.013139 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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