设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7630|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。' a% K4 R3 l' ~. w: e: R5 |

' k6 T" k0 K# s; a0 K6 ^但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
/ m$ ~2 d9 ?5 V( c( J! z& C8 k
; S8 @. _% r* gturtles-own [a b c d k f g h
2 U, G8 U+ g0 _  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 7 E* v) ?: S& C
]+ G, s: _9 Q: H  w( E/ w
to new- E* Y1 ^5 C/ ?4 }. c- ]: o( B0 f
  ca: S' I% n3 i( V2 a
  crt 5 * num_of_building& Z9 {+ N7 w+ }0 h: c. U
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]8 S! _, T( s# Z( M
  scatter     ;;keep center-turtle random positions
' u; \" ^8 B, m/ Z$ C  unit_plan   ;;make up the building plan/ J3 \: d: U4 n- f/ w# }: |
end% t  X7 ^/ J' H& e
to scatter7 J" f7 c( p; E" z
ask turtles with [remainder who 5 = 0]2 u- r$ S( X4 y1 B% w; M' \
[
- T- y  h8 z8 _* f+ Bset xcor xcor - 6 + random-float 15
; E& E4 u% g' Y0 Y+ u/ `set ycor ycor - 6 + random-float 15
# B- C, w5 y- k  ^0 P( m]$ t0 d3 i+ m$ ]) N" b% s
end8 p1 L$ ?9 M* ?$ l, v! n, x
to unit_plan 5 _; e' \3 Z; @5 {/ W# c0 }
ask turtles [
6 b. R. T4 U: o* Eif (remainder who 5 = 1) [set a who 0 _) ^. o, y' n4 ~- A9 `  N9 K+ F
                          set x ( 0 - Wid / 2 ) ' c; I4 Q7 Y; p
                          set y  Dep / 2 ]7 _9 r* H1 n- F) C3 ~, s8 O
           set b  int (a / 5) * 5
/ D: A6 ^5 ~5 N' p    setxy ( xcor-of turtle b + x )
( i$ u/ }7 a# m' H/ o& V! U' R          ( ycor-of turtle b + y )
' `$ e* L1 s# j/ iif (remainder who 5 = 2) [set c who8 m& M1 U0 N, B# `
                          set x ( 0 - Wid / 2 )
- i( l: i3 n% j" G: i                          set y (0 - Dep / 2 )  ]
* n  e/ N9 T/ P# g; K/ _8 B                          set d int (c / 5) * 5# M$ G; h' ~- v( S! h& m
   setxy   ( xcor-of turtle d + x ): R- e' C0 ^3 g' \
           (ycor-of turtle d + y ) ; C8 @  h) s8 q! _6 p
          1 v1 H) b* \' l
            + Y0 u5 n0 q$ g% x* ^# z
if (remainder who 5 = 3) [set k who- p0 a2 q5 ?! P( f1 B9 w* I
                          set x( Wid / 2)  + d8 R$ E, A" g7 E( k
                          set y (0 - Dep / 2 ) ]# I! I' _$ l- v* v' `
                          set f int (k / 5) * 5
% t2 F' z0 W( ]  y  setxy   ( xcor-of turtle f + x )! I2 h* C- J. f* U0 f
           (ycor-of turtle f + y )
) m. s% [; O* w( h& _) t% L& V           
3 U: C" G2 h% q9 _           1 B4 K4 f: q- m! Y. c  o! d
if (remainder who 5 = 4) [set g who6 H% _6 c7 P' `. J% a0 H
                          set x Wid / 2
5 ^/ D. s1 I9 X5 p! R                          set y  Dep / 2 ]
  h% o' _. t+ @                          set h  int (g / 5) * 59 A: |' W& X' y% @0 H
  setxy   ( xcor-of turtle h + x )4 u! H5 N1 Y, m/ F& f% \
           (ycor-of turtle h + y )
4 F5 W9 N3 W. x( Y                          
/ U/ j' k% L( n                          9 w& b* B+ y4 ^  V6 s
                          ]
, j" a3 R+ {, o; F* S! gend8 i! K  {6 p. {& H9 _" _
7 ?% f, B9 @  }0 w5 L% @0 p
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
3 G, Q0 J9 V& d% L应该是
9 A! R3 G1 C  Nask turtles [
5 c- R1 I& a, L& J' vif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 3 r" V* E# ~7 l, _
                          set y  Dep / 2
% S+ y. M& M' ?2 L3 e1 E4 d           set b  int (who / 5) * 59 x* P- d1 d8 `2 j. u+ N
    setxy ( xcor-of turtle b + x ); V2 c# _3 Z+ j
          ( ycor-of turtle b + y )]]& [- c/ o6 ]; N5 x
end
" E9 G* s! B; i. B3 x之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-8 15:38 , Processed in 0.015352 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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