设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6773|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
6 H( u$ ~6 s, w% E
1 G0 S% a) H* w$ S但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
0 R9 W5 i- [: o  B8 \- f- L2 w+ M4 J1 s! K0 }
turtles-own [a b c d k f g h% m0 g% p8 @- M7 _
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 4 a& P4 l3 y" G, u% E1 `
]
* n* v" G- @$ [' V0 [5 [to new
" B  w& @- `* k% c: x  ca
5 x' {# y$ v) T  crt 5 * num_of_building
. N4 ], `6 T: c+ e  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]; s; |+ Q0 }: A- \$ e* y7 f
  scatter     ;;keep center-turtle random positions
- @: D2 w) Z# u1 F  unit_plan   ;;make up the building plan
! J! Q8 c% D& T$ send
% v* O/ m0 H8 W: Bto scatter+ f) I' U8 p7 b1 Q
ask turtles with [remainder who 5 = 0]
% R: `; a3 i3 F7 I' ?[
3 [( C) }$ x; U% L4 g: u9 {set xcor xcor - 6 + random-float 15& A7 e. T6 n5 C
set ycor ycor - 6 + random-float 156 v8 e3 i% v' i
]
6 O1 P. Q; l& ^' |end! w+ {6 @5 F/ a
to unit_plan / V% I: q% f3 q7 [( j' I+ W
ask turtles [
( k' L9 ?# Y- T% M8 Uif (remainder who 5 = 1) [set a who ( v, ~" N  V) r  ~9 e/ [
                          set x ( 0 - Wid / 2 ) 7 m1 X" n# _7 d+ j3 C9 E
                          set y  Dep / 2 ]
, c; h$ Y5 C% E           set b  int (a / 5) * 5$ g0 S9 y/ |7 U: ]  ?
    setxy ( xcor-of turtle b + x )% v; B" X! y# ?& X3 ^' }& S9 s
          ( ycor-of turtle b + y )0 {1 @9 X/ m( O. w5 _
if (remainder who 5 = 2) [set c who
9 T* d+ Z8 w+ x( ~" B: s                          set x ( 0 - Wid / 2 )
# q- K3 ^5 [9 C                          set y (0 - Dep / 2 )  ]
3 \  @0 U$ h3 k4 C0 H                          set d int (c / 5) * 5
/ G3 `4 ]& x$ h$ Z1 R   setxy   ( xcor-of turtle d + x )
# [8 o  {( B  d, M* u/ B% X8 d; q           (ycor-of turtle d + y )
3 G2 K: ]: M. k4 a3 `" l5 B3 g          ' |- L" _$ P/ W5 R
            
: W6 X, H; s3 ]4 ]% B: R; p% E, ^if (remainder who 5 = 3) [set k who' w' Q1 d1 H! m1 w+ l
                          set x( Wid / 2)  
) F$ n6 |6 k+ X7 t                          set y (0 - Dep / 2 ) ]
8 D7 z8 V4 h. f9 S: h: l                          set f int (k / 5) * 5
6 i* Z( B. Y; ~( y9 Z9 j0 v  setxy   ( xcor-of turtle f + x )5 [, f+ F" Y; h1 Q2 t9 |; Y4 G
           (ycor-of turtle f + y ) 6 E. Q' [4 [3 E2 _# _. F
           3 C8 x8 e  i) `- D: O! s6 Y  n
           
+ f, w  y1 n. U' `if (remainder who 5 = 4) [set g who
! R0 t- k) }/ T$ d+ ~" P                          set x Wid / 2
1 a) h6 g& o. j5 k7 I                          set y  Dep / 2 ]/ R" ]3 C& i8 I% x. {. Y
                          set h  int (g / 5) * 5  |9 I* V5 K/ ?: L) k6 b$ p3 J# V4 Z
  setxy   ( xcor-of turtle h + x )
6 |* y8 P; E+ P4 L# z  U* X, a+ y" O) ^           (ycor-of turtle h + y ) $ `; X: g; @7 Q" }3 I: b
                          1 u; a. ^) |6 I
                          , x6 {' g( T3 {3 J5 P
                          ]
' V8 o' o( s: m5 [end
- Q8 o. `2 D5 I; A% O+ g- a1 S  f* q& V, H# J/ ?- j4 U7 j
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,* ^$ E* r9 X" K( B
应该是" L* [! _0 z( ?1 i) y% X7 i
ask turtles [# @9 M" a9 D0 m3 C6 i6 Q' B
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
8 ]% _# i6 X$ l, }8 K                          set y  Dep / 2
% o7 ^; i- w! x5 h           set b  int (who / 5) * 53 N5 h: c/ W$ ?' g
    setxy ( xcor-of turtle b + x )% T" d; x1 x, S
          ( ycor-of turtle b + y )]]
' v, f8 z9 \4 \& W& Oend
1 Y7 `: S3 L% O: g( w之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-22 06:46 , Processed in 0.018565 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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