设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7641|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。) s& z+ N6 w- a3 A6 J

; M6 z: `9 K$ j但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
- I& K3 R. k7 ]! i7 y# `% A6 z
, X# }/ `- m% z. n' _$ j, yturtles-own [a b c d k f g h
/ r  D3 E" M9 q2 o4 M  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
/ b1 X( u9 q# |" Z/ e! j]1 q' j' c8 J. f: S/ B% w
to new" W8 z% a& @6 ?# \3 ?( |9 J
  ca$ P+ h; i" P$ {" l# c/ o
  crt 5 * num_of_building2 r7 m; J3 o# A1 y9 W
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
* |7 q! t( ^9 ~5 ~  N  scatter     ;;keep center-turtle random positions
9 ?5 j; e; Y; z  unit_plan   ;;make up the building plan
/ L. M( ~% S) @end5 _/ o+ t: w1 c/ M% D
to scatter6 t9 j3 Q3 s; o6 E* q  K
ask turtles with [remainder who 5 = 0]1 k4 R% h7 x, L' P2 h/ J
[7 V( C2 g7 u2 t3 q
set xcor xcor - 6 + random-float 15
( s0 a. }) o! w- L) l8 mset ycor ycor - 6 + random-float 15( Q# O9 P; e) o. [6 s/ W
]
$ {; T+ t2 N4 k2 E0 _+ l2 ^end
; W! u& J' H6 d8 Yto unit_plan 7 I: [2 l! `7 z# |$ W. U- T: S
ask turtles [" w8 A" |& \5 s( V- F3 ^/ s8 U8 `' Q
if (remainder who 5 = 1) [set a who / x1 E- t, |0 v% d
                          set x ( 0 - Wid / 2 ) 8 B& ^! a4 j4 }
                          set y  Dep / 2 ]
3 O/ V! u# C8 z3 N0 Z           set b  int (a / 5) * 5
% o) e( A  S+ Z% U! ^    setxy ( xcor-of turtle b + x )5 f; C' z5 S' H) S9 {1 A, D# ?! O
          ( ycor-of turtle b + y ); g1 o. ~" @$ M0 U8 r
if (remainder who 5 = 2) [set c who. F6 x2 K! ]" b# m5 H8 W  U
                          set x ( 0 - Wid / 2 )
3 b: t/ f$ d; p+ w+ f                          set y (0 - Dep / 2 )  ]
9 @( f2 {7 o8 A4 H! s/ E                          set d int (c / 5) * 50 [: t1 a- J0 O& Z) i/ H
   setxy   ( xcor-of turtle d + x )
) c. D$ S2 J* F' ~( R           (ycor-of turtle d + y ) 1 o% j( j) k* ~) a) e
          . @) H. q6 _9 b/ k8 a4 w+ E
            
, A. w7 ~' Z% O5 D* dif (remainder who 5 = 3) [set k who
% m6 k1 o! B2 F( F                          set x( Wid / 2)  
7 \+ t: |4 r( ]                          set y (0 - Dep / 2 ) ]7 {! E+ o/ O! j) ]: V
                          set f int (k / 5) * 5+ F  o9 A3 j, R9 \, ~. E
  setxy   ( xcor-of turtle f + x )7 J9 \) {; o4 ]+ c8 x
           (ycor-of turtle f + y )
2 J( o  R1 y/ a. i( t2 @4 c           $ b6 k) V  q1 e7 T' r6 r. g* |/ t
           ' H2 V, M& }2 U
if (remainder who 5 = 4) [set g who9 X2 }( S; |" `: W/ a
                          set x Wid / 2 + t5 r. H, F" k' u) r5 r) o" y
                          set y  Dep / 2 ]
. t- e* K7 Y2 [% z  p                          set h  int (g / 5) * 50 m  S' S& \, c- c: B
  setxy   ( xcor-of turtle h + x )4 e! z) j- [. ?
           (ycor-of turtle h + y )
, Q; b$ u# U- H! r) s: U                          0 n% ]0 O( [4 ]9 Q' Y
                          3 j+ n) \: q4 s# M# S% ^7 R+ ]
                          ]
$ x+ \5 y0 D# ?: Z9 c2 Lend
( F& O( z: ^4 t! d8 w: n: H; U; C1 E; d% y& x% f/ _
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,% Z$ I7 a9 {+ s- _( ^- k. a) k
应该是4 X; O4 p2 x# D7 ~9 y" ]
ask turtles [
, n& v" Z2 w; Q0 S- ^0 @, xif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
$ u5 L7 s* r, m0 B                          set y  Dep / 2
( G5 y5 e' v: i, `! i2 J           set b  int (who / 5) * 5  x, w) N1 J$ S+ m+ G' n% E! f
    setxy ( xcor-of turtle b + x )
% ~6 c! N) L7 c: }! C4 L          ( ycor-of turtle b + y )]]$ ~; j+ E/ o/ ~; k+ d& M% a% A
end
. ^# N5 w/ i; K, X3 C之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-10 02:11 , Processed in 0.015815 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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