设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8156|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。7 z1 u  t' H# f+ f9 @
% S! r% I! Q) E/ w# {, s
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
  S4 _3 j5 C0 h2 b6 l/ Q5 ?0 d' o3 t1 Q3 C( J, e
turtles-own [a b c d k f g h  r! s- e- ^/ ^. d- x" {% R
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
$ |; T) y0 X0 \" R+ r; V]
- L+ P0 N5 I5 e3 {. gto new( C7 Z: M9 F1 U4 g+ w
  ca: \) ?' x- J, E1 ^$ X1 Q
  crt 5 * num_of_building3 R$ {  q6 c2 r+ r# k
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
/ [: G* V: j8 ^  scatter     ;;keep center-turtle random positions 8 c" r8 v- f8 f* Q& b' }
  unit_plan   ;;make up the building plan
. c0 z2 W4 K0 ~; |end
& I# |2 h$ V. a; e- _9 bto scatter: a" B# t+ l  y, e
ask turtles with [remainder who 5 = 0]7 [2 Z6 L1 w7 N6 m& l! c
[
3 l; T0 Z) `% ~set xcor xcor - 6 + random-float 15
- N, V: }% }2 Y! a/ y7 Dset ycor ycor - 6 + random-float 15
1 i4 e: n+ ^0 d( Q' H9 m; L( T/ `% d]
9 I! a; K7 h6 `( a, Mend' T2 |7 u( F3 r
to unit_plan * S$ D! b4 z4 L+ U' p& p# N
ask turtles [
6 w* f, I! F+ v, p: fif (remainder who 5 = 1) [set a who
' C. P4 P. ^. V$ U& A1 O                          set x ( 0 - Wid / 2 ) 0 a. |2 @' d  ]4 P/ H
                          set y  Dep / 2 ]
$ x' a' K  h/ j1 Y) f3 O1 W- {           set b  int (a / 5) * 5
1 H+ X* x( `- Z7 L0 S    setxy ( xcor-of turtle b + x )$ a& k5 V2 k. @
          ( ycor-of turtle b + y ), b' a  a' `8 o5 X4 M) h3 D6 k
if (remainder who 5 = 2) [set c who
% ^- z* E7 g8 |0 z; }. e( A4 g3 K                          set x ( 0 - Wid / 2 ) : A9 W+ P7 M. `7 e% v0 l
                          set y (0 - Dep / 2 )  ]
* n/ z! M) X( z+ S/ M' f                          set d int (c / 5) * 5
4 B2 G# @3 |( I7 w$ P   setxy   ( xcor-of turtle d + x )8 u: S6 w+ o! @* t: p$ D1 x
           (ycor-of turtle d + y )
- M4 M, H* v3 Y& m          ' R% U; E- F* ]# P, E$ `
            
4 o) s! `/ |/ p# d" Xif (remainder who 5 = 3) [set k who: ]8 b# B% y; M! R
                          set x( Wid / 2)  
7 Q: z# K7 O! ~5 o! s; J& F* W4 [                          set y (0 - Dep / 2 ) ]
- a4 L0 z: n; u' ?" @; Z2 w                          set f int (k / 5) * 5$ Z& I" T, P0 [% g
  setxy   ( xcor-of turtle f + x )2 H5 L% _; a7 ]" a; Q- z+ x
           (ycor-of turtle f + y ) . H. o/ m: v  S; U* @
           
6 P+ z% ]+ [! C           
6 {( A/ L! y5 @3 o: E4 }9 oif (remainder who 5 = 4) [set g who
8 Y+ y. p. z( r. s8 H& k" u( F                          set x Wid / 2
& ?4 c+ L8 ?8 `- J6 U                          set y  Dep / 2 ]" w, D5 t& q/ N2 _2 r
                          set h  int (g / 5) * 5: m3 @  O! g' K9 O' `6 R
  setxy   ( xcor-of turtle h + x ): x( q" x3 M; g
           (ycor-of turtle h + y )
) g1 f/ O4 V( D5 c                          3 `' P$ s) Y. _
                          
" v+ A" D6 c8 S# {, X' r- y# v                          ]
; o3 W& Z5 m: _, v  A7 jend
3 I; a; Q3 b# r0 }$ Y+ @, v7 F/ o! M5 \! L! f. _
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
, U; O2 J9 s1 N+ N( ^- m! e应该是
1 Y# U& C8 h  _5 e# Qask turtles [
1 `) C; Z9 M7 ?* bif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 9 @! J% ~5 s- q
                          set y  Dep / 2
7 M$ {; N5 h9 T5 I& v           set b  int (who / 5) * 5* e+ E* i9 ]' j4 E
    setxy ( xcor-of turtle b + x )' L& N6 I6 C. [0 v$ T  w1 X. w# a
          ( ycor-of turtle b + y )]]. K! F' G5 G8 Q" M  x, `. A3 Q
end
$ X% E' |8 }6 ?9 K8 m6 z之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-12 12:03 , Processed in 0.019025 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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