设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8379|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。- f0 p2 E& m6 S% @# M  |% |' u
) t2 ]9 n: q0 p% d
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。1 Z3 S$ u0 o* F: T
7 O9 t7 v2 R9 G' ~" ^/ [* X) ^
turtles-own [a b c d k f g h9 g5 f& x2 ~, D0 |5 U$ {
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
7 F: h; |( j  |]8 K% a  ?8 [9 L6 {) b% \5 l1 ?3 \
to new7 N. f' J! |% m  C1 ?  k5 e
  ca
1 {4 l$ ]3 C( k# y; _  crt 5 * num_of_building
8 P( m: {2 j3 G' P$ y6 Q; Y/ X  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
+ a% \' B/ X* R. |3 \  scatter     ;;keep center-turtle random positions
% P! C# }& b! t3 w  unit_plan   ;;make up the building plan$ x) s$ {/ n1 ?; `0 g1 I
end  T$ S( F" H, f! B. S! S
to scatter
8 V+ q" G+ Z/ y  Q% d3 }  r8 Aask turtles with [remainder who 5 = 0]6 B: ^' g/ L8 Z1 I+ F6 f* b
[
. K7 a. ^0 H3 n2 h! C6 V# Eset xcor xcor - 6 + random-float 15
/ e4 s( H- o$ ]* f) H( Dset ycor ycor - 6 + random-float 153 @3 }0 ~9 I  I( v' T: b+ l# W/ Z* c
]2 Z/ T  T# Q. ^' m7 R8 z  c  p
end6 d9 r7 f7 x! G' l1 r& ~& m5 f8 L
to unit_plan
# Q" a& p% g" G' D7 }2 B5 Gask turtles [
; W- {9 s( l% |6 ~5 P2 Z1 ~0 yif (remainder who 5 = 1) [set a who
9 q. P8 D% D$ V; t. ~                          set x ( 0 - Wid / 2 ) 5 v+ v( B* q  {; m, M; i8 K
                          set y  Dep / 2 ]0 |  b' I4 C" m% {' M; B
           set b  int (a / 5) * 5
; I. d2 }, _+ X3 z% {! {    setxy ( xcor-of turtle b + x )
  l$ E3 {% [) R' S0 `( F$ @1 @          ( ycor-of turtle b + y ): [4 Q4 G3 _4 e  G- c: Q8 |9 A
if (remainder who 5 = 2) [set c who
$ T5 c+ Y4 D% ^2 ^$ k# L                          set x ( 0 - Wid / 2 )
5 o; u4 [3 Y, \$ o& W, S. K                          set y (0 - Dep / 2 )  ]$ S( ^' n3 K" ?1 v. |# H6 E
                          set d int (c / 5) * 5" a) L1 z! k* z: d
   setxy   ( xcor-of turtle d + x )
+ x1 V" v* N# G           (ycor-of turtle d + y ) " d# V7 T5 E# M  R6 V( G
          5 D$ D  X1 }2 L" |* H9 Z/ X
            ) `5 q, I* l5 P0 k$ c$ e5 Q/ g0 v
if (remainder who 5 = 3) [set k who
  |- Q6 ?4 u! e+ y1 E5 ^" b                          set x( Wid / 2)  
2 y) p' R, @( l1 w0 w                          set y (0 - Dep / 2 ) ]
. o6 R% h3 f: ^0 x: i; m6 G. m! Z                          set f int (k / 5) * 5/ G2 c4 I& ~/ b- [
  setxy   ( xcor-of turtle f + x )
! q6 t% ]; G! ?) s           (ycor-of turtle f + y )
4 E1 l+ G5 O- t3 {5 s' ~3 I; a           3 E/ v' M% A8 K% d, O
           3 I% P3 [4 L& [0 U. U6 v
if (remainder who 5 = 4) [set g who
& Q/ ?0 U7 v/ |                          set x Wid / 2
3 r, d+ @' l6 D+ ?: f' Y8 O6 f                          set y  Dep / 2 ]" Y; }* ^/ p! L
                          set h  int (g / 5) * 5
. U1 P% C; S6 g/ A6 U) o* M  setxy   ( xcor-of turtle h + x )
' t' {" E  I/ M$ L/ q/ V           (ycor-of turtle h + y )
5 ]& {- F$ U3 A( Y8 P1 N                          9 y9 a$ U$ r3 M2 e' O* e; c1 c
                          ) V1 `6 e6 t) z
                          ]
: |, v# Y$ B/ Zend# _$ x0 \5 B' n7 E1 T
/ g/ ^/ N- ^* M6 I1 L6 p* p
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
4 R3 e, \0 R# \3 [2 @5 ~应该是
, ^7 J/ W6 J" W. ~ask turtles [( i  _. ?0 W' ?1 }) M8 V# u
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
; i# t) o. X1 L: k, L                          set y  Dep / 2
& m: O7 E2 P! [6 t           set b  int (who / 5) * 5" i7 t0 \" R  P# O/ c; C+ H
    setxy ( xcor-of turtle b + x )
. Q) _6 s+ o0 I  N1 q: y          ( ycor-of turtle b + y )]]$ V& a) ?  E9 H8 P) T
end0 U' ~; N: I* p  }
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-16 23:02 , Processed in 0.012400 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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