设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7201|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
. H& m/ J, L8 c' O& P8 }  o8 f+ F" R2 x, k0 @
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
( E9 K3 _3 V; {* J+ t. C: _: g; a) m" e" k2 |
turtles-own [a b c d k f g h2 n( E: T  c: Q4 w
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
9 V+ x3 a6 N3 A( L  m0 H( V! n]% D. V( U) n0 {' b$ y4 Y
to new5 W7 ^/ l0 E$ E# M+ H0 h  |9 M
  ca
* o( ~! ^9 b! e  crt 5 * num_of_building
4 }+ \. u  q5 Y  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
8 b$ E' t1 \% b. w% u  scatter     ;;keep center-turtle random positions & s1 @2 w& c: \/ |( M4 t, w
  unit_plan   ;;make up the building plan7 H: w' {' r9 N  L3 C- {
end( ]. _4 i5 S% }% N7 K  d9 D
to scatter: a* I- x/ ]2 K6 e
ask turtles with [remainder who 5 = 0]+ I/ X. y) D% J# r# i
[
6 ~9 |+ [' B4 w$ s5 O' S7 ~3 {set xcor xcor - 6 + random-float 15
. S0 s  n! z3 t0 Q3 H3 v7 M- xset ycor ycor - 6 + random-float 15
& g! n) V/ ?9 V* u$ X]) `2 c- e+ _% x0 p1 ]* K+ W
end
# i1 L4 Y* G3 c6 X0 \to unit_plan
7 c# ^, n7 A. t" Y' z+ `ask turtles [
$ U9 C8 E/ e$ wif (remainder who 5 = 1) [set a who
2 D0 n$ n! R- M! y2 Z                          set x ( 0 - Wid / 2 ) + w9 H; q5 F6 R8 d& e( h) X
                          set y  Dep / 2 ]
4 L- D) c' z+ V' S  f6 ~           set b  int (a / 5) * 5' L# v2 K% u% G
    setxy ( xcor-of turtle b + x )
* J7 e  Z8 w8 a1 b6 b2 ]6 P( n& x: ^4 p          ( ycor-of turtle b + y ); B1 s. M8 g* h
if (remainder who 5 = 2) [set c who
. [' C) w- W( t) k2 O( L                          set x ( 0 - Wid / 2 ) ! d6 o" z0 C0 b. l# w  S
                          set y (0 - Dep / 2 )  ]* c! ^9 a$ u' g+ ]+ V# `3 ?$ {
                          set d int (c / 5) * 53 R- g+ o% `6 S" w1 y6 X5 l2 W
   setxy   ( xcor-of turtle d + x )/ q9 j& f6 A8 j5 y% Y0 h5 y
           (ycor-of turtle d + y )
2 K3 a* u" q" _. E7 J4 w         
/ H+ Y; n$ z# }9 Y) m            4 W6 N# v! T5 u' x7 Q) p7 T
if (remainder who 5 = 3) [set k who& e& L+ X+ V1 D, _( R
                          set x( Wid / 2)  1 w3 f, }/ `1 _; t; \1 z
                          set y (0 - Dep / 2 ) ]
/ b& V, z$ o6 J" e0 ~7 S8 y! R1 N                          set f int (k / 5) * 5
4 l* f& \+ q: f/ x, k+ I2 s  setxy   ( xcor-of turtle f + x )0 U5 s# Y) t- N8 p( W; U2 B
           (ycor-of turtle f + y )
* H2 C$ n8 W7 K5 L& {           + Z: z8 H( W6 v
           
5 `8 x: \& x  [/ ]4 k$ F/ ]if (remainder who 5 = 4) [set g who& |; l6 r$ s2 ]! P0 ~
                          set x Wid / 2
2 i# Y% [* T* E  C, H                          set y  Dep / 2 ]0 U1 Q/ N9 o/ U
                          set h  int (g / 5) * 5
6 X4 F1 g( C" h7 h, `  setxy   ( xcor-of turtle h + x )
4 V, n4 t. x% x7 s* r# Q& k           (ycor-of turtle h + y )
2 S: Q- Y: U6 L                          
; Y6 g  h8 {' i& }1 R; w                          , I% R! c7 \0 }6 N% X
                          ]
' H( O: a' x& ]$ _2 q' p! eend
$ o  f) e9 O+ W4 _$ G" d
/ P2 V1 A# N4 e4 Y/ ^  o[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
0 l/ H9 g1 k1 m( E8 M6 p应该是
* h/ p- e- c; d" G4 T0 E) \+ eask turtles [
, i. ~# j+ P0 [8 {8 l0 uif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
. k6 a) s# y+ I1 ?4 g5 ]* L  q4 S                          set y  Dep / 2 0 N. |4 m5 ~* w4 l
           set b  int (who / 5) * 5+ I9 ^/ L( I7 c, `4 ~) y
    setxy ( xcor-of turtle b + x )' r% I" I, H" Y+ N. S
          ( ycor-of turtle b + y )]]7 H6 h: s+ `% ?: w
end
" d5 I: J' K/ F6 A$ t  s0 v之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-16 05:00 , Processed in 0.018546 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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