设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7413|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。& ?, w5 L8 t% r, T5 M3 w

3 H$ N$ [5 q  Y/ X1 M! N但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。, ]) r3 Z0 Z: K9 n( M5 W; w

" l5 `6 s- O' \; Z" A* W4 pturtles-own [a b c d k f g h% F; [8 J+ I& }7 ^% f
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 4 k& W* O/ P' S* N3 E! s  S0 r4 C5 t
], B, w/ @! j0 ?$ u! T
to new
- o- ]  m) S+ O7 ~7 t3 n7 O; e  ca
0 {$ ^$ ]3 Y4 S  crt 5 * num_of_building+ g: H, z4 ^9 t
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]$ i* @/ q4 W: W2 ?
  scatter     ;;keep center-turtle random positions
* M7 {* T1 f* x! S0 `" }  unit_plan   ;;make up the building plan
/ Q$ [/ U" W* V5 [0 E" s: Gend
. G3 ~, [1 Z9 H5 L& j7 v. Fto scatter7 z/ j: h; M7 m( z" V8 `
ask turtles with [remainder who 5 = 0]
( v* B3 }% W- E, o8 D: G+ v[5 L7 @# L9 j8 |0 q7 F
set xcor xcor - 6 + random-float 15
' x" _( W) Z1 C7 y) u/ ]9 o$ Sset ycor ycor - 6 + random-float 158 e' l: ^! Y5 K  t: E2 ?
]
! ~0 G( o8 J8 aend7 Q3 _# d2 L+ W5 q
to unit_plan / l# e: k) r7 s; j4 y! y
ask turtles [! S3 n; C3 ?1 V  \5 {0 d
if (remainder who 5 = 1) [set a who + {& s& i+ m! n; y2 `
                          set x ( 0 - Wid / 2 )
8 E1 x6 b: o3 ^% B! S                          set y  Dep / 2 ]
+ U  S  F! g+ y6 S: |, M# Z           set b  int (a / 5) * 5
3 @8 B" C4 i8 i) j6 }# W    setxy ( xcor-of turtle b + x )
' Z7 I# J4 ?9 P) Y          ( ycor-of turtle b + y )
7 N- ?" f' s( b7 Q1 q9 Oif (remainder who 5 = 2) [set c who0 y5 G1 Y! g1 m$ i, z2 Q
                          set x ( 0 - Wid / 2 )
0 o( f* k$ y# {, _0 f                          set y (0 - Dep / 2 )  ]
: w( A3 Q! o4 v; v5 [" b7 }) B$ Y                          set d int (c / 5) * 5
4 x% T( ?7 Y( t& ~   setxy   ( xcor-of turtle d + x ): n) b( D/ A+ l) Z2 m; B
           (ycor-of turtle d + y )
" X. O6 L1 n" Y  f         
, s+ {3 j$ O9 p% M# Z            / f: q  n$ W& N% Z2 x+ ^
if (remainder who 5 = 3) [set k who& R) w+ k6 `7 ~
                          set x( Wid / 2)  
2 W8 x$ p* s. p) ^+ n6 t2 o                          set y (0 - Dep / 2 ) ]
( c8 y  E' O5 s! d                          set f int (k / 5) * 5
- C0 W: {3 V' @: L' ~  setxy   ( xcor-of turtle f + x )
2 w; z( n$ I% S  `4 l0 Y           (ycor-of turtle f + y ) 8 u& `( X$ D7 M/ `% h9 l% f
           ( E7 N. d! i" ~# y: b+ X1 p& `0 H  X
           3 ~' {1 d! `, X% ^$ F
if (remainder who 5 = 4) [set g who" O0 w  i6 g3 g% ^3 Q
                          set x Wid / 2
$ [8 X- M( G" O7 H                          set y  Dep / 2 ]9 [  l) g8 ^( N/ p0 g
                          set h  int (g / 5) * 5, x4 w1 h0 x6 f
  setxy   ( xcor-of turtle h + x )/ r) w8 l8 s6 h
           (ycor-of turtle h + y ) 8 S$ j5 Z) r3 K1 \, F4 N5 x8 p# _
                          ; G$ s. D9 u, ~# F
                          ; E* M) a5 d; {, H8 F/ u" {
                          ]
9 ]1 Z" {/ N$ y- M% Oend# P6 R9 j9 D- o8 k: {7 |
4 m, U. S4 m8 x" Z6 e6 k
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,/ K+ q$ M5 ~) C1 ~" C: B! J
应该是
- z" M) J, e; Iask turtles [/ D; F$ A$ {# C* j! f* N5 A
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
5 }* u& D( S5 T8 U2 ~$ x7 {8 x6 X2 y                          set y  Dep / 2 * F! m  @' B) [% z
           set b  int (who / 5) * 5
1 f' X# q3 `4 Y& S/ h" o6 T    setxy ( xcor-of turtle b + x )
! x" g, U0 i7 a8 r! V; f1 `          ( ycor-of turtle b + y )]]$ _4 o; m" y6 |, z! m
end
3 Y1 U; G, D3 q$ M$ t, S& I之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-9 08:04 , Processed in 0.019414 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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