设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7924|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。1 x$ e( Z5 i& J4 ]8 G- p

5 s, s6 @0 \! {4 K" p# C但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
& q! J, M7 t% ^$ b9 U5 R5 e( ?4 m. `- {
turtles-own [a b c d k f g h
/ r9 d$ \. b' P$ f, y/ Q( ]  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 7 y# G4 R1 X" @8 z' ~
]0 b+ f! `. ]( E
to new: N# H- P9 ^; A8 ^) j
  ca
0 a1 }& [$ C6 Z4 C; h  crt 5 * num_of_building& ^, ^  ^/ r! Q) K* z2 E# P
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]' s2 U; I. f0 @) w' c
  scatter     ;;keep center-turtle random positions + o5 w- R# t! Y, F
  unit_plan   ;;make up the building plan
1 K5 P- U! `$ j2 Q( V: pend+ ~, j0 v: U# ^! [
to scatter
" T& L1 h0 T, m$ ?( S5 oask turtles with [remainder who 5 = 0]
& B4 W- G" N% V  b  D5 s[2 j6 @2 Y, g+ m% {  e
set xcor xcor - 6 + random-float 15
; z* B- j# u6 h4 r# Yset ycor ycor - 6 + random-float 15
/ M) t6 h9 S, R' e1 f+ ]% C% W7 M]
$ ?1 b, n- w7 z3 Fend1 F! _! h' U! s& [6 N! S+ y% @
to unit_plan ) c+ W, E. _- C$ F) e7 f9 L
ask turtles [; s: V7 I2 ?; }
if (remainder who 5 = 1) [set a who ! a8 J4 y7 q* d2 F! `: u! K: B: Y/ {
                          set x ( 0 - Wid / 2 ) - }% j6 Z: w' V, D
                          set y  Dep / 2 ]. }) c& b' C& G4 D6 D
           set b  int (a / 5) * 59 c: D  b; W) t
    setxy ( xcor-of turtle b + x )
; t* o" `) d# R* S7 D2 }# [          ( ycor-of turtle b + y )  \4 D" {. q3 H  l
if (remainder who 5 = 2) [set c who0 g. K7 e1 V: c8 Q
                          set x ( 0 - Wid / 2 )
. \, e5 T* d3 X- w( k                          set y (0 - Dep / 2 )  ]. j( J, w9 n6 ^
                          set d int (c / 5) * 5
" @3 V+ i% w+ l( s3 r   setxy   ( xcor-of turtle d + x )
& C6 A+ A, m. F: r% N' F& ]           (ycor-of turtle d + y ) % t% e4 t2 h. z7 e
          " s+ C- {* T6 w- m( P
            
3 c. b1 G- {' \if (remainder who 5 = 3) [set k who
+ @; D7 i% D$ @  N& M                          set x( Wid / 2)  ' m# T3 k' J  ?8 S- D. v% [# d3 b
                          set y (0 - Dep / 2 ) ]
+ A& O' o8 w& [$ ]5 x4 R0 e3 J( u                          set f int (k / 5) * 5& x6 T2 c, I! X4 D7 n& b, o
  setxy   ( xcor-of turtle f + x )
/ V2 y- E5 V5 a4 _' {% F           (ycor-of turtle f + y )
0 F" y$ z) @9 @5 E4 M% a           ! d8 w# l2 f- o$ d
           " |5 n+ `: D/ q7 x
if (remainder who 5 = 4) [set g who7 }) l+ n6 `* r3 `  c5 o4 @. c) u* N
                          set x Wid / 2 % A8 n& `, O6 P; _& I
                          set y  Dep / 2 ]5 L# n3 S, @- g$ R% |5 r; E; z. a
                          set h  int (g / 5) * 5+ e' w5 D  H$ }6 c
  setxy   ( xcor-of turtle h + x )
* Z9 b8 \# s2 n4 Z; ~# j           (ycor-of turtle h + y ) ' c& i* ^8 \4 V. v) l/ m) {% T
                          9 z) z7 m$ q; F2 e3 Q/ v& @; n9 K
                          
  z! z# o! Y; v  s                          ]
6 e  ~: l+ m3 I" L* k* w' V$ k' iend3 p) N7 J: f, Q+ [3 n

% \; m* ~+ a" I: U" j4 y. C[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
/ v  B" b" q, y( w# H应该是% ~& ]9 t: q  I" W& N5 B0 \
ask turtles [
& ?& O, @, R8 P5 M( d3 K. qif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 2 j+ V& {" N7 y. f! m
                          set y  Dep / 2 - U# d  h; _6 u) w& i
           set b  int (who / 5) * 5( ~' T8 R* Y/ E, H/ l1 F3 \; W
    setxy ( xcor-of turtle b + x )
7 i4 U7 v! u3 z& B3 H          ( ycor-of turtle b + y )]]* _& M  `2 F2 N2 M
end
; J6 d. m* [  h8 m之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-18 10:46 , Processed in 0.018872 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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