设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8510|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
0 k$ F; H+ T) y
2 Z* B' B1 h% I  h6 {7 O5 m' u. f但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
6 y5 ]+ W% U8 v  _5 a7 _: v* c2 O2 z3 q
turtles-own [a b c d k f g h
6 a3 N' m5 u, B4 D  }0 ~0 F4 N/ e  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
) T, D% \% `! r7 V7 U]1 P/ n: A) v( a" v4 P% M
to new
* P8 w. S. C" G% }* ?$ G  ca
2 q  }5 l, a- y; |% P' R% S1 }  crt 5 * num_of_building
1 Z: i5 ?/ v' M2 m7 }9 ?, m$ B. S  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]4 `/ j0 f7 V! |6 E, O
  scatter     ;;keep center-turtle random positions
3 _: o# Y( D4 j, n  unit_plan   ;;make up the building plan
1 E" p8 t- s# J8 {- J6 jend
! z$ G0 ]+ z( v' W- O. Xto scatter* y' p# a9 A  }5 M# N
ask turtles with [remainder who 5 = 0]0 g. E0 M# O9 w( W+ R
[
" C7 `$ w7 L% B( T9 Iset xcor xcor - 6 + random-float 15
, D2 \7 d/ Y' n8 mset ycor ycor - 6 + random-float 151 i, J! n7 f! [6 L
]: j3 n3 K; ]: r: H
end
% H. R& P8 }. e3 F+ d  Xto unit_plan 2 \/ X% h2 u, m, \
ask turtles [9 Z1 t' g* Z. W* F7 Z
if (remainder who 5 = 1) [set a who ( W8 w% w  Q4 o# z/ r
                          set x ( 0 - Wid / 2 )
; R% v- h$ s( _  `8 q+ Z( K                          set y  Dep / 2 ]% F3 |8 N# e* F# E) e
           set b  int (a / 5) * 5: X8 t. I2 i' B' k$ Z
    setxy ( xcor-of turtle b + x )/ G3 l" U! O& \/ s, P" [2 ~
          ( ycor-of turtle b + y )9 q  A' X4 o5 f4 @! X
if (remainder who 5 = 2) [set c who7 \  _5 C  `2 ^! z. M# l0 o
                          set x ( 0 - Wid / 2 )
8 T% }; a8 u: l5 ~# }# J                          set y (0 - Dep / 2 )  ]$ ?. P! }4 \4 f1 M# z
                          set d int (c / 5) * 5: E# h" k$ f& |$ g" H/ v
   setxy   ( xcor-of turtle d + x )& L- P3 [2 M* o6 h9 B
           (ycor-of turtle d + y ) 4 @1 ?9 m- N" E; ^
         
* V2 v& C1 V7 h7 B8 l5 m) Q            
- s. p$ v4 s+ J! k8 ^* h1 p, nif (remainder who 5 = 3) [set k who. x, b0 R  k, ^  h
                          set x( Wid / 2)  
. a8 c- l# P# G- ], Y3 F                          set y (0 - Dep / 2 ) ]' m" l) d; v' ^% G. A$ X0 x
                          set f int (k / 5) * 5( ]1 i& Z$ S' S3 D1 Y
  setxy   ( xcor-of turtle f + x )% p: n6 s! D  [( l, l
           (ycor-of turtle f + y )
# o9 B0 {- X( B' Z, s           
4 }1 I0 r# u! p8 N% i/ _           + t) q/ U, \% A2 w
if (remainder who 5 = 4) [set g who% I. A/ A( [/ V; {/ V" ^
                          set x Wid / 2 3 X1 Y3 N* V# l3 N$ n, x- C  M
                          set y  Dep / 2 ]6 N' Z  ?) C9 K9 d% o- l9 O+ B
                          set h  int (g / 5) * 5
7 G. L. O  C5 e0 X9 B) Y  setxy   ( xcor-of turtle h + x )! b0 c' m$ {+ h, k# Y+ \
           (ycor-of turtle h + y ) ; Z+ j% O6 I0 ~% @
                          % r$ I% r. f, w6 t
                          
% \& g. `3 U+ O! ]: |8 y                          ]
8 s2 i' R% O' [) ^% Nend' }% Z) a. w# V& g+ Y0 p
( s8 s, h0 p, l, v0 O7 M  g
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
8 ]9 c% i1 \# J/ u0 y应该是
$ z: T& f8 x" f) Z0 D. dask turtles [
/ T6 L/ L) g9 b( r- q& B) i8 qif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ) i0 F! M2 w3 L2 A3 Y& h
                          set y  Dep / 2
5 d( s5 m8 G" `) q; i           set b  int (who / 5) * 5
/ _2 L' r/ q( i  ~0 ?, o- L    setxy ( xcor-of turtle b + x )) t) V: K2 k( T% X, B
          ( ycor-of turtle b + y )]]4 s3 @; c: E  \7 M8 x! q
end9 d3 M9 S# y6 F+ q
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-8 05:30 , Processed in 0.014588 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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