设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8353|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。" h" G6 [* E$ ]8 s3 `0 p

" V- f+ J7 j4 j但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。9 Q" S' c- |5 ~/ V# z
5 b  y8 o) x$ J: f4 q, F% V9 G: N; D
turtles-own [a b c d k f g h
1 k- ]. ~. r; C6 G  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 2 _8 o* S# z+ t) T1 G
]( R. ~3 Z3 a, O8 K
to new( M. C* O0 J; v* C* Q* t
  ca/ f6 l* O+ Y: t8 v* w6 t9 M$ B
  crt 5 * num_of_building$ ^( F6 G( R* f
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]3 g: W( S. h/ Q+ T( p6 ?3 J
  scatter     ;;keep center-turtle random positions
  W+ Q/ \1 Q8 ]4 s  unit_plan   ;;make up the building plan' ^# z- M* c% O5 L, @9 p
end" \" M7 n% A5 \9 e4 E
to scatter' H8 c$ R' X  K' B6 P
ask turtles with [remainder who 5 = 0]/ |2 \7 g6 K$ d% y" Z
[
8 n- a' A2 j* Y! f& jset xcor xcor - 6 + random-float 158 q& m* c: o) R4 M! h
set ycor ycor - 6 + random-float 15
* s3 L2 M* ?3 @5 y1 m; [# s, c]% N7 Z# i' t6 \
end, r. K/ Q% S; @; S3 J
to unit_plan 0 H3 ?7 _' F  |7 x8 O0 n$ Q
ask turtles [
6 j9 m  Y0 m/ Q. \( G3 W. zif (remainder who 5 = 1) [set a who # O/ n; x( x# P% o! @- w
                          set x ( 0 - Wid / 2 )
8 I/ L: v) m* q7 ?' U0 R                          set y  Dep / 2 ]
; l# G+ D5 p% h( W           set b  int (a / 5) * 51 z0 T7 F, c& i% Z2 _' ]+ B
    setxy ( xcor-of turtle b + x )/ U9 @  O% K$ c# a% x4 @
          ( ycor-of turtle b + y )
: P" T2 s, Y7 B# t6 f% p9 V' Y- ?' Q3 Dif (remainder who 5 = 2) [set c who: ?$ I0 D9 O: ~/ Q9 M
                          set x ( 0 - Wid / 2 )
  e% m4 A% H. u; x                          set y (0 - Dep / 2 )  ]
( n4 r( G) [. ^# {3 Y! ^                          set d int (c / 5) * 5
8 x7 ~/ {/ z. z   setxy   ( xcor-of turtle d + x )3 B) ]1 o2 i! k, o
           (ycor-of turtle d + y )
- Z% V+ \! k; o          , l, C2 N  U  @
            
& d- Q+ H. J& |if (remainder who 5 = 3) [set k who
' o" }0 \) A7 s, ~                          set x( Wid / 2)  & {2 A9 ?' \8 D. s# L: H) g/ U' m
                          set y (0 - Dep / 2 ) ]5 [, z4 t% [. O
                          set f int (k / 5) * 54 Q$ i! t0 L+ G6 X  x4 C5 j
  setxy   ( xcor-of turtle f + x )
4 w6 j* P4 }" v* p: x' e0 T           (ycor-of turtle f + y ) % v9 \# b; @& {
           2 e. P  K# z0 V9 a. P
           
- k" ?* u! n9 _, a; K+ iif (remainder who 5 = 4) [set g who
( V5 \. m. d# C/ z                          set x Wid / 2 , e" `( u8 n8 r1 i9 v0 G5 L
                          set y  Dep / 2 ]* `8 y6 S+ T3 T$ y) N" n
                          set h  int (g / 5) * 59 s# ?* v0 w+ Q3 B( h, Q
  setxy   ( xcor-of turtle h + x ), D" @6 o9 l3 ?# \7 j/ _
           (ycor-of turtle h + y ) 5 ]5 V" W$ t* ]" s9 M3 }: w. r
                          
8 c: a9 F/ i, i  g$ u2 Y) a                          3 Y6 F. J* n$ u. J; \9 t
                          ]
. V# h' z1 r2 u& ^% J$ ?6 wend
3 P( D; l+ Q% p9 j3 M: ]% i* l% i( G; m& H& F- c
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
- C- F+ g2 h6 W& K! P* X- }应该是* o4 U3 ?) R: u: _! j0 h5 N
ask turtles [8 n* @( S. c; o1 f! j
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
; a- U* j' G/ _7 l' x                          set y  Dep / 2 " a% w) x' \1 N# j& N  i! |/ \
           set b  int (who / 5) * 5! ?* f! u( l2 r0 {$ N. s
    setxy ( xcor-of turtle b + x )
! }' R3 v) y; U9 F5 N; ]          ( ycor-of turtle b + y )]]) W+ B$ g1 P6 h" ^# L
end& W$ c: D, Z- R( j0 T. f# l* R4 U; `
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-14 01:55 , Processed in 0.014366 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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