设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7770|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。( {5 n) T! C0 i5 r$ q, T& `7 I
0 F  G% I+ z$ V4 e0 t: t4 y
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。) D" e6 q# G! D

. `' @! T3 \" c2 [. Z. ?turtles-own [a b c d k f g h: P: G* V6 o5 C* Q
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ) {4 E. ?5 ]0 N- `( v( A# C! R5 a2 e
]1 h: e) @/ T, ^3 F  j
to new
6 Y4 [; t/ z' C/ H* b  ca
, b7 V5 \2 U5 X2 {, T' J$ j  crt 5 * num_of_building. h$ y: c/ T7 P0 m2 y. \
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
) D2 b0 g7 r2 {& a  scatter     ;;keep center-turtle random positions
2 X2 p& u8 L5 b( w0 R* H  unit_plan   ;;make up the building plan
) o9 y% @" x9 S1 U0 l: Oend3 g6 P% c6 i$ B6 Y- V; Y
to scatter% P. r9 P# S8 x& U5 _
ask turtles with [remainder who 5 = 0]8 X0 i/ I; J. x9 ~" m
[
6 m( [, {; M5 o; Wset xcor xcor - 6 + random-float 15
7 e- R0 Z9 s; S/ xset ycor ycor - 6 + random-float 15
- A' M2 F. Q1 a4 o. m7 W]
& y& g9 S" G6 O: [4 T7 Iend
/ \3 @4 E. Z9 f, [to unit_plan
6 D' h. L5 P+ o4 P/ |/ e4 l! _ask turtles [
7 ?0 S% c" N7 s+ Jif (remainder who 5 = 1) [set a who 2 J7 ~+ s9 U+ g. K
                          set x ( 0 - Wid / 2 ) . p& ?1 d9 f0 y9 J
                          set y  Dep / 2 ]
+ R3 J, |' f: }# [9 ?: v# L           set b  int (a / 5) * 5
5 a4 T, Z9 _% t! i( z  L5 x$ Z9 D    setxy ( xcor-of turtle b + x ). ]: U& |9 `% N( E7 v* m
          ( ycor-of turtle b + y )
1 u* L9 m- \# ]3 kif (remainder who 5 = 2) [set c who
- U. C! _& U2 g# c- ~                          set x ( 0 - Wid / 2 ) & J7 c1 Y* a7 L6 _( Q  X, E- `
                          set y (0 - Dep / 2 )  ]
4 _" T4 g0 Q0 P' p                          set d int (c / 5) * 5
& z# l5 v+ \# N- W# L/ `   setxy   ( xcor-of turtle d + x )) a5 p  e' ?8 T' p% I
           (ycor-of turtle d + y ) " k! x- r4 K, V3 `- w
         
1 T- N3 }  _, F" I; `' Y            % P( V. a- L) z  l% f& {
if (remainder who 5 = 3) [set k who
1 L( g" Y% k. ^" E/ \+ ]  @6 c                          set x( Wid / 2)  
" {0 p( u0 w2 ]) e' I+ e                          set y (0 - Dep / 2 ) ]" X! _# q( z! {/ }( n
                          set f int (k / 5) * 5
3 u+ F3 v6 L, K+ p6 {. r# w; }  setxy   ( xcor-of turtle f + x )& }* |( B1 O- ^3 N7 X. W3 A
           (ycor-of turtle f + y )
: v  L. }; o0 d8 E- t  X7 P" {           
, Z8 S0 t6 [" F           - x& H, M" t4 Q8 s
if (remainder who 5 = 4) [set g who2 f! O& F; H1 J2 j- m! ?; o
                          set x Wid / 2
, @7 K" {5 M  K) n                          set y  Dep / 2 ]
: I1 [, e4 t' b7 X7 b, `                          set h  int (g / 5) * 5! k5 K6 L3 n8 k) G2 P
  setxy   ( xcor-of turtle h + x )
6 m+ E  Q  Q9 y, l           (ycor-of turtle h + y ) 0 s; o9 F* e# ?5 W
                          4 [* F9 \; a% L" ~8 M4 h
                            M# n  q, {* `: W6 N" s
                          ]2 S+ y* j) U! }5 h3 ^& a4 V
end
; `0 `. B6 C, `; E) [! F5 X; G6 q$ e1 Q3 k5 R( K. ~) ?
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,! Q: n1 I3 a9 a$ W$ s; P
应该是% h$ {& Q: {. J! `
ask turtles [
: N5 X$ o  q9 W( D7 G2 jif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 7 y, O9 G4 @; z, a
                          set y  Dep / 2
$ W# }9 |( q7 r" g/ p  @) c           set b  int (who / 5) * 5
  U# v& t# O8 V9 {! l6 u* i    setxy ( xcor-of turtle b + x )8 v8 ~; \$ A% \& ]. A: P
          ( ycor-of turtle b + y )]]
9 ~6 I( g: U1 m$ m& ~end/ }! E5 s! u9 {, c
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-28 13:56 , Processed in 0.023129 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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