设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8659|回复: 1

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

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

: F7 W$ Y' n7 g但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。% i* y$ f9 [0 K. J
# M+ V8 R) A4 u
turtles-own [a b c d k f g h
( v  A8 @) C% D. `# [7 Z  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
" w1 m4 R8 }, ]: []
  v# v# t, o( |1 u# Lto new
( c/ r) y9 \" O# t4 |  ca" c" `3 T, m( c8 z
  crt 5 * num_of_building! Q8 q9 p% u! |: R# ~9 z1 V
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
6 X+ i- L2 D+ B5 [1 A* T  scatter     ;;keep center-turtle random positions / b/ Z" p" k6 N% ^+ d9 Y* l: F
  unit_plan   ;;make up the building plan- y/ v0 a6 M1 g: |
end
, C7 l7 S6 ~! G9 X0 z: |+ Q7 N% Z' b* Lto scatter
  \# w1 O+ R, X$ O7 J8 Sask turtles with [remainder who 5 = 0]) v/ ?- @- t2 y# f
[9 B) `' h* \) i8 l
set xcor xcor - 6 + random-float 15
6 Z2 D2 R6 W) }6 _, e7 s/ \- Vset ycor ycor - 6 + random-float 15
" z; }! n6 i9 }. {* H" j' P6 Z7 p# e]
! A% ~" B+ A) Fend7 [: C  m% L$ r/ @  _: r
to unit_plan ! A$ d, t4 a1 D% B% h# N' w
ask turtles [
+ x- L+ }/ Q/ L% }9 }/ T) p$ dif (remainder who 5 = 1) [set a who
7 u- z1 c9 T% G% B7 ?                          set x ( 0 - Wid / 2 )
& ?* K7 O/ X/ M, y                          set y  Dep / 2 ]! b( R- M* @0 w5 v8 L% |" \
           set b  int (a / 5) * 5
& J, t7 X- ~6 A# L0 l( _    setxy ( xcor-of turtle b + x )
: ?0 C& y3 C; h+ J1 _& W* N          ( ycor-of turtle b + y )! |+ g# w9 |: s
if (remainder who 5 = 2) [set c who) `- e- {* @8 x
                          set x ( 0 - Wid / 2 ) - @. K; N7 i, n1 f% E" T! w: b  ?
                          set y (0 - Dep / 2 )  ]
5 v1 D- W0 ~3 G$ d8 Z) a2 B% m                          set d int (c / 5) * 5
) x  \) V6 e6 x8 Z& h2 Q/ e$ U   setxy   ( xcor-of turtle d + x )
# t* Y# O. J9 z. ~+ ?, h1 x, [           (ycor-of turtle d + y ) 6 r8 c- \2 X2 ], t
         
8 {6 H8 ]7 ^3 f9 |            
' B4 A5 d7 s6 a" D/ Jif (remainder who 5 = 3) [set k who% v; \: z( Z$ I- i
                          set x( Wid / 2)  . n( a0 B, |9 D
                          set y (0 - Dep / 2 ) ]# a  U; ^# x: o" m
                          set f int (k / 5) * 59 V3 k1 h% l" t6 b4 R6 }# [
  setxy   ( xcor-of turtle f + x )
# @0 L: i) E2 i6 p! W8 D# z3 Y           (ycor-of turtle f + y ) 9 n9 i% o% {) `0 ~
           , ~! E: T- S9 a. w4 y& z
           
9 [% \) C$ E* R6 x( j4 iif (remainder who 5 = 4) [set g who6 ]* w+ v) d& |' V& F( Y6 }5 L* X
                          set x Wid / 2
! L) l- Z* j$ T$ A4 F+ y* D3 `# Z                          set y  Dep / 2 ]6 \8 _) M, r/ K& k1 A' c
                          set h  int (g / 5) * 5. `, e% i" T8 B+ V) w9 c( ^
  setxy   ( xcor-of turtle h + x )
: u' H5 w& D/ l, y7 O/ B           (ycor-of turtle h + y ) 8 {% V2 R' q) d$ M% ?4 B# r& |
                          
: z. Q& e+ ^4 b" v1 a9 T( q                          ) @' ^) X4 r  ^: ^( v
                          ]
+ c/ l( ]- u; V" }8 D+ T: rend: q3 |  ?4 r, \" Z

; f; T5 k8 O. Y5 M" Z[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,) l% q; n% `5 p) n
应该是
7 v( @( {7 }% W% s9 v- V# @ask turtles [6 G- W3 B5 c% t
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
# r3 M/ p& R- p( C( P                          set y  Dep / 2 " P) k9 M) S1 Z( U, j' s4 }
           set b  int (who / 5) * 5
" i$ g8 l7 E! x    setxy ( xcor-of turtle b + x )5 C+ |! K$ J9 S: ^, Q) I& Z
          ( ycor-of turtle b + y )]]( Z! _2 i. ?2 P2 S
end% t& G; P. j# n) e6 |
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-21 18:54 , Processed in 0.015492 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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