设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8053|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。2 o; a7 Q5 }6 w4 d* [
! `) @6 N: g  \
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
8 Z9 }' l! d0 X$ A8 F0 b6 E' u# a& S# ?
turtles-own [a b c d k f g h, M. H& y9 H; V3 h# O7 J
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
" A( Q) ], b2 @3 P* y3 s]8 d* p8 Z/ }: l. X$ u' \2 g  E
to new
  g7 D+ A) I0 r" V- O  ca4 j1 z8 R4 }0 S1 m9 n
  crt 5 * num_of_building( U/ n% @6 ^5 p# _4 D
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
& d, P1 _/ i' L- Q* ]  scatter     ;;keep center-turtle random positions 4 ^1 F# Z( o$ o- _; i% _
  unit_plan   ;;make up the building plan  r3 X' w/ ~( k4 H; |5 f0 Q3 ~
end
' O4 D" J+ a  M8 v, I; W2 pto scatter
& ]0 s$ D* V) T. e7 u8 M0 h2 qask turtles with [remainder who 5 = 0]
7 S- d3 K' k# j[7 k4 c8 a0 ~  D
set xcor xcor - 6 + random-float 15& \3 ~' `2 l  I! Z
set ycor ycor - 6 + random-float 15
3 F2 }) {, W  Q$ f! t  Z]
2 D7 @" ~* b3 i/ `8 a4 o# `5 `4 g4 ]end; T' w6 }2 g6 x/ h( J0 n4 M
to unit_plan
9 m2 C0 Z- T: U! p: u$ i" O. ^ask turtles [
9 H# y' l7 s6 p  R; ~if (remainder who 5 = 1) [set a who 6 d/ Q8 Z; M; \4 S, v) o
                          set x ( 0 - Wid / 2 )
% f' p; q. c( m2 B% {4 _  k2 p6 V                          set y  Dep / 2 ]
9 G2 \% }" \6 g; n2 `1 U& i. R           set b  int (a / 5) * 5' o8 i8 i5 Z2 U
    setxy ( xcor-of turtle b + x )
* k4 }- ^! Y9 m% g+ G          ( ycor-of turtle b + y )
, q; q2 W4 u5 dif (remainder who 5 = 2) [set c who* q: B: r  J" R- {. ]- R/ x. b
                          set x ( 0 - Wid / 2 )
/ P2 s" w; Y6 I& n+ p2 b5 F% Y                          set y (0 - Dep / 2 )  ]0 R/ \) n7 K! p
                          set d int (c / 5) * 5
' W( D0 M0 p4 Q! B) B9 c% s% a3 f  z, A   setxy   ( xcor-of turtle d + x )
8 E$ f9 l9 ^7 m! x           (ycor-of turtle d + y ) + d8 J: ^  D% d. x$ r
          - y% ~, c  j' ~6 Y8 a
            $ \+ w+ p1 h6 U9 z/ u
if (remainder who 5 = 3) [set k who$ o1 z1 ~+ y6 S& [: B% L
                          set x( Wid / 2)  
2 K9 e9 y6 w. V  S                          set y (0 - Dep / 2 ) ]/ C( y9 S8 |+ k0 K1 @! M$ m
                          set f int (k / 5) * 5
# |" A: v* d0 ^  setxy   ( xcor-of turtle f + x )
* ]; q4 X- k" D/ T5 s0 `; ?           (ycor-of turtle f + y ) . t1 X7 m5 m/ ]- ^+ S  c
           , N' ~6 y% `% R5 P; x
           
. l: t: m* d. y$ F- qif (remainder who 5 = 4) [set g who) d7 N( ?  [, Z9 n
                          set x Wid / 2 ) o9 [; J+ h0 g! F% i4 P/ @+ I4 I, V5 U
                          set y  Dep / 2 ]& g: }# E6 Y2 b4 y) n3 `* v8 `
                          set h  int (g / 5) * 5
: K% s) n- w0 ?  setxy   ( xcor-of turtle h + x )
7 E# Q0 R. Z7 U2 q  K           (ycor-of turtle h + y )
# ^+ N3 w5 Q$ H: `  m                          # c, ^/ Q: I8 [* O% L
                          - o* p1 ?6 q. ?1 s; r" j
                          ]9 ^" ~/ A0 d4 |2 r9 [) w) q+ |0 ?8 c
end
/ |" v/ `' l9 l2 O- B! y( J2 p! f
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,0 N1 }! x( Z5 p5 a
应该是) i4 z; w7 O, S$ _8 c
ask turtles [
* W9 u0 y; m& [2 ~7 ~$ lif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
! x9 Q) M/ s  V. X                          set y  Dep / 2
- l9 `: c5 H' N3 Z. M           set b  int (who / 5) * 5, ?# z. X& {) ~" O7 _
    setxy ( xcor-of turtle b + x )
- p1 ~3 l1 Y2 F+ z& u5 q9 J  d          ( ycor-of turtle b + y )]]" q( B  D- S; J9 K2 h
end4 \/ d) [! x. X* Z
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-2 01:45 , Processed in 0.020673 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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