设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7817|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。5 E: L; G0 X- k+ Q" d& F+ {4 K2 X
: Z8 c) S; t/ B$ D/ ^9 C, a
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
" ~4 r9 E$ B/ b2 E% R/ t/ @5 f0 D& n; p
+ m0 T- c& H5 S) D1 Bturtles-own [a b c d k f g h
7 x% U" d1 m/ N' H  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
0 G5 R$ r. \% e+ N]
4 I2 H. ?( @& x0 x2 |! eto new
$ ]7 i; W5 D0 }/ D. H' M- c  ca# h" ?7 ?1 f* m) O
  crt 5 * num_of_building
; R4 C: `; s+ N  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
% }7 O1 m' G/ ]0 j9 O  scatter     ;;keep center-turtle random positions
6 ]- r8 A- q: W: ]- a2 A  unit_plan   ;;make up the building plan& c( P& g7 |% a! ^) Y+ y
end' i* d% T2 L" a4 R. x4 j
to scatter
( i+ ?$ ~4 q# b& s: R3 v% v* fask turtles with [remainder who 5 = 0]
$ d3 z+ M+ X4 X" \2 Z[/ \, P( g+ p" d3 @5 n5 Z
set xcor xcor - 6 + random-float 15
7 K! B, C) [1 r6 {2 Oset ycor ycor - 6 + random-float 155 j: N3 T7 {# S$ s% h/ ?$ a$ U  C
]
9 x+ ?3 A2 ~+ G  ^) ?end( z4 `1 O& j+ h2 o
to unit_plan 3 V* h( S5 U  U' P) K6 [% b
ask turtles [9 C3 e! i" y7 ^
if (remainder who 5 = 1) [set a who
0 Y/ q6 \0 `. w7 z% |% S  h- M  L' X                          set x ( 0 - Wid / 2 ) ' O' h# ]0 e: o  J: i0 }# ~
                          set y  Dep / 2 ]
! O5 H% u* w% U6 m4 a* X           set b  int (a / 5) * 5. O6 A& a. p5 c
    setxy ( xcor-of turtle b + x )
; l! f: D9 t! J          ( ycor-of turtle b + y )
/ K" d4 V: Y, y8 K7 J6 Jif (remainder who 5 = 2) [set c who
  ]4 ^0 H- U4 A                          set x ( 0 - Wid / 2 ) : j. H3 J0 r5 W4 f) K* `1 R
                          set y (0 - Dep / 2 )  ]
- o7 F1 `! ~: h! e" l( F4 W0 S" k                          set d int (c / 5) * 5
0 F' R! z, U% R2 i% B9 V   setxy   ( xcor-of turtle d + x ); @1 i5 S, c! U4 q5 x
           (ycor-of turtle d + y ) : R4 h8 ?9 H% \- c7 ?
          * S# N# P. Q3 {; [
            ; U' y/ V! k; B9 t9 H$ }0 N
if (remainder who 5 = 3) [set k who# z+ b3 O! ^  {; Z# B- Q3 e
                          set x( Wid / 2)  
/ d8 `4 d6 ?9 H4 U) z                          set y (0 - Dep / 2 ) ]
. b: I5 B3 z; H0 t! ]6 T5 A                          set f int (k / 5) * 57 ]. ?1 J- a5 ?9 k
  setxy   ( xcor-of turtle f + x )
' Z4 Y5 x8 R0 c7 N  M           (ycor-of turtle f + y ) + O+ E6 A6 g) B7 l, Q
           6 {- E1 Y" n: I
           - T+ _8 e! \3 \0 g7 m
if (remainder who 5 = 4) [set g who+ h+ j' }& |" x: k3 z1 D* m9 i: p
                          set x Wid / 2
3 I" _3 f% J$ c+ j; u/ {3 P# m                          set y  Dep / 2 ]
, D0 ^; R7 Q/ ~0 O" B                          set h  int (g / 5) * 5
/ M, {* Z  [2 W  setxy   ( xcor-of turtle h + x )  ^; h" K. n4 S, g7 _8 @0 n
           (ycor-of turtle h + y ) 4 l* E9 `' p: w9 S0 i
                          5 r5 ?5 P0 k2 F# f
                          
/ z2 l, d" v% g- W- ]                          ]
5 J' X( Q4 @3 g4 |end/ n5 j, `5 h) W, V6 X
; p( W7 X6 k" l8 J
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
, F0 M0 I- ~8 h应该是
  h* [# G  N- A. B  w6 I& G0 zask turtles [
9 Z8 O$ Y8 u( N: Q( L7 e  T% mif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
8 b/ H0 U0 k& P3 O' C! e( m                          set y  Dep / 2
- \' ]3 j& V. Q3 B1 f           set b  int (who / 5) * 58 U& m6 r  v8 E9 F% M' }8 ~1 h  s
    setxy ( xcor-of turtle b + x )
* [' G1 k: a8 n! G$ g! h" o- h          ( ycor-of turtle b + y )]]
# n; {$ N0 D& j& H9 i- j# @1 f: Jend& i$ U- e5 D: _$ O. s; D. ]
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-5 06:47 , Processed in 0.015479 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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