设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8830|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
3 v; W) B3 w8 h  a7 D4 G' L" H5 \5 O7 Z- w8 z+ S  \5 ]
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。4 E4 a/ c6 h. k" ^0 _

' T8 i# |2 o$ x0 z& ~+ ~8 Yturtles-own [a b c d k f g h
1 b2 M/ s5 V' ^/ ^: {! o- ~/ p. S( m  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
. e0 u6 k7 S& @( \]
$ g$ u( z" E! M# M# H7 E' Q8 S, ~to new. o5 Z4 P6 q3 h. N2 a  ]/ ]3 Z6 Z  L
  ca
  ?0 d2 K3 R' p  crt 5 * num_of_building4 ]! z; ^8 U8 U5 T, P* F  W
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
- W; a5 C8 }' x  scatter     ;;keep center-turtle random positions
3 p; T  j! U) h. }9 p+ g6 Z& B  unit_plan   ;;make up the building plan$ e* m% t  \% ~! P% q
end& S! h- y  \7 @' [5 k
to scatter
: W: S# n3 g* eask turtles with [remainder who 5 = 0]
& ]" K9 J3 V9 H. T* d5 o3 ~3 |  i/ X[
) Y3 t; P- e) s7 Fset xcor xcor - 6 + random-float 15
5 \' g. L% x. A% x1 t4 Zset ycor ycor - 6 + random-float 15/ v/ P  t. Z8 N+ z0 S: _! N
]+ ]) b# S) o3 _& A
end8 K. @& @/ [$ g) p, m+ r
to unit_plan 4 R% ~  O) w8 Z: H  f
ask turtles [. a6 R$ ]. _( ]- d* x; W
if (remainder who 5 = 1) [set a who
. @6 y' h# W# c9 m" m: b( R                          set x ( 0 - Wid / 2 )
2 E+ j8 k  q5 _& o9 S% D9 Q9 S& b) c' E                          set y  Dep / 2 ]% S- K1 E) X& X$ K2 J% @( z) n
           set b  int (a / 5) * 5
8 h/ I  {9 J$ ^, U! x    setxy ( xcor-of turtle b + x )& z" T" ^6 ~# ~8 `
          ( ycor-of turtle b + y )
% X+ U' ^9 `! Zif (remainder who 5 = 2) [set c who
6 h: m( Z$ b2 @* L9 X4 `1 {/ ^                          set x ( 0 - Wid / 2 ) 1 E5 S' |: a1 @7 N
                          set y (0 - Dep / 2 )  ]
  U' o5 i- G- O7 X                          set d int (c / 5) * 5
" D/ |  R& D( S0 l' T) o$ c   setxy   ( xcor-of turtle d + x )) j. ^9 b; L, G( l  s) D; H
           (ycor-of turtle d + y ) ) l- K6 C% a8 u" ?" J
          % @# N$ \" i4 y+ g! c7 `
            
, j5 v6 m" s* V3 J) i3 Z; w. Cif (remainder who 5 = 3) [set k who
' w. t% e) D" f% ?0 e                          set x( Wid / 2)  / r. U" ?9 f2 n
                          set y (0 - Dep / 2 ) ]
$ q2 {' w6 i2 n7 g                          set f int (k / 5) * 5
  T$ \* f) _2 H6 A! K3 p6 r  s  setxy   ( xcor-of turtle f + x )
0 }1 a/ y" a2 t! a1 f# d           (ycor-of turtle f + y ) , h6 X/ I: o/ I: I9 W# W
           
* Z$ q1 ]+ p3 Y0 \4 f$ S1 N9 }           
4 v3 v5 s+ u+ V( b( Tif (remainder who 5 = 4) [set g who1 f! X, M9 f( K" w
                          set x Wid / 2
: g3 ^4 x! k- F8 O. l                          set y  Dep / 2 ]
$ e; B( K! I& c4 l5 z, C/ G                          set h  int (g / 5) * 5; g! [5 o) [+ W5 ~- @' H
  setxy   ( xcor-of turtle h + x )
* N* k# L  J3 G; w2 i           (ycor-of turtle h + y )
* Z" O: v& t  E: ^$ U+ X                          
/ r; q- w" h3 T( n! N0 e+ S                          0 t; V' j1 |$ W: j  n
                          ]
% ?2 |& }, O$ a! J, D. Pend) c/ Q. K" {$ g' h" o

' R2 K9 ]! z' W: C[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
5 b# x8 T2 ]/ N4 O应该是
, b9 g" z0 ^9 Y1 Rask turtles [, g. g0 y( C2 i; h$ u8 d4 n
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
* F7 r& y; W& y6 \8 O; S# M                          set y  Dep / 2
9 a0 D$ n1 L+ l2 r8 ]7 d8 X8 s           set b  int (who / 5) * 54 `% b% w" X4 y6 B
    setxy ( xcor-of turtle b + x )
6 I. _5 d" n4 G+ i          ( ycor-of turtle b + y )]]/ N  [) G7 Q2 U5 Y* }
end
! ]9 R/ U  d2 D3 K0 M+ z之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-9 07:00 , Processed in 0.015475 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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