设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9091|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
! E2 u) i6 H' W3 b# ]( n$ W* P+ O& ~  x8 Q6 T8 |! k1 p9 J- u
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
/ ~3 Z* Q' l- D- B0 M) m& u
! [; Q, q$ G7 y0 C4 I  \2 Fturtles-own [a b c d k f g h
) [8 N3 K, R3 i/ X1 }6 v( j. ~  e  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 9 s- U7 P! ]. a# \" |+ @
]. e* `9 |7 Q3 b% c! _/ M
to new
; k* e9 A8 r2 y3 ^  ca7 `8 k9 ?( _# c& Y5 r
  crt 5 * num_of_building
! Z4 o, ?* f: s' z) Q! }  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
; w! s' \% d5 v1 F. `  scatter     ;;keep center-turtle random positions . B$ R, ^6 S8 T7 g! b5 Y
  unit_plan   ;;make up the building plan" M# p5 O/ @& W
end: Y- z6 c# J) ^3 W
to scatter
' B  P' O7 X' u; Dask turtles with [remainder who 5 = 0]
- Q$ H  K5 _5 Z2 J+ B7 V[+ V- r+ g5 o+ r4 J! E0 R
set xcor xcor - 6 + random-float 15
% a2 q* B/ Q. y- `$ z2 wset ycor ycor - 6 + random-float 15/ s; |+ L! H& X3 D% s$ O$ Z
]
7 G6 Y# S# o+ R/ v6 pend( ?9 V2 i+ R7 [$ A1 h/ {
to unit_plan 8 ~, Z. _0 R; S6 j; u# ^
ask turtles [
6 x! x2 f" H1 ]1 A% `% Gif (remainder who 5 = 1) [set a who
/ _  R1 ?. r, ?% b! s5 i. L. {                          set x ( 0 - Wid / 2 ) ( V' j- Y" i) V" d3 o& Q% t
                          set y  Dep / 2 ]1 T9 }5 k4 b9 ^7 G
           set b  int (a / 5) * 5
$ z4 s- b, j# I2 R/ P    setxy ( xcor-of turtle b + x )
" a) T6 `8 Y. Y/ j# n0 i          ( ycor-of turtle b + y )
4 N: P! C7 x! M6 @/ h( b+ b) D; N: iif (remainder who 5 = 2) [set c who
, b* n& W# ~* ]! Q* s                          set x ( 0 - Wid / 2 )
, t$ Y# i2 {! P/ Y% A                          set y (0 - Dep / 2 )  ]( ^" X2 v$ [0 a4 F8 R3 t
                          set d int (c / 5) * 5
  g0 F& |4 F6 \0 Z8 m# f   setxy   ( xcor-of turtle d + x )2 Z$ |0 w1 j: L. y8 }
           (ycor-of turtle d + y )
# g9 M  e1 _+ U8 o  A; O$ F& d% G         
% _# v) Y3 W$ C+ G; F            & h! o3 J1 z2 f/ V3 q
if (remainder who 5 = 3) [set k who
- d8 [) a) |' S* `+ a) O                          set x( Wid / 2)  
! {2 E* B& u5 g/ u6 j/ p                          set y (0 - Dep / 2 ) ]0 c' d; q* s, W$ A8 j/ y" z
                          set f int (k / 5) * 5
0 m5 R% W! H' `6 V* r$ f  setxy   ( xcor-of turtle f + x )
( q! Y. H; q6 r4 d           (ycor-of turtle f + y )
7 s7 G9 B) O. Y( V& v! `           
" d/ g2 l; `- G( j7 y           
" I* W7 Z, C( x# j; A+ e" o  yif (remainder who 5 = 4) [set g who; v2 \- n( W  U% A9 Y- r
                          set x Wid / 2 ; ?2 h; _$ z% c3 ^5 \
                          set y  Dep / 2 ]
7 d7 ~" j( |( L                          set h  int (g / 5) * 5% j' O, ]7 o) w
  setxy   ( xcor-of turtle h + x )
: c7 e  v7 c5 V. @# B4 A, d1 \           (ycor-of turtle h + y )
& `# k7 l( H3 V; Q                          
# v2 N0 k" ~! g( m1 c                          ! n, N7 {' y9 m" s
                          ]
# H1 g- y! G2 K/ y# `end
3 u6 p9 |& g( Q8 o- `1 {
( ?( p- w# u+ H9 R[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
, Z" J: _( H: W* Z% _% e应该是+ B* k; G" V- W  b6 q8 z
ask turtles [
& l* v3 P- t5 `+ r7 j- T" b: o0 }3 Bif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
* l" @9 T7 z$ S; o$ W# p                          set y  Dep / 2
5 M/ u0 M8 T( ~           set b  int (who / 5) * 5
7 Q' \+ C: F7 j8 s+ B+ r    setxy ( xcor-of turtle b + x )* C0 V$ Z0 e9 Q3 U
          ( ycor-of turtle b + y )]]9 ?* z' H' A, H, C: ^( T9 c
end0 I' s8 Q; ~( }' t* E+ n
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-16 18:21 , Processed in 0.020032 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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