设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7885|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
% F" T! ?* t( M6 }+ V+ i' m- t: j* F+ J) v* t5 H
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
! ?, ^8 y  r5 c/ W0 Z; _  g, ~; A  T3 R& o5 D! M
turtles-own [a b c d k f g h
$ b* R/ X" d5 L- G4 p$ o5 }# C  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 3 s' w2 C0 |, J- p; ]
]
/ h9 u, `' H( u) p7 ato new' l5 n/ L1 P9 y$ a& G
  ca4 E' D* O$ m. [& q& x% w' @0 h4 x
  crt 5 * num_of_building
# G/ i6 _& @" p* a  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
4 {% m' J+ `; L0 E  scatter     ;;keep center-turtle random positions
# H" A1 ]& @9 ]+ Q, R: j4 w/ M  unit_plan   ;;make up the building plan! z8 s5 X" o2 G1 ]9 v, i
end
! {% O$ h% Z0 _" B3 V7 rto scatter, A8 i- m6 A' Q. O6 w
ask turtles with [remainder who 5 = 0]& m7 B9 w! A3 H! U
[% Z8 C3 Z1 u/ e! b
set xcor xcor - 6 + random-float 15
+ K6 B" r) r# t! r3 b: W8 `! a, [set ycor ycor - 6 + random-float 15- }5 J  ?; h" N- t, w
]" f- @& p% D  q. g# s
end" d# K, V7 w5 F# [, C9 q
to unit_plan % i& _- R- j0 i
ask turtles [
- A: O. a  k! yif (remainder who 5 = 1) [set a who
% e& k) S. x7 l4 M" e6 n                          set x ( 0 - Wid / 2 ) + A  \- p& W2 b+ p
                          set y  Dep / 2 ]- r$ g6 I' d# _0 P9 n9 s2 ]
           set b  int (a / 5) * 5
$ N: k0 q( a# T! M* @1 e. v- k4 Y    setxy ( xcor-of turtle b + x )
) Q7 l7 ?9 S/ ?- C          ( ycor-of turtle b + y )' Y# ~5 A7 @& @4 d" G; _) ]
if (remainder who 5 = 2) [set c who6 L; }0 t% f/ o" N4 }6 l" S& X
                          set x ( 0 - Wid / 2 ) & l' [9 i+ z7 E6 J# I" x! p' F
                          set y (0 - Dep / 2 )  ]
1 u+ m# v/ }) `3 @; L                          set d int (c / 5) * 5
, Z/ K6 l6 I- q8 T% q# L   setxy   ( xcor-of turtle d + x )
- }# H2 |/ T: O6 L" t. R( R           (ycor-of turtle d + y ) 7 t# Z- C& p: R
         
  y/ A9 _% B& l' q1 l) `: `            / C% b/ ~! g4 ?9 l: i
if (remainder who 5 = 3) [set k who( _2 G. ?4 O* S( `. W/ S
                          set x( Wid / 2)  # F3 ~5 V+ W% e8 c( |# b
                          set y (0 - Dep / 2 ) ]2 _$ h4 p, C- @
                          set f int (k / 5) * 5$ _( I3 J3 Q/ G$ Y4 k$ U4 Y2 B# t2 Y
  setxy   ( xcor-of turtle f + x )
/ e; M. \2 U5 A2 u& ^4 L           (ycor-of turtle f + y )
' i7 G- R  N5 x, u- |3 E" B- u, Z           5 o  v( f4 L* ?6 R( [
           
/ S4 `+ S8 w! ^/ \& p9 U- z# Qif (remainder who 5 = 4) [set g who
) D* |7 r- ^% _* ]7 E% m/ i9 S( h                          set x Wid / 2 / `6 o; u; M9 }/ F! C2 a, {6 \
                          set y  Dep / 2 ]6 y; P) d, p- u3 c9 ~  J' S
                          set h  int (g / 5) * 5/ t) G8 B1 O, K0 V, P
  setxy   ( xcor-of turtle h + x )
# a0 Z& Z% k- }2 P6 J1 V           (ycor-of turtle h + y )
9 _0 n" ~0 v1 ]5 b4 M$ F                          
- b) _: G, y9 C  O% Y" J                          9 w0 l: K* P1 g2 s
                          ]
) V3 }4 T  E4 ^( |end
/ h: l3 A& b/ |$ t
- c( }- ?  k3 W2 G8 t* ~[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,0 u7 V* V! ?( G0 c
应该是. V' Y- f* h, Q# U" @8 P# K5 L
ask turtles [
2 S8 I3 m" b5 |6 U7 H0 `( I0 xif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 6 n" m7 J& e$ J/ A0 G: t0 J6 {
                          set y  Dep / 2
1 a1 ^& i1 ~2 w           set b  int (who / 5) * 5" O4 ~" ?7 a  m5 X3 x1 {. ~' d
    setxy ( xcor-of turtle b + x )) Q* Y) c& |6 G- ]; M$ e
          ( ycor-of turtle b + y )]]( ]& v! g  D( O1 u" \8 d. S' n
end
1 z% S: A" M* N( f, d之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-15 06:45 , Processed in 0.020171 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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