设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8968|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。$ `' X! B$ B% H6 o
1 N1 ^( w; Z# V$ e7 `
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。& _; z, C$ ~, F- A

; E( p7 ^1 V; a! g& k& ~turtles-own [a b c d k f g h. V* |. W" t5 Q" {/ L. B+ N1 @5 o9 ~
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
; {2 z8 t2 \# l' p]: i: O' A3 P% o' g/ c
to new0 y* |* r' [+ L: ?) y
  ca
5 q' e4 F2 d; d1 C8 J5 C  crt 5 * num_of_building
6 r" C, _& i+ e* M& H: a- C8 j  z  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
3 K9 R# W) h( P. Y: |) R9 L  scatter     ;;keep center-turtle random positions
6 x$ Y4 s( G) w  unit_plan   ;;make up the building plan
- D3 p' S8 Y  hend  `! m6 l3 E2 O5 V6 p( p3 y  x
to scatter" j3 U- A0 Y' i; k5 q
ask turtles with [remainder who 5 = 0]6 A* i& R, V  y
[  i4 C0 o+ C$ c2 j3 G
set xcor xcor - 6 + random-float 15
% r  ]! U# A0 q7 lset ycor ycor - 6 + random-float 15
5 b( X3 }4 a1 R( W+ _]6 H' K) U3 y* w; T% U, U, V1 F6 H
end5 v9 A6 e! m& V9 o/ r" O
to unit_plan ) p& I1 u/ R- ?4 N4 c
ask turtles [
2 o! q6 W/ L2 B4 hif (remainder who 5 = 1) [set a who
, X. N1 p2 S  |3 a5 ~4 m                          set x ( 0 - Wid / 2 )
6 G' s5 `9 ~: J# v- y! F                          set y  Dep / 2 ]2 o+ @% `: X3 f( \( P
           set b  int (a / 5) * 5
/ A) c# l) R2 }9 ]% _9 |    setxy ( xcor-of turtle b + x )" D6 v) v: N* F; m
          ( ycor-of turtle b + y )
/ b+ ^2 x, e$ n9 Tif (remainder who 5 = 2) [set c who
3 [: r, J: ]' H% O                          set x ( 0 - Wid / 2 )
+ L* E* b3 o% [% z. C) M+ w                          set y (0 - Dep / 2 )  ]
1 W, c; m7 `1 A+ ~; Q! i                          set d int (c / 5) * 5
. _' P; x& _7 x  v   setxy   ( xcor-of turtle d + x ): E5 u% A. O/ a
           (ycor-of turtle d + y ) ( i$ F! D; J0 ], S2 v3 E
          1 P. L8 @4 ^8 O; E
            
9 A  k7 ?% r  f* jif (remainder who 5 = 3) [set k who" C0 Z# ]& `: S! y5 o# B% S1 `
                          set x( Wid / 2)  
* G1 s! h2 F( K  o# a" m+ M* ~                          set y (0 - Dep / 2 ) ]
+ V# f  f- r2 N6 D8 [                          set f int (k / 5) * 5
5 f& O$ t1 D4 |" s0 L& y+ F  setxy   ( xcor-of turtle f + x )* ~8 h( G! {% M; F0 E# N. Y$ X. K
           (ycor-of turtle f + y ) 9 a- H5 n4 _# t* M' z
           
$ p0 P! H% L! P9 R: k           $ w. `0 E+ z( t9 b
if (remainder who 5 = 4) [set g who2 b- p  K8 M% d8 D( B$ F: c6 H9 L
                          set x Wid / 2
5 o! i+ e$ N7 Y( Q  W* P, i# I3 r                          set y  Dep / 2 ]
; w6 v% {0 U( u5 K                          set h  int (g / 5) * 5% R! t! y7 ]6 i* c0 ~8 x6 q5 v
  setxy   ( xcor-of turtle h + x )
( d/ g! d0 S' R4 t  I3 ~# `           (ycor-of turtle h + y )
( }) H# p- w6 t( k- C; M6 I" j                          
& I5 j' h8 R& J3 z( T: o                          
) E8 g% y5 |! W* H7 C! r$ m                          ]  Q/ q, x) R& A5 `9 B1 {
end
" H  c: D3 l. W- [7 d+ r( |" y
8 U- [9 C1 l& i  u5 l, i  W/ Z- c[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,; L5 c' Y7 l3 I9 ^- C& V
应该是
1 t% X- k' {- ?$ Uask turtles [
& p2 A+ T$ r( _+ [if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
; Z7 E4 M. t* {; i  V$ t                          set y  Dep / 2 8 R! u/ B  {, E
           set b  int (who / 5) * 50 v) G" O! X) |
    setxy ( xcor-of turtle b + x )
2 O8 P+ X  ~: P8 J, G          ( ycor-of turtle b + y )]]! S9 e, P; ^0 q' _+ v/ f7 @0 f
end
( {$ _( h% T- `' A$ U之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-1 19:38 , Processed in 0.018623 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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