设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8023|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。% n/ a! H  t! u2 A

- x5 N& E1 C& \/ o" C8 j  `但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。( Q+ O8 V' @" f, F0 l- t8 v3 p
+ P5 e+ R- e7 b  d' E1 x
turtles-own [a b c d k f g h! O9 W) ~  f4 h0 i
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
7 n! {' F, k+ S3 I  f1 p2 s], q6 U( T- V& R- }% s/ ?  z; Z% @
to new! M1 }( N4 H! u, x
  ca
7 D% p- `1 K1 r$ W- n, z  crt 5 * num_of_building& m6 ?+ [. c+ n. [! X, G) d
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
7 R9 o8 X% O- U! |  scatter     ;;keep center-turtle random positions 6 |2 F! p5 H5 J# C" \
  unit_plan   ;;make up the building plan  `$ M7 v3 p  k; y4 {( P" {! v# _
end: N, l& }/ s3 k8 q' ]2 ^, |
to scatter
9 T- c1 b" T' H  R1 e4 kask turtles with [remainder who 5 = 0]
1 z* r3 P# \# m# v[2 a" U1 ~8 p9 b: n1 F
set xcor xcor - 6 + random-float 15
! k8 _3 |2 M$ V" uset ycor ycor - 6 + random-float 15
( ]# g7 q4 \# w  ?2 E2 y]
, t% S. U4 H7 H6 Eend
% \8 p$ |+ w6 _# u! N: {' X: Xto unit_plan
9 X& [0 P, M1 ^0 j2 j  D1 w  qask turtles [
3 |1 M; C- E+ ?# tif (remainder who 5 = 1) [set a who ) i# d$ y; ^  |2 T: O
                          set x ( 0 - Wid / 2 )
- y2 M, ?  P. ^" E6 n# O! R6 B                          set y  Dep / 2 ]6 e( a; U* T  g8 N
           set b  int (a / 5) * 5
; ~# t+ n0 h: b! X" s8 i) X4 R    setxy ( xcor-of turtle b + x )
4 b5 }! K$ X0 r1 i2 X' m2 T          ( ycor-of turtle b + y )( J" g4 I  f8 l
if (remainder who 5 = 2) [set c who
% h1 n" s, _& p% z6 B8 V2 k                          set x ( 0 - Wid / 2 ) ; s7 w9 f) m  |1 |" }5 [) a& w
                          set y (0 - Dep / 2 )  ]+ w# N. a! r  t3 G1 D6 \
                          set d int (c / 5) * 52 O* S# X1 s: F4 q" }6 |& S
   setxy   ( xcor-of turtle d + x )
/ q. _' ?$ S& d( X2 |           (ycor-of turtle d + y ) 0 M& y2 M2 b+ i$ W0 @5 M
         
& A/ |7 l! z4 s; N: _4 y            1 @# L4 H  M. j% {* M( ^
if (remainder who 5 = 3) [set k who$ z" T3 Y( x' W6 V: @! Y& S+ A5 D* r
                          set x( Wid / 2)  * b( T* }. q8 o9 k4 E) C9 P: N6 o
                          set y (0 - Dep / 2 ) ]8 ~7 w  _/ w, u  Y% s
                          set f int (k / 5) * 5
( c: z- e& _2 ^  [5 D* u* Z" g  setxy   ( xcor-of turtle f + x )
, w: A7 v) a( G6 d5 U  R           (ycor-of turtle f + y ) ! X$ m  Y( k+ }2 K- v
           
- t$ [# h! R  b( K7 f! Y! q; O+ D           
( R* G1 P2 W9 A1 Z# ]if (remainder who 5 = 4) [set g who
  K0 z6 l! Z0 w/ D' G                          set x Wid / 2 + [6 j5 X& m; v, x' y
                          set y  Dep / 2 ]' R2 `# V2 x9 ~+ c5 l, c
                          set h  int (g / 5) * 5
9 D) k6 U1 @, m$ n7 U  setxy   ( xcor-of turtle h + x )
. \- V0 t/ j/ C/ `6 v$ [/ i           (ycor-of turtle h + y ) + F$ t5 D/ g: H7 |6 I# J
                          
8 E6 _- w0 o& c; A8 Y6 G                          
9 l/ L, E3 g( f; M4 a                          ]" n8 U% ]' z3 q' Z; x$ N
end
# G4 j" p- `; n
, J8 Y2 X2 M1 l$ h7 A: O& w[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了," Q1 z, g+ }% ~: i4 L9 F
应该是5 N5 a, u$ s9 @( d8 K
ask turtles [
- l2 y/ o. J* F4 X1 B& Uif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
/ c* d& a  n8 K. C( i7 l, |8 o- M6 f) }                          set y  Dep / 2
% x1 ]& p& S+ D. W) [6 }           set b  int (who / 5) * 59 V% H7 {" S9 z. }: p7 D, ~
    setxy ( xcor-of turtle b + x )0 z, {. W( A6 D" s+ A
          ( ycor-of turtle b + y )]]9 m  F! G% V$ _% A8 Z8 y2 W: X1 I$ G
end
# h3 ]' M: X+ L; r8 M0 @之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-29 15:16 , Processed in 0.014825 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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