设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7462|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
7 D3 j) ~* f0 s( k' L- |6 |) G* O* A+ C8 R& j: ]
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
" g6 i$ D# |- |0 [2 O7 q! O: R1 d
; ^# r- {' p0 R( L& v: hturtles-own [a b c d k f g h
/ S/ C  m; d9 Y: ?5 J& H  x y     ;; these are the leaf-turtle's offsets relative to center-turtle " p3 z0 Z# N5 @. B# E
]
9 s. g5 ?0 m2 f% F- oto new
$ Y7 z! j/ @- D8 B9 T  ca
" H# y: ?$ \9 P! l& o  crt 5 * num_of_building
& i. R. }* ~1 j" h3 }  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]6 t; C0 n  e( `: X. o7 k
  scatter     ;;keep center-turtle random positions
% }. V  G0 w2 O5 F* D  unit_plan   ;;make up the building plan
9 }7 W! J/ j2 G. s. I8 p. bend9 l8 l" Z& x& n% o2 f, g, M
to scatter$ n! @  L' V1 U
ask turtles with [remainder who 5 = 0]4 [- i, P/ W( `
[8 m# m/ R$ x* l3 T. o1 S; H
set xcor xcor - 6 + random-float 15
" Y+ j! j0 u& P1 A0 h, aset ycor ycor - 6 + random-float 154 n  \8 F2 R/ A7 y# \
]
- M  S, Q6 U6 s/ T0 oend
% y7 H4 @+ v! c- |& R0 U6 {to unit_plan
# }3 y5 r  B2 _$ i  u" B# X+ pask turtles [
0 B" l- a1 ~) x; y3 Lif (remainder who 5 = 1) [set a who
8 ~7 Y9 n7 I3 X0 c) f0 p                          set x ( 0 - Wid / 2 )
, N6 s7 y" M1 R; [" q- V: v                          set y  Dep / 2 ]
6 }% |- u$ y6 c8 M0 b& a1 e9 [           set b  int (a / 5) * 5
- O* O- S9 M9 v/ l) D& ]+ c    setxy ( xcor-of turtle b + x ): t7 P3 m2 {" `! [# L' V9 ]
          ( ycor-of turtle b + y )6 p5 P! y' ~+ Q& g; r+ [  [) G/ H
if (remainder who 5 = 2) [set c who
4 b8 g8 c6 _: b7 D9 Z" V$ B                          set x ( 0 - Wid / 2 )
3 h( U- j: \  ]# J                          set y (0 - Dep / 2 )  ]8 f3 |' l) ~1 n4 Z& c3 q
                          set d int (c / 5) * 5
) A' C% N# _; ?3 ^5 j# i, {8 q   setxy   ( xcor-of turtle d + x )! R8 r( d7 n" y& h
           (ycor-of turtle d + y )
% `4 _- Z/ g( s+ e         
' r& p( D% f5 g  y            
9 g$ \: X: G" [! }- i" Eif (remainder who 5 = 3) [set k who
: ~$ Z7 F6 R* B* u! Y/ {$ k3 z$ _" T                          set x( Wid / 2)  
# N! m) g# l7 o                          set y (0 - Dep / 2 ) ]
1 {& r/ i5 a1 E, @                          set f int (k / 5) * 5
/ z$ K2 i6 N2 ^0 [; f: L  setxy   ( xcor-of turtle f + x )
, Y! N( h. I+ Y- t& k' z0 m           (ycor-of turtle f + y ) ) |; x$ {  ^# Y' r$ G
           
. a8 j2 y# t) B3 F4 b4 V           : e6 f- `9 k( \- k4 W2 y
if (remainder who 5 = 4) [set g who! z/ k2 ?0 ]1 N- Z1 W; a' Q
                          set x Wid / 2 / Q! D3 J; r& U+ A) x$ ~
                          set y  Dep / 2 ]
* i) k+ D3 M; E  d) r! x5 N                          set h  int (g / 5) * 5/ m$ `4 w2 q/ v) c5 c
  setxy   ( xcor-of turtle h + x )/ V0 P5 B+ W( z/ }
           (ycor-of turtle h + y )
# G9 Q, Y2 {7 q: W: T                          / s2 a5 @8 U- e! q& I3 s8 \/ ?' U
                          
$ P: `5 d) t! ]' ?6 ?' Q$ O" t                          ]- j1 Y2 X% U: N5 J7 d7 r
end+ f' ^8 C6 Y  l) g9 R) K: O/ T* s
4 ?0 @- z. P7 |$ x3 Z
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,7 l. t; C$ N+ y9 P2 P6 H4 d! g0 p
应该是
* v% T, W- [6 p( Z& Sask turtles [
$ _3 E, _, q& X4 M+ Kif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
" Q$ p# W0 Q3 s/ e, g                          set y  Dep / 2 . A6 w- c6 e% B' B5 {$ X
           set b  int (who / 5) * 5
# J7 T" z+ y( @' ^$ H    setxy ( xcor-of turtle b + x ); {2 ]2 }* _! J: k% [/ q
          ( ycor-of turtle b + y )]]
: G; B3 O: A, ]end
  \+ F8 I) }! r8 T/ [) a) b4 {$ X之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-13 18:48 , Processed in 0.016209 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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