设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7270|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
; D- G$ y9 ?- k, f. L% q3 ^. z1 ]) G7 d1 I, K  t2 d! I
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。" V% z$ r( g# @2 W
" i" B/ }+ f/ _, q+ i: q: H
turtles-own [a b c d k f g h
2 [. z6 u5 q2 T  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
; m) ^4 {% i$ _8 A+ e; g# S$ ]]/ ^) m. E+ v* ?
to new
% J# M$ s( @; L& }; y* [  ca
7 P" z9 ?" S7 E  crt 5 * num_of_building
. m5 O2 h1 O( ?0 V! {  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
9 O: Q( \1 Y% |! A4 Q: {# ?  scatter     ;;keep center-turtle random positions 9 d( o1 Y. I# Z# P/ w9 ?9 s
  unit_plan   ;;make up the building plan" A: ]' |. [* M9 h+ g
end- h' B& h2 f9 V4 x  J2 G1 G9 [
to scatter
1 M% Y0 T8 F$ r2 L+ b/ ?ask turtles with [remainder who 5 = 0]
2 [- S% c$ O8 n! ^; h" k0 g[
6 x) Q% X: S6 f, D$ Y1 mset xcor xcor - 6 + random-float 158 e+ n! f& K, v0 v$ |9 e
set ycor ycor - 6 + random-float 15' r  H2 U6 ]) M' h: A$ F
]
/ U; _* j0 p% o/ T2 }# ^6 bend# _- ?9 z, }# }" r# d
to unit_plan
* U+ q- V7 E  Q5 Y  k6 Z/ dask turtles [
3 Z/ f9 s! j' I1 g, Zif (remainder who 5 = 1) [set a who
! s1 ^6 [! ]9 A  _9 [& D5 o" X                          set x ( 0 - Wid / 2 )
/ E: O8 F& |% O; ?- z/ e. U& {                          set y  Dep / 2 ]3 T6 u- X0 R: ?( o' {
           set b  int (a / 5) * 5# Y: J  L0 A2 f, G
    setxy ( xcor-of turtle b + x )' \5 ^* [4 c& U! j, E9 y: s8 ]# X
          ( ycor-of turtle b + y )
+ U2 M. T: X5 |4 I3 V6 @if (remainder who 5 = 2) [set c who8 [7 y' [& Y4 v* m5 J/ P3 H4 V
                          set x ( 0 - Wid / 2 ) 5 ?3 T+ @" X* E+ h, w$ e
                          set y (0 - Dep / 2 )  ]$ Q/ f$ c( [6 U1 Q' K( Z# L
                          set d int (c / 5) * 5* v6 |( m) z, ?" b$ V- ~6 J
   setxy   ( xcor-of turtle d + x )7 Q. x$ E; d" C7 R; C1 M
           (ycor-of turtle d + y ) $ Y7 |  \9 S4 P0 q' Q' r
          3 p8 y0 m) e1 M9 ^
            * o0 w0 y) Z/ \& p/ z- U' n/ g8 J9 |
if (remainder who 5 = 3) [set k who
5 j2 ~* B, |8 D2 S- T4 B                          set x( Wid / 2)  & H. K* ]& v+ a7 m9 X8 z
                          set y (0 - Dep / 2 ) ]' g% a/ x% a8 ^, m: P
                          set f int (k / 5) * 5
8 V& }9 d5 ^3 Q# z1 t' \  setxy   ( xcor-of turtle f + x )/ Z& S% j# \( @: h: ~8 |: {
           (ycor-of turtle f + y )
+ h$ \3 T7 W$ I3 j2 o           $ A4 `$ t) n2 h; {! G! f
           / E$ m0 c  q; r( N& n, ]. R$ k0 L
if (remainder who 5 = 4) [set g who
/ g1 s1 B/ w6 M4 s: r0 F% W                          set x Wid / 2 9 Q& L9 E6 m1 I! b$ F
                          set y  Dep / 2 ]
" I( \7 s, D$ J- p) [! t9 J* a                          set h  int (g / 5) * 57 ?9 A8 U6 e( R/ B! D
  setxy   ( xcor-of turtle h + x )
- t: f1 Z. C) ?* c: s           (ycor-of turtle h + y ) - {+ a5 _8 H) [2 D
                          * l3 E. o5 C1 _
                          
7 G/ g: ^8 {0 n" _- |0 G. u                          ]" r0 ?. R5 w2 b! r5 O& _
end) s! U0 Z. T; M7 m, H' j

6 V/ N7 Q& M* C* Z8 v' j5 Q" K[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,0 W; t" N9 B5 {* b. ?
应该是' P. x6 W; |# G" |
ask turtles [3 ~* C4 k3 U" S+ D* ~% h% G4 u( m/ T
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
: j- M& G, q; T: H                          set y  Dep / 2 ' s% _# V5 d4 R* }
           set b  int (who / 5) * 52 F2 ~# k9 p. X5 I
    setxy ( xcor-of turtle b + x )
- [5 l! H' `, M5 {4 C1 m          ( ycor-of turtle b + y )]]0 ]% ~' \# Y7 A- c; p& {& ?
end
" I1 y0 R+ S. F7 Z2 M) J之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-23 10:52 , Processed in 0.017523 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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