设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8234|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
6 |4 u! L' l+ N& }0 y) W8 w! N' p9 D3 o* \' \, d- N# c& {, J
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
- R$ l" M5 a7 ?% `3 M; s; j4 h; r3 G7 h' T7 v: E$ m
turtles-own [a b c d k f g h0 n6 A& t9 R0 m% r
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle # H% ^5 E, q( I7 U
]1 F8 k0 S+ c- `9 F" L8 H# Q5 u9 A
to new
; o& v" f' I3 i$ x: o; Q( e2 v  ca
0 B( F% Y0 G3 K1 X5 ~  crt 5 * num_of_building
, P7 y& H8 |4 \  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]2 n  L; O( x* p
  scatter     ;;keep center-turtle random positions
4 E; o  p# Q% ^) P1 k  unit_plan   ;;make up the building plan
$ r( W2 i2 }" yend  E/ d  i, J: ^, `- x$ M
to scatter% Y: t6 W% R; Z: H! s) y
ask turtles with [remainder who 5 = 0]
2 V$ V$ H6 N  U7 o7 Y: I[
8 Y: M  u% ~. y8 Z) M! D4 Zset xcor xcor - 6 + random-float 15( ^: l# m! b) f% R6 x6 D
set ycor ycor - 6 + random-float 155 z; v6 [+ v; z( B: k6 H) V
]6 n) ~$ C! ^3 W4 E  W6 @
end
1 E& V1 F* }+ V5 I! N& o1 B$ c* H- b8 rto unit_plan
1 w; T% N$ Q0 vask turtles [
4 ~4 L* b5 J- @) oif (remainder who 5 = 1) [set a who
" l  M) S8 L& Q% Q: }- y7 d                          set x ( 0 - Wid / 2 )
$ @7 N1 b$ H( W# T5 G                          set y  Dep / 2 ]
* U4 i: B$ y6 u0 \! w: M           set b  int (a / 5) * 5
! Q0 b& m7 L/ G  G3 y5 V8 Y    setxy ( xcor-of turtle b + x ), ]) D- o6 F' T& D/ k9 P. s6 {3 n8 o
          ( ycor-of turtle b + y )2 t7 v% ]) d! C, m
if (remainder who 5 = 2) [set c who
: m2 I$ ^1 ?; \8 L3 w6 u                          set x ( 0 - Wid / 2 ) ' B9 M3 L. x9 e& |" }
                          set y (0 - Dep / 2 )  ]
, w; q: Y4 a2 k4 b                          set d int (c / 5) * 55 b. H# v" e4 o! t
   setxy   ( xcor-of turtle d + x )9 [4 i2 f1 k$ ?/ k! s
           (ycor-of turtle d + y )
9 r& J' D( {& _         
2 I4 n, [, j5 S! q  R$ V            $ {( n2 ]; r1 @" z& I( n; f. \2 ^
if (remainder who 5 = 3) [set k who- R- C/ E7 x7 w; O
                          set x( Wid / 2)  ! X) e. e  K' g  d; v' u  ?
                          set y (0 - Dep / 2 ) ]; i$ l4 D9 _3 O& t$ O# x$ c
                          set f int (k / 5) * 5, x! ^; g* O+ S$ N
  setxy   ( xcor-of turtle f + x )# o* q, g, D' Y+ z
           (ycor-of turtle f + y )   u0 S" D1 x8 B1 h
           
2 m1 F8 t5 v7 K! c  I           3 ~  k8 t# b) H8 N) K. I; }# l
if (remainder who 5 = 4) [set g who! b8 x3 n8 I7 W' J& ^% [
                          set x Wid / 2
. w7 H1 X, Z/ `1 d5 q; p: R" z# D% t                          set y  Dep / 2 ]
) X$ j0 h0 j" B( p* U                          set h  int (g / 5) * 5
3 @$ w" F9 d: a3 z  setxy   ( xcor-of turtle h + x )
1 p" [7 R+ V3 l2 n2 e           (ycor-of turtle h + y )
  T# O  o9 ]* C5 X( b                          
2 y- F4 Z$ [! v9 O8 k                          % Y5 f' j% }1 q# h: {
                          ]
7 r( s3 k' M- H  F. Pend4 b. T# g# D0 b. g0 n

" `; U$ Q  e+ a+ F8 {0 D1 H[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
+ X! j- ^: B0 m% W8 k5 ]* I应该是
' g' Z  Q, F9 uask turtles [" L% x6 Z0 @, w+ d
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) $ k& {8 D. Q$ c3 v
                          set y  Dep / 2
8 g$ [. f7 t, U1 R1 q. Q' D' B           set b  int (who / 5) * 5
' W. v% `( m% c+ w9 W3 {    setxy ( xcor-of turtle b + x )2 E! Y" y( X$ X; U
          ( ycor-of turtle b + y )]]
3 w# J/ k2 n  U( t! r) w" Eend
& Q. [: l& J0 A之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-22 12:53 , Processed in 0.017294 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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