设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8994|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
$ k8 d6 \- D0 g. e* ?, a# l; `7 v8 }: S% F- ^9 E
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
; g0 b0 k& y/ s1 n  M  r& z% j( M$ G* j$ g$ E7 P5 U1 c
turtles-own [a b c d k f g h4 _6 J' Q# I7 l
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
: y# Q& J1 }* r8 H]
* z# e; }$ I6 I* Q+ `: bto new. R, C3 R3 u! v1 c# F0 x9 W
  ca
$ S/ `4 g, n$ M6 |$ g  m  crt 5 * num_of_building$ A8 c7 Z& v) ~- r+ h- g1 E+ d
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]* W. ^5 [& \$ R# A
  scatter     ;;keep center-turtle random positions + |6 B" s' c$ A1 e6 Q3 M- S
  unit_plan   ;;make up the building plan/ _3 ^5 j8 \$ o1 }1 ?
end: b! n# G. A4 t" [* Z3 f& s: d
to scatter
8 M; c4 l$ \! G" \1 o3 Gask turtles with [remainder who 5 = 0]6 i) M6 c) v6 a# i$ \& V9 J
[
* f; J1 U+ k7 |# @: M# Yset xcor xcor - 6 + random-float 156 c' @7 M4 z3 K2 Z
set ycor ycor - 6 + random-float 15  o; i! J/ k# S1 B
]
% u6 J3 M+ o1 q' M' C3 Yend
2 G# U! J; ^7 J( e, S2 H/ |& M% `to unit_plan $ o) W4 {& W/ q
ask turtles [& Z2 s! W7 r- e- `) p" {
if (remainder who 5 = 1) [set a who 9 H6 t( t/ p% {/ a% Z
                          set x ( 0 - Wid / 2 )   e( c. f; u8 d. t6 G
                          set y  Dep / 2 ]& K3 g- Y2 O* ]) S3 U- v; b
           set b  int (a / 5) * 5
! U1 F6 |, Y; ^6 F6 }# |    setxy ( xcor-of turtle b + x )7 C3 z& Z  D5 S
          ( ycor-of turtle b + y )
" K# J/ o" b0 r1 ?if (remainder who 5 = 2) [set c who1 v; w' o- Q; X$ v0 F
                          set x ( 0 - Wid / 2 ) ( A5 O. X8 T( O
                          set y (0 - Dep / 2 )  ]
3 [2 {( x9 I! f: Y+ u2 ~" E                          set d int (c / 5) * 5% T* S% y9 o  m; |  n1 z7 j
   setxy   ( xcor-of turtle d + x )
& Y  T" s! ?( |" x/ s& ?1 G           (ycor-of turtle d + y )
% k; s* Q% W# H$ E         
1 }5 R* Z: Z# h' B0 N, ]            
0 |7 v1 T& q5 U4 O0 e* ]4 oif (remainder who 5 = 3) [set k who  S) R7 J9 N- M! ?
                          set x( Wid / 2)  
2 H# o  b4 O" u' y% M6 F                          set y (0 - Dep / 2 ) ]9 U8 k# i) _; p- H9 @& S* N6 j
                          set f int (k / 5) * 50 C; l8 V( b9 X3 b6 X3 v
  setxy   ( xcor-of turtle f + x )
2 x1 O# h2 r1 S6 S3 K; @           (ycor-of turtle f + y )
+ V+ e+ e# w0 C, }/ @! Z           & _; K* x0 m. ~, }4 Q% T
           . e. g  a! z5 n  r% `/ z3 @
if (remainder who 5 = 4) [set g who
& G' L* L5 b8 {4 O  v                          set x Wid / 2
( F$ d* f7 p  m                          set y  Dep / 2 ]: [0 {3 ^; r6 ~/ l
                          set h  int (g / 5) * 5
7 a( W! x5 R9 ?# O  setxy   ( xcor-of turtle h + x )/ V1 r! ~  s2 B4 }9 S' E" C
           (ycor-of turtle h + y ) - m0 u( s6 n' C& g+ s/ C
                          
4 f1 Q0 Q) C3 _; `1 K                          4 A" V8 i9 P4 K! l0 u3 \: `
                          ]
. u/ P$ s: D1 {; N" d- ~; x( {end( T$ q( e/ H, h+ |! _5 \; f
; P- k9 a+ L; d$ |" U: o; [
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
& ?9 b, }1 a. K( j- [' ?应该是
! ~% `8 p% m6 d: z9 o( gask turtles [, W. o$ `& \/ h+ K/ M
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
. h0 W, e/ W+ r! J                          set y  Dep / 2
/ r! j# m( q! z* X           set b  int (who / 5) * 5& R( I/ N3 N  N( ~0 K7 u( [7 R
    setxy ( xcor-of turtle b + x )
: B  @  }2 i  n          ( ycor-of turtle b + y )]]
, i6 k1 C+ a- p5 t7 v' j; A* s5 tend: a9 G1 a& m3 |* q
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-4 04:48 , Processed in 0.017909 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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