设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8998|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。* F& L3 w8 D% e+ C3 b1 M

: d/ P0 x- Q8 T6 Z9 ]; c- Y但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
: |( q# r+ t, L8 H2 X% O6 V( q/ X  I3 @0 j; T2 @8 H- L
turtles-own [a b c d k f g h
$ Z4 h; M) H9 A4 k  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 3 ]' Y3 _/ C+ k/ u+ D
]
. |; a, o8 m! U( Y" B3 L3 l) |2 uto new2 w  F6 ]. a' S
  ca. Q# A; R3 ^$ l$ @# e  o
  crt 5 * num_of_building
- b2 \) {* t8 i% p- o1 O) y  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]], `4 q- j$ M+ L2 N
  scatter     ;;keep center-turtle random positions
+ W# C1 g# M5 V6 _! g  unit_plan   ;;make up the building plan
+ @  ^' a; S3 Z5 L( ]end/ |# P0 ^% Q( _% p
to scatter4 A$ D1 p1 i. |/ q! F0 @) V
ask turtles with [remainder who 5 = 0]
  D" {8 O, e7 J[
' s- @+ Q/ b: R! T6 v$ w" h# U+ Lset xcor xcor - 6 + random-float 157 {( p+ j4 Q% V
set ycor ycor - 6 + random-float 15
5 C+ K* p" u" p" h: i/ n3 H$ V]
0 R( n! Y2 I& xend
% `3 @- s! @6 Ato unit_plan
/ |6 H# [  B5 z* B3 E- A, cask turtles [+ L* Y! H6 B, v) i- c0 T/ W0 Y3 h
if (remainder who 5 = 1) [set a who
2 D8 J6 t1 @2 Z! t7 Y- u2 o# i1 A                          set x ( 0 - Wid / 2 )
, d: F- u0 a  U/ w  `                          set y  Dep / 2 ]5 x. D* Y: ^0 m! t
           set b  int (a / 5) * 5; J# s" D. @+ o2 x9 b
    setxy ( xcor-of turtle b + x )
& V" m: U3 }8 d          ( ycor-of turtle b + y )
1 [8 ~. H) ]! K9 I) M5 Z1 {+ \! vif (remainder who 5 = 2) [set c who
: i5 ?1 f% }" X% w                          set x ( 0 - Wid / 2 ) % O: n& r% Y) ?& V( V" V) l
                          set y (0 - Dep / 2 )  ]
3 l2 S6 Z! I' T' b0 |                          set d int (c / 5) * 5) E3 R4 t3 n2 J5 d: E: G* l3 O
   setxy   ( xcor-of turtle d + x )8 V" n8 K6 N6 G4 V: H% D
           (ycor-of turtle d + y )
/ ^) j1 N6 s2 V0 K, |$ H5 {, t         
  `4 G+ l, t; q9 }7 G* D. }            5 L1 \! l. c3 @% {
if (remainder who 5 = 3) [set k who; n! C5 _  a$ V
                          set x( Wid / 2)  3 o( a# O; P3 v+ N9 F- I
                          set y (0 - Dep / 2 ) ]
9 v3 M% o5 M+ y$ R* w) m# k                          set f int (k / 5) * 5% H" n# u) s# t( ]
  setxy   ( xcor-of turtle f + x )
8 K+ j4 K. _. ?8 |4 O, W           (ycor-of turtle f + y ) / `, Y9 g, R  K
           ! q: K2 t  X3 ]% N: E% r# e5 ]
           2 r- O; }7 l& T( q9 }) u$ i) }0 E
if (remainder who 5 = 4) [set g who  W, M# W0 ^6 T4 X4 Y# Y$ X4 |
                          set x Wid / 2
8 h- ]1 R9 @5 W0 p4 {                          set y  Dep / 2 ]" P$ I! J" N, [$ |
                          set h  int (g / 5) * 5% ~' a3 Q3 }" s+ ?. _
  setxy   ( xcor-of turtle h + x )
0 ^! f4 u, M: P$ M0 B" X           (ycor-of turtle h + y )
" }9 E% {4 o" M                          
2 z5 Q3 x8 W4 c- r                          
' M( ~" M7 [1 [' P3 X, e                          ]8 a' D- ^+ |$ M; m# [8 z* m
end
' n2 Y4 ~: l1 u; R( ~- U) ~& Q* n$ |% Y& _* a, X9 g. [
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了," J! w' G5 x2 G1 p" G. e+ B8 ^
应该是: @$ r0 q& N% |. X; d. m  @
ask turtles [
; G6 K9 I: L4 T! L( D) F" w- {; dif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 8 `$ b  _6 ?' n' O0 T% W
                          set y  Dep / 2
# ~5 d+ m0 r% P# U# a( Z           set b  int (who / 5) * 53 r: j5 T( _7 n$ I5 F& j
    setxy ( xcor-of turtle b + x )
" y# D; f% i4 E4 z) C          ( ycor-of turtle b + y )]]
- j1 ~; z" T1 t  nend' ^& K$ ]8 b4 W- p) O
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-4 11:29 , Processed in 0.019100 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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