设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9047|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
. h* a: j" y# E- L( u' G. b1 d" E- u0 K2 o; R1 _
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
2 ~! G# Y1 E3 q5 W1 s3 V+ N' E' c% U0 j  }
turtles-own [a b c d k f g h
1 u8 }2 P# A6 Q* j. D9 R  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
2 I8 o2 V/ d. P7 a( m2 ]6 J' j) V]6 x0 Y3 ]( B! m; `- d4 @
to new' ~2 O7 a1 m% c$ _$ U6 Z
  ca$ {6 u/ s" ~$ U3 q
  crt 5 * num_of_building' U9 O  @: C1 e- l- R
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]- U/ J" H- D' `4 N9 L) m
  scatter     ;;keep center-turtle random positions
5 `' T8 d* J/ m* z6 C/ D5 j/ }, m  unit_plan   ;;make up the building plan# S4 L# D7 W! F- h" X. F% c
end
$ W) b8 c+ S  r) Z  x+ V4 y/ G- bto scatter9 S, H% |4 _5 @
ask turtles with [remainder who 5 = 0], M, W! b) G/ r' W
[
% A- [8 k" z% T3 }. o2 Eset xcor xcor - 6 + random-float 15, P8 c4 V# Q. U* Z7 Z
set ycor ycor - 6 + random-float 15
0 x/ ?7 J! K6 W" z& v]
9 l- @6 u0 \4 n$ `. |" u: H( xend/ e( Q2 O- }4 p
to unit_plan 9 E. G  d6 q% {$ ?4 P8 c
ask turtles [1 T1 N, w5 N+ H  }  {0 Y! A" U
if (remainder who 5 = 1) [set a who
; b# R  \$ ~* Z$ @& R, Y" |& X                          set x ( 0 - Wid / 2 ) ' v7 N% z* z4 c
                          set y  Dep / 2 ]
0 H2 X) {( K. l1 {. ]           set b  int (a / 5) * 5% o! u& K7 d, u  a, F
    setxy ( xcor-of turtle b + x )2 {4 j( t. c3 D6 `+ W' c
          ( ycor-of turtle b + y )9 Q7 b5 T) V/ K$ v! H- k
if (remainder who 5 = 2) [set c who
) ~. o& e8 x( a% p3 _                          set x ( 0 - Wid / 2 ) 1 B# i0 B/ E2 ]' ?" u+ H/ T( \
                          set y (0 - Dep / 2 )  ]. s9 n" Y' D$ s
                          set d int (c / 5) * 50 ^0 {( k% w+ e# I" M2 A' \
   setxy   ( xcor-of turtle d + x )
' K3 }9 u" f) G. ~' b8 ]+ h           (ycor-of turtle d + y )
. a' z! y7 t9 `/ y% d/ M1 O          2 u, h2 T' o  N4 _
            
) m2 o' E" w7 w; `' U6 Q7 Gif (remainder who 5 = 3) [set k who9 R  W1 _6 U% g5 d
                          set x( Wid / 2)  5 A" ^0 Q1 a9 y
                          set y (0 - Dep / 2 ) ]7 R3 `6 N7 r2 v9 }
                          set f int (k / 5) * 57 W1 z6 z" ?6 C$ _  t5 F
  setxy   ( xcor-of turtle f + x )8 |2 b/ I6 k) f  h* w5 k3 l
           (ycor-of turtle f + y )
$ b) i5 K$ L) E5 k' Y1 u           
- w9 W3 \# k3 d           
' K! B& @2 S$ w# lif (remainder who 5 = 4) [set g who
# N- J  U1 Z- j$ P4 i* [+ b+ h                          set x Wid / 2
2 |+ {+ O! L6 r                          set y  Dep / 2 ]
+ V5 A: ^; h# q4 h/ Q                          set h  int (g / 5) * 5* }0 l1 V9 F, d) f$ {" g( G  t* W
  setxy   ( xcor-of turtle h + x )
% V  u/ N/ @& W! @- X           (ycor-of turtle h + y )
8 y9 o; }9 N+ K  s                          
. z  T0 L5 u( |) L- q, i                          
% J" u- c* p0 K" F& q                          ]8 l& J: f6 K  i" I& \& F2 N
end: s2 O$ r4 @/ n
+ E1 f& W' b/ @! }  {( K
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
* I, v* F6 ~" F  U& _1 n+ I8 T应该是
" i: M9 D& x- z# Y8 pask turtles [
2 `9 L0 e( n) y! Y* I3 }if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
7 `4 U; ~2 ^8 z+ @: C                          set y  Dep / 2
! x" ?% l: ~( _, ~  p. H" U           set b  int (who / 5) * 5
' R6 V; Q/ i1 L: P( i$ w    setxy ( xcor-of turtle b + x )
9 a  P/ B7 `! @. |7 z6 K          ( ycor-of turtle b + y )]]
' C4 b  O  Y, v+ \end
7 F* w5 E  T8 @! ?5 C$ A之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-11 15:31 , Processed in 0.016869 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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