设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8610|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
* \  e2 J; E# B8 x4 J
: o! A) C  o& m. l但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。& P4 b5 \7 }% f5 ^3 \

6 c: t% |$ U: @* {0 a# \7 l$ {turtles-own [a b c d k f g h
4 z2 W1 A8 J- [, n, Q/ A* N7 Y- B7 h* U  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ) t: h4 y4 X$ n* D: H$ }) e# m! O
]# O9 ]5 R- K: v& |, B, j+ S
to new( X+ ]- J- E1 v' o- Q+ \4 }
  ca
- K8 Z) K  ]" |% A: W. |  crt 5 * num_of_building
9 z) n* D/ g" e! K- G  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
8 O: F3 O: x6 u. B  scatter     ;;keep center-turtle random positions 5 B% k% h1 U& W3 F( j$ d
  unit_plan   ;;make up the building plan
8 V/ R7 a/ l9 p0 Q' [/ Gend
9 f/ D9 v  R9 [to scatter+ n* h3 R4 J# ?& f9 D$ ]% z
ask turtles with [remainder who 5 = 0]
, ^- ^4 m+ a1 t2 {[
! J1 K% w% c) Q9 _0 p3 ?set xcor xcor - 6 + random-float 15
5 R5 m% m2 \' U- H/ s' [" r4 ?set ycor ycor - 6 + random-float 15# v. y/ S4 W7 I* [4 x- W! [
]
  U( c$ H1 M; _/ `9 u- \end7 ?% p* G5 Y7 f0 [( j
to unit_plan % |2 L$ n- I! R8 \
ask turtles [
" p! @0 }# O- K, O  pif (remainder who 5 = 1) [set a who
  b4 {: ?; R) o$ a' [6 t                          set x ( 0 - Wid / 2 )
; {9 b: V# k. I% E7 J                          set y  Dep / 2 ]  ~5 }) h$ R8 r' h4 M
           set b  int (a / 5) * 5$ ]$ G' Z1 x3 ~9 N; V- a
    setxy ( xcor-of turtle b + x )
6 F6 P& K9 R% m          ( ycor-of turtle b + y )' I5 E! C4 x! A! @# o
if (remainder who 5 = 2) [set c who
1 S6 v& v; ~/ K                          set x ( 0 - Wid / 2 )
7 B4 y% c& J  E                          set y (0 - Dep / 2 )  ]4 s6 g' {! B0 j0 [& l- ?. @( k
                          set d int (c / 5) * 5
7 o* t% L! F( Q3 l# j& M8 {   setxy   ( xcor-of turtle d + x )
0 d! j& o7 M# n) U4 U9 S8 H8 H' x           (ycor-of turtle d + y )
6 N3 `( E) J3 N) _* X         
/ B. r; B% a& G4 }1 q            
: ^4 Z- @; v9 ^8 Z% Jif (remainder who 5 = 3) [set k who& u8 k" G6 F2 U, B6 d
                          set x( Wid / 2)  % G6 N3 {: e$ u
                          set y (0 - Dep / 2 ) ]
, ?: Y6 W. Q" O                          set f int (k / 5) * 58 q) T" Y; d0 k: M4 V$ i
  setxy   ( xcor-of turtle f + x )2 b: B4 D  U/ B5 P  n) ]4 U0 C
           (ycor-of turtle f + y )
; B8 a: _8 {& j2 i6 ^           
# l( e  M: Y9 H           ' I! ]. I! }+ w7 a
if (remainder who 5 = 4) [set g who
/ A; e: b  o4 Z                          set x Wid / 2 ! @2 ?6 x: g/ w, B# N
                          set y  Dep / 2 ]
# |! L# S& c; w" R6 m0 C                          set h  int (g / 5) * 5
5 n8 Y( B8 g6 y/ g% n& F8 f  setxy   ( xcor-of turtle h + x )5 N/ K( N& p/ O' d
           (ycor-of turtle h + y )
5 |5 S6 q! V0 }7 Q9 V9 a6 H                          
$ e% c4 N( Z  F                          
* J; F/ H! a( `& i$ R                          ]; o1 H2 T% T( y; a5 y" l& w# ~
end# K7 a( o/ P: s/ _* d

+ e& s- h# F$ i0 [0 v4 O[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,5 ]2 o! a3 p1 Z7 n* Q# U. b! @
应该是
/ {( d( y6 S& |4 l$ S* u: n6 D5 bask turtles [+ B' E+ B) D5 V( h  l3 G7 }
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ' |1 Y/ r- b% I' W) C
                          set y  Dep / 2 - W  X, c  Z1 n1 p$ M) V
           set b  int (who / 5) * 5
6 @6 R+ z$ E4 v" T0 C* f$ ~    setxy ( xcor-of turtle b + x )
+ L$ Z  ~+ R% w9 j- U4 Y          ( ycor-of turtle b + y )]]
  T2 b9 C; R* ?& |0 r3 Jend
" e* N: X6 G/ I0 p" |( q之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-17 03:35 , Processed in 0.016553 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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