设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8878|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
  Q( ?. Y' l" T, e/ e0 g/ B0 @2 k# K) i" p9 m
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。  B/ Z/ K" q. p# ~( G
0 f8 Q* T$ d" q  a+ F( |8 a
turtles-own [a b c d k f g h
8 E: `# ^7 Q- A  x y     ;; these are the leaf-turtle's offsets relative to center-turtle . u- T7 c8 |( f- y
]
( W$ D  j' _, f$ c, e* y* c" Tto new- r0 f9 t0 U' d2 ~: `
  ca, }  E. m4 G) i; C
  crt 5 * num_of_building4 o4 D& c9 |! t9 h. d- Q
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
6 ]/ Z; m) k1 \6 F9 B  {$ y# }  scatter     ;;keep center-turtle random positions
$ {- |6 z7 x+ H2 A3 p! G  unit_plan   ;;make up the building plan( L' O& e0 g5 B+ s1 r8 P  g
end& ]- d' J6 E2 {, W, ?: H
to scatter
# E5 G5 ]& t: B& K; u2 u; Bask turtles with [remainder who 5 = 0]% x  U4 O8 _, R0 l
[
: a4 e1 y: L; _/ {$ t# uset xcor xcor - 6 + random-float 15
6 ~. C. _& l: W' W# @, K$ n/ Rset ycor ycor - 6 + random-float 15
8 |3 Z; I. e# P" [5 o/ O; M/ i5 `' y]
) n5 o) J& w' W( w4 @7 Fend' k8 A  z, Q- u- J
to unit_plan " ~) Q( g; I, `- I) C* C
ask turtles [
$ g+ I1 Z2 i- W& `  y" k% dif (remainder who 5 = 1) [set a who - a3 F1 c( o. M* F. e9 J
                          set x ( 0 - Wid / 2 ) 9 i; o( b) V' \9 L; s; I
                          set y  Dep / 2 ]  o, d7 [% K; S( h/ l' B) @$ a
           set b  int (a / 5) * 5
9 K* i8 S  C. J) S3 @" u    setxy ( xcor-of turtle b + x )
0 s* x3 F: ~5 N% `# h- \          ( ycor-of turtle b + y )+ |1 v9 N/ w$ J% u9 s; K9 ~/ `8 _
if (remainder who 5 = 2) [set c who
* u2 t& O' `) u" A  w/ K  q                          set x ( 0 - Wid / 2 ) 3 d" c  [$ ]' `( d  k
                          set y (0 - Dep / 2 )  ]
5 J5 A* K. _+ E+ g* t7 `$ D. t                          set d int (c / 5) * 5
7 O, l7 G- A; D* a8 B/ c* q! z   setxy   ( xcor-of turtle d + x )
* A+ e6 d/ h9 s           (ycor-of turtle d + y )
  @9 r: C+ W1 Z$ L" K" c9 P$ a+ q8 b          * E# y3 ~* d6 R( @) @
            
' S0 x, t9 B! w  W' b' l; g! |if (remainder who 5 = 3) [set k who2 i4 c  w( a* W5 }6 R& v; m! z
                          set x( Wid / 2)  ; ~4 _0 @7 V! \' B% u" U' Q
                          set y (0 - Dep / 2 ) ]" t8 f8 c1 O& ^% k/ [
                          set f int (k / 5) * 55 O+ e) D# s2 j' L1 Y2 {1 {
  setxy   ( xcor-of turtle f + x )$ f$ [' f. r! ^
           (ycor-of turtle f + y )
" J. |* Q- O2 s+ N           / X- k' J( E! f+ w8 ~. G2 I% @
           
  M1 U! e& [& ~* v6 ?: H( nif (remainder who 5 = 4) [set g who
  i* p" U1 x; a. P  `3 q                          set x Wid / 2
' v* h" @7 p8 A9 z4 _                          set y  Dep / 2 ], P8 @9 t4 L" p4 A
                          set h  int (g / 5) * 5, t9 ?, o+ j7 J! p7 n0 O
  setxy   ( xcor-of turtle h + x )
" K: r& N0 s# R3 u+ h# j           (ycor-of turtle h + y ) * G$ B  o, F0 w
                          3 I2 y; k+ j2 W. b' u
                          
9 |, V% {" ~; o                          ]
( j: i+ I" \& X0 ~end& y& n( p$ F2 p" Q0 m; g/ o

" v/ \. _" |/ s3 T[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
+ [& c2 k% q! ^/ `* ^: R. Z* B应该是6 j7 c3 N6 s$ C, j. Y: b; A/ e+ ]2 A
ask turtles [
3 l. u( R& G* c/ ~0 D4 dif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 3 K* Z: @. I$ d% G8 R2 ]4 g2 {* b3 }
                          set y  Dep / 2 1 ^5 z: }5 E: `4 @0 O$ ^( |: P+ v
           set b  int (who / 5) * 56 w3 f2 f) e0 v2 m% G! A4 M* c
    setxy ( xcor-of turtle b + x )  v: ]3 i1 Z( X, j. W
          ( ycor-of turtle b + y )]]) T0 Z6 p/ ^9 q; U) [1 t  K
end* {) p& y! ^5 Y! V! W0 k4 \, x
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-15 14:18 , Processed in 0.025394 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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