设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7809|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。; E8 v$ I4 ^% j4 b  j* s' W
5 Z, A, C# d" ]# z
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
+ T. H4 C' Q, F0 F5 X. G2 W, b/ Y, V5 V3 T* [. O. U# d
turtles-own [a b c d k f g h
" o/ _& p% d( _; i" p& ?  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
8 q- R0 B) u3 i) q4 P1 ^]
% g2 O% B. K+ }+ u8 j$ `# Gto new& E7 a7 o0 v0 }6 i% \; l: p
  ca: c$ x& n- G6 P& A" D: N
  crt 5 * num_of_building
& A1 j" t( f3 q, z8 x6 k; _  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]6 C* I" A. X6 o4 y( H( Q6 O. y
  scatter     ;;keep center-turtle random positions
, p# l& ^1 p1 L+ D. z# @5 w  unit_plan   ;;make up the building plan
2 ^! s8 R" Y4 s7 ^0 C' o4 g% Wend$ f2 M: n# ?/ Q0 [5 k- i' i4 k9 a
to scatter
5 L. Y7 g+ Q; X8 L! _$ e3 uask turtles with [remainder who 5 = 0]5 T' G" S+ r$ K# F0 k
[; M$ G( o9 M* t  d4 A
set xcor xcor - 6 + random-float 15
2 f; G" D/ Z  l1 r% H; g  Wset ycor ycor - 6 + random-float 15
( E0 {: @* W7 [], N- N# N9 q% A6 b% h
end
7 t1 U$ _- F0 Y: O: Nto unit_plan 2 Z; r( `; ~5 h
ask turtles [" _  e  M% n0 L! b; K! }  u6 u, U( p
if (remainder who 5 = 1) [set a who 6 M2 q* G$ I, v) [6 f$ V1 E
                          set x ( 0 - Wid / 2 )
. T: r+ J; x4 _! x/ c                          set y  Dep / 2 ]
8 D: Y! V" |; r, Y9 @/ D: M# R9 }           set b  int (a / 5) * 5' C' V+ k5 b! Z. {  n* a
    setxy ( xcor-of turtle b + x )2 C2 Y6 z! A+ W
          ( ycor-of turtle b + y )% E, b  h# C  n
if (remainder who 5 = 2) [set c who
7 v% N$ M8 e, B$ T8 v                          set x ( 0 - Wid / 2 )
' v8 |/ `" L, ?9 P8 [. ?# ]' N* I                          set y (0 - Dep / 2 )  ]; s+ D( c* R$ B6 m
                          set d int (c / 5) * 5
+ p$ G8 g" |# k6 {1 y$ I: F   setxy   ( xcor-of turtle d + x )
0 X+ b- \! ]1 I0 d& X           (ycor-of turtle d + y ) 3 @# S% u- K; ~% d8 ~" ^
            W8 u+ u( o) B% }0 T
            
% p! e! N. P' {4 Q. b3 Z0 q. vif (remainder who 5 = 3) [set k who9 l0 f! ]! L) K3 b+ o
                          set x( Wid / 2)  " N9 ?" T) A2 C6 J& Z2 c1 ~$ o: i: B  ?
                          set y (0 - Dep / 2 ) ]
* T5 c" q- b+ _! N5 Q: b                          set f int (k / 5) * 59 C/ ~8 W* O0 R; \  V
  setxy   ( xcor-of turtle f + x )
" k1 C* V0 p6 q- v4 j" D4 p1 o9 _/ @( R           (ycor-of turtle f + y ) * w1 v: U/ ~7 n: U8 Y. }8 s& E
           ( P# a" F( R( k$ a! z6 s/ w7 z
           
% s* E2 d% p. r5 L0 bif (remainder who 5 = 4) [set g who8 O% I9 U: Z, ?% W/ U) f- ]/ M  S: i
                          set x Wid / 2
% ^7 m3 q) }' l( ]/ p& Y4 @                          set y  Dep / 2 ]
; }1 u; w1 U. n3 j  W                          set h  int (g / 5) * 5
  _0 J/ m, q2 n9 l( |2 ?3 c  setxy   ( xcor-of turtle h + x )
- p0 Y3 \7 W8 P9 e  o; p           (ycor-of turtle h + y )
* `5 |9 ^6 X( A0 k                          , p5 @6 j9 B) O$ p) A
                          
+ D. f! \' `+ S& H                          ]) h1 \0 a9 Y; e+ u6 x9 b
end; R2 g1 M8 n5 o+ @" ~$ H* i: H' [3 W
% ?% p' `+ Q; D/ |; e* t# N
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,* i1 A# x6 A% H/ e
应该是
) o3 M7 @. e# R/ e6 ?ask turtles [
# w: t" W  o2 N' ]if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) / q% e* [7 W/ i* Y: d( J* x4 v
                          set y  Dep / 2 7 v" ?6 _  b) P% J
           set b  int (who / 5) * 5
  z0 }6 b* L) C+ d! y& q# v: p    setxy ( xcor-of turtle b + x )
3 J( x3 ~. ?1 y          ( ycor-of turtle b + y )]]) ~. _, [1 y; E% x5 W" i
end& r+ j) `! Z3 K: Y: H
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-4 01:09 , Processed in 0.017255 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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