设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6911|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。! ?1 c- o! `; b1 P- r/ g8 A

0 O0 k; Z; L. \' d/ u/ w) p但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
5 ?: k6 g# |! ^/ g9 }( @  m; r# z. L  Q4 ~2 |  h0 z
turtles-own [a b c d k f g h3 V. M3 z2 n! }8 L
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
+ O# S$ k2 m- k  ~4 R]
, S, Q) I5 o4 {/ r8 ^0 ito new* }2 Q: {/ D, k; L
  ca; p+ H" ~) f- F2 S. d  V* A+ C' |6 W
  crt 5 * num_of_building
& p( Q4 ?/ z6 R8 Z8 P& p) W" ?7 ^  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
+ `& [9 V& I' M% z1 j! n; j  scatter     ;;keep center-turtle random positions 8 B# L& W1 D/ H. Q
  unit_plan   ;;make up the building plan
& J% X( Q5 v/ b2 }: n$ V! [; V% oend
1 u* h5 a$ D/ |+ w* T7 N  n/ Mto scatter
% j& @6 c) P2 J% G( @8 w; W" Bask turtles with [remainder who 5 = 0]
$ Z% H4 V7 H# R[
$ U2 u; k/ z4 p1 X+ nset xcor xcor - 6 + random-float 15* e' k- d2 P1 W" H( p
set ycor ycor - 6 + random-float 15
8 P* T; C6 x2 y+ ]" v  D% Z  F% o]; T1 Z4 n7 K2 t- Q
end$ |, E/ C! {, x! ]! Y+ b0 y7 m
to unit_plan
. F: R' }, I7 M$ L$ Z/ m: lask turtles [" z- _$ n4 W1 q! y9 C( b5 M
if (remainder who 5 = 1) [set a who
4 f3 }  l  p4 o- f( a                          set x ( 0 - Wid / 2 )
% j- u9 B6 |8 \) O' |1 n/ r( v                          set y  Dep / 2 ]( K# S! M* a) b. V
           set b  int (a / 5) * 5( G$ k, ]# D0 [
    setxy ( xcor-of turtle b + x )/ q0 O, \% }2 _8 K- f8 C: p
          ( ycor-of turtle b + y )
4 r$ o$ P% N! V% |; mif (remainder who 5 = 2) [set c who
3 u* A7 f* v- }* Y, }% i4 i                          set x ( 0 - Wid / 2 ) ; s* S, A. f" E
                          set y (0 - Dep / 2 )  ]
" p1 F" v; N. D5 @. ]( y/ d                          set d int (c / 5) * 5
2 C  \. w% m/ c. s+ Z5 Z   setxy   ( xcor-of turtle d + x )5 i( b! `) L7 K5 r4 Z5 U
           (ycor-of turtle d + y )
* j" {4 I; R& [         
7 k# m+ R# M" x8 \5 q. [4 M            * X) ]. p8 c1 e( C) @9 L) X
if (remainder who 5 = 3) [set k who/ P- o- @4 K+ S; o
                          set x( Wid / 2)  
8 A& I6 N8 R0 y+ D0 Q* @/ C: n                          set y (0 - Dep / 2 ) ]! V! g# P& F& S& T# [/ J: ?
                          set f int (k / 5) * 50 v; S1 [8 B' u
  setxy   ( xcor-of turtle f + x )
5 S- R7 c+ n$ y9 {+ r           (ycor-of turtle f + y ) . Q' O0 x1 p; M% A, Q, h
           
/ k5 D/ E4 P! ^, u$ f           & |( D. g0 d  M( \' u
if (remainder who 5 = 4) [set g who% j. |. J' b5 {  F9 M3 K8 ?! L
                          set x Wid / 2 3 L. o' {, B0 e. ?
                          set y  Dep / 2 ]7 W% `: {& b  l/ v) n/ E+ L( y
                          set h  int (g / 5) * 5
7 i4 @1 Z# _, J* u+ M( Z  setxy   ( xcor-of turtle h + x ), J3 s; @! m1 q+ }! ~, I/ ^+ B
           (ycor-of turtle h + y ) ( N" [9 S1 m( x  }  R( v3 L- P
                          # R& [/ I3 ?5 N1 G
                          & \2 P. k# m; V5 ], ]: a
                          ]
/ g) q/ p7 ?$ O/ Oend7 b3 T3 k6 C' m! e
) n4 f' w/ q# j5 z. T# N5 j4 X
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,9 Y. j# v5 w( b2 e
应该是
, w7 {; _, h0 z" yask turtles [. v9 l0 q6 [! o3 ]3 l  j; t+ M
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
* P- ]8 R# a% y# T1 p) b                          set y  Dep / 2 8 G! E! w& s, b, h
           set b  int (who / 5) * 5
, p% A) x% E0 d7 ~& e    setxy ( xcor-of turtle b + x )
# K) S( ]( v2 T2 u          ( ycor-of turtle b + y )]]
2 v# R. |  b) J: ]  mend, ^/ {+ P/ _& Z) C
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-9 06:59 , Processed in 0.015076 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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