设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8232|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。( k2 X  f8 s( n9 F& E% E
5 t5 ~9 g9 }6 T0 @
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。3 K* x4 Z7 Z& [! [% W
% c5 Z8 V$ |/ Y
turtles-own [a b c d k f g h% y  Q" [# v$ U  O0 H
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ( }+ P  m! P4 J& H8 Z2 W& D
]
' P$ h+ Q/ f. Jto new. u: k; h1 G  D9 z; J
  ca  C; ~/ E6 G2 L5 I7 F
  crt 5 * num_of_building; M, S! G  z, ^  g; l: j
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]3 i4 D9 q( K3 m8 [! z  E
  scatter     ;;keep center-turtle random positions 0 ~9 G: I7 M( l' s8 e* Q$ H6 f0 r
  unit_plan   ;;make up the building plan- q* q1 D) y+ K6 I* n  e
end( i2 ^0 x* E  ?/ N, O
to scatter6 X; I$ S, F  H" M. D) F! C
ask turtles with [remainder who 5 = 0]4 n" {9 e* l( I$ Y
[- y, h0 J5 F3 W& L
set xcor xcor - 6 + random-float 15
% D4 d3 D3 u' l6 P. W0 M8 Eset ycor ycor - 6 + random-float 15% j* N9 Q) Y& o/ H+ [
], w; ?$ D: P" {6 L
end& l: D/ Y0 r2 v3 G
to unit_plan
+ S5 a, k' d9 w) D8 x# N, Iask turtles [
+ H* u% ~4 a9 r: P3 T) Qif (remainder who 5 = 1) [set a who 1 i7 h! P$ Y, p  O
                          set x ( 0 - Wid / 2 )
  e) ^$ z9 l- S" v+ l                          set y  Dep / 2 ]
( V3 c) B2 s+ o; V" B' `+ F! {% F0 \           set b  int (a / 5) * 5
  G2 I# o& h% a+ |2 F    setxy ( xcor-of turtle b + x )
# g9 r# q- A, n! T- ^2 M          ( ycor-of turtle b + y )
0 \  O1 M  ?  {2 R5 Pif (remainder who 5 = 2) [set c who
2 k( K% ~) L( ]                          set x ( 0 - Wid / 2 )
+ g+ u$ t7 Z9 m$ o# e                          set y (0 - Dep / 2 )  ]0 \- ^: ?( V. `: [, r) T( i; P
                          set d int (c / 5) * 5
0 [/ q1 c( R3 a1 b  e6 l' t   setxy   ( xcor-of turtle d + x ): c# n% m% ~: z. L3 s8 f) k
           (ycor-of turtle d + y )
) s( ~  x, C# y7 d. q0 w          , z9 l' \6 Y! C/ `
            
4 }- T+ W, D5 V4 c4 ?+ Uif (remainder who 5 = 3) [set k who: Y# u- e6 _. i7 \
                          set x( Wid / 2)  
+ u( o3 v4 K$ f! y9 m/ Y! a                          set y (0 - Dep / 2 ) ]
; @& y: h6 {$ e# A                          set f int (k / 5) * 5
! t9 x1 N% k0 d7 x9 O  setxy   ( xcor-of turtle f + x )9 {2 y& x  Y! K( p0 S7 B
           (ycor-of turtle f + y )   _4 ^- ]1 t5 I1 G. B" `+ a
           # H6 Y- R! c: Z! Y% ], \
           
$ o. }; [; V, ~3 u2 ^$ O1 `0 `if (remainder who 5 = 4) [set g who9 ]5 D, Q2 y3 Y0 I+ I3 I7 f$ S
                          set x Wid / 2
( \: q0 R. f- A7 }                          set y  Dep / 2 ]% ^5 e6 }9 B/ P2 J* y) t) d# h
                          set h  int (g / 5) * 5: ?  R6 l& o$ _0 l+ b- T; v' P
  setxy   ( xcor-of turtle h + x )9 ~4 e8 e) H5 L
           (ycor-of turtle h + y ) 8 b4 r; T7 a4 x# \" A
                            @8 w9 Z+ G3 K8 v; l$ b" ?3 J
                          2 q5 k* e5 z% Y, W* q
                          ]
2 o$ u5 w( r7 X- I6 q( p# Jend* j0 f7 X+ k3 p+ ~, ~
1 o* i- F1 c& U$ ], V+ D& N
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
+ r% x/ N! B; ?- c! k- q& G- d( {应该是
- n$ B& l. a1 u, ]ask turtles [
, O7 K" X2 r* P4 `  q5 Mif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
; }* p# G8 \* z" f" r- |                          set y  Dep / 2 $ ?$ [9 c0 }  r8 Y
           set b  int (who / 5) * 5" b- N7 H$ l- l' n( A  ?0 h
    setxy ( xcor-of turtle b + x )6 P% U" H1 I0 T8 b! h
          ( ycor-of turtle b + y )]]
1 G; s- {9 l% iend
# n* F5 _. ]4 a4 d: {  W之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-22 02:19 , Processed in 0.016969 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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