设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8095|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。# a* c. J2 s1 |
1 [& T" W: x' F( y  z
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
. \) H, Q" f% C# K& }6 v+ Y+ E& a! k9 Y9 M# v
turtles-own [a b c d k f g h
; f2 @6 o5 s; T* Q8 v+ I  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ( {2 t5 a, p- i
]% @" K% y/ t/ d+ H& r7 F/ u& c  v
to new
, v! p& f4 ^' _8 F( K" g3 B0 {  ca4 p2 e5 d9 M  d, N- E  L8 e8 y9 d
  crt 5 * num_of_building
8 k  r- L, W; f. T9 \  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]" E+ y# O% j6 n0 b: I
  scatter     ;;keep center-turtle random positions
9 y/ v; K5 [% J0 O* ]1 Y; V0 `  unit_plan   ;;make up the building plan
( @* T+ G+ H1 ]' ]6 U& Pend
; @1 N* a1 ]% I4 V& @! xto scatter9 S- v$ X6 V# b9 V6 i
ask turtles with [remainder who 5 = 0]
# V# g/ o* I& u& ?5 x[: a' J6 v6 @/ S3 E" T( {
set xcor xcor - 6 + random-float 15  O5 X, c8 Q* r0 Y$ ^- n
set ycor ycor - 6 + random-float 15
9 \- M  B' Z7 \' l]
* C# s4 o3 D' ?0 W4 qend
+ o" H& ?1 E* h/ g; Sto unit_plan
' h. H' o" W( p, @3 g: X2 cask turtles [5 `# H/ h+ i$ j/ P- P
if (remainder who 5 = 1) [set a who " |, T0 `7 f9 ?0 [5 _
                          set x ( 0 - Wid / 2 ) ; M" n) z2 ]/ E/ c0 |+ O
                          set y  Dep / 2 ]' [/ Q1 C) ?: ]  y
           set b  int (a / 5) * 5: F7 I3 G  w- u; f4 `  v$ X
    setxy ( xcor-of turtle b + x )
* }' X% `+ K7 h; O% I; L, l          ( ycor-of turtle b + y )
1 x% s# B5 g; ?: A4 t$ |( tif (remainder who 5 = 2) [set c who. ?$ i8 r( i# a
                          set x ( 0 - Wid / 2 ) 6 t3 U) r! b" c7 E0 s  ]6 d3 @7 C
                          set y (0 - Dep / 2 )  ]5 S: k; C; ?5 [
                          set d int (c / 5) * 5
3 B3 j$ \* T1 }( L% f' Z, c8 d3 j& ^   setxy   ( xcor-of turtle d + x )7 ], C$ p( q  b' u
           (ycor-of turtle d + y ) # e, g7 M# ?: ^8 y
         
# ^: w' ~9 _( ]. T0 j$ ~; O  B            : w: R7 G% y+ g  @3 _. N* q3 O/ I* o
if (remainder who 5 = 3) [set k who
% O  h+ Q4 U' O& z                          set x( Wid / 2)  
, @' l0 b7 F" h" Z1 x. j) X7 i' j& s                          set y (0 - Dep / 2 ) ]
( r$ f$ @; S- @- Z" S4 p6 ]                          set f int (k / 5) * 5- U9 K+ Y/ k# R( ^& |% j0 U, C
  setxy   ( xcor-of turtle f + x )8 q1 f* \) x" B6 D4 Q5 p( n
           (ycor-of turtle f + y )
! o' P0 C* L  e: L           
: q. O' B8 P; |9 h- ], r+ T+ ~, |. B           * @( O* V/ m5 D4 ?
if (remainder who 5 = 4) [set g who* |3 q! U$ n; j
                          set x Wid / 2
, Z: P8 V. }+ Z8 q                          set y  Dep / 2 ]% p5 a! ?" V0 t7 H8 `" e/ L$ n
                          set h  int (g / 5) * 5
1 t  c/ F2 E2 A6 f7 l  setxy   ( xcor-of turtle h + x )2 v" ^& G5 z4 y# Q9 S7 w6 m9 u
           (ycor-of turtle h + y )
% b1 Z. I* m& b5 E                          6 c/ s0 b2 W  V
                          + r8 v! T% c+ z% R* |1 x* C2 m& g) z* ^
                          ]
; [3 B' u. b% ^( s/ ?& [) `end  f1 H- N8 n0 c! I
- X3 O; t6 Q4 E# @" z, \
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
: `% B0 v) C2 j9 k# R) K1 |0 r应该是  f- ^5 e: h" d0 o$ p: w4 g7 y8 x
ask turtles [
  Y0 e1 Z, j4 A% k4 Eif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
# c3 V8 I7 ^* U5 a4 x                          set y  Dep / 2 3 v) y& C& K# h* D4 P3 ~
           set b  int (who / 5) * 5
( L; z# u- {3 K# t0 A    setxy ( xcor-of turtle b + x )4 \  [/ G" Y# e% K2 }4 G
          ( ycor-of turtle b + y )]]
: d! O, q- X$ Send- `) G3 v( _# n. |) p2 P! v/ Z
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-7 12:11 , Processed in 0.019293 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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