设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7181|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。5 {: O  t7 M1 l* T
: M. Z4 i1 z- @) q2 X% V9 t
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
3 _9 z+ v. J% }: ]: d
1 q2 n, k0 _6 \7 c5 _turtles-own [a b c d k f g h
2 j% v7 z) {1 R. {/ q- g' j  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
# P' ?* n, R+ z8 \5 V( T; J]7 `6 }4 }' O. G7 |7 X
to new
: Y. e- p* b6 B8 Q# `" Y- _% \* p  ca$ Y. y5 Q' O7 U) p
  crt 5 * num_of_building
. F5 O3 w! d8 a  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
+ e/ H, w4 U# g/ g% q  scatter     ;;keep center-turtle random positions
, \' Z8 O! H2 ?3 Q. K, }, K, i5 g  unit_plan   ;;make up the building plan
$ {# g1 c& F, w  X/ a" o; N0 d1 Rend3 W5 R4 [: [% c" Z: |/ V/ _, d6 p
to scatter; P# K" [4 M$ d
ask turtles with [remainder who 5 = 0]
) E8 D! H) i, x. M8 J3 m[, @5 R& K8 n# L! R) p# p
set xcor xcor - 6 + random-float 15
$ p$ M0 B* M; iset ycor ycor - 6 + random-float 15
& k$ l5 \" z1 c: c" b]
% w5 g- @8 O2 a3 l7 ]end% R  K8 o' b5 I3 C: g7 v( V
to unit_plan
1 a' ^6 Q2 F/ A+ m) a; z! vask turtles [- \# h: `& ~, G( a; a4 D
if (remainder who 5 = 1) [set a who
, ]5 L4 C& v$ i; q# u8 L, u9 V                          set x ( 0 - Wid / 2 ) * Z9 Y) u$ L+ M
                          set y  Dep / 2 ]/ U- ^* k# @- ^6 Q+ J- @. ^
           set b  int (a / 5) * 5
% f& B7 _1 ?' Y( ^    setxy ( xcor-of turtle b + x )7 m" K. d, Y  v) ~; m
          ( ycor-of turtle b + y )
5 Q) T& P6 r. C) Cif (remainder who 5 = 2) [set c who) Y" x0 ~! _9 W
                          set x ( 0 - Wid / 2 )
' w& E  f  R6 S' M$ m9 H                          set y (0 - Dep / 2 )  ]
  c& }. m+ n  h& [8 J$ h" z2 A* H                          set d int (c / 5) * 5
* r0 ^( z# \& H! B& M   setxy   ( xcor-of turtle d + x )4 ]6 W. Z% i/ ?
           (ycor-of turtle d + y )
" R5 ~& |# ?' i# o4 j$ `" p          # x, ~9 T/ r9 ~& B" @, B
            
; ?5 D$ S# ?' G" I0 P( Zif (remainder who 5 = 3) [set k who
; P% U- z5 g. B" w                          set x( Wid / 2)  3 R; @# R  X" F% x8 M. W/ e
                          set y (0 - Dep / 2 ) ]( ^2 o! f) I2 r" n: K" x, l
                          set f int (k / 5) * 5
$ R1 z: E# \4 u0 X4 X1 o  setxy   ( xcor-of turtle f + x )9 V8 u  |# W8 [: @7 E( V
           (ycor-of turtle f + y )
0 Z8 T0 X$ q$ m; ^2 V           ( e& v  K  Y% w
           
0 D0 `) @& h' q. v1 fif (remainder who 5 = 4) [set g who6 s% N4 |$ m% e& ?
                          set x Wid / 2 1 H4 a! ?  w) m7 g  D6 h
                          set y  Dep / 2 ]
, {9 ^2 b8 ~0 c                          set h  int (g / 5) * 5
9 D" Q7 V* ]$ B" q3 E" K; U4 ?# j  setxy   ( xcor-of turtle h + x )
7 B0 d: [/ \% u! G5 z/ \5 W4 B# E           (ycor-of turtle h + y ) : [, P3 j3 N; m9 r/ l: J$ u7 C
                          
# L* \. h" W! v& j5 r$ N& V                          
) Y: c' D% A" O& t$ ]* M( D                          ]0 H* O4 D# [: @& S& K
end5 u" S7 u5 s  t1 [+ u$ m: V3 Q. K# y

# g, A' P' q- Y* l  \! e[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
( O) o' X! |) X0 F3 @; }% y应该是
; u( ]" l# J8 a* D+ v6 ?ask turtles [' i0 i+ W8 v* `0 R# \
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
1 B2 _+ _0 s4 h5 O) S$ t                          set y  Dep / 2 4 F0 j. A5 X# h: W8 x
           set b  int (who / 5) * 5
% S4 R" p* L( s! E+ u2 x  ]    setxy ( xcor-of turtle b + x )
) I; l- o9 ~% W& z8 Z' a          ( ycor-of turtle b + y )]]! S7 H2 d* m7 m8 y  E
end
: `; Y( H# A' H6 I之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-14 06:29 , Processed in 0.016736 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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