设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7273|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
# f, G# I$ W, h. f" c% V; t
( ]8 c9 q  h) @) z7 ?9 P7 d7 Y但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。3 i# _/ w: m+ V& y* t* Z" T" J! B
$ A* A5 ^/ c2 O" N2 ~$ m
turtles-own [a b c d k f g h
) u9 I: [! K9 }  Q9 E  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
1 a% f8 U0 e( A1 |]
; h1 z9 `$ \5 X' K' \to new) q* [8 g( w( V( b) C4 }
  ca
# S8 [1 d9 B" K: w4 v5 _" o, M  crt 5 * num_of_building
2 O- {2 C8 ^# [  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]: `9 I. ]+ m' j* `& z, Q' X
  scatter     ;;keep center-turtle random positions
% x) A5 X- s6 a' l; X' H0 Z  unit_plan   ;;make up the building plan* e4 M- g+ P# P1 R2 x* l" }+ n
end( `( C3 l, ^& y9 r8 v
to scatter
  _2 r& G2 U" \! o3 R" Zask turtles with [remainder who 5 = 0]& [& _( E0 a! S5 L5 ^. ?! i8 g
[
. h8 u! O- J1 M5 j6 `set xcor xcor - 6 + random-float 15
0 L- E) {% i8 [. a9 L2 r  Xset ycor ycor - 6 + random-float 15
2 p# H/ f7 ^# z  i( J' d8 q9 z# k0 b' O1 h]: W7 |3 r8 q: u  B
end" V) h% @, u+ R* e' f' {
to unit_plan
: {2 Q1 v5 A1 s* `- S! zask turtles [
# a4 J, N! N" a2 C/ P& Bif (remainder who 5 = 1) [set a who
, p1 l  Z3 b( c5 w( e                          set x ( 0 - Wid / 2 ) & Z) j3 M' @4 A
                          set y  Dep / 2 ]/ R1 F: `3 S) ?
           set b  int (a / 5) * 54 v: M, m2 c* Y, ?
    setxy ( xcor-of turtle b + x )2 C5 Y$ r  Y- h2 a) \5 s' \
          ( ycor-of turtle b + y )6 w& v) s* M: G/ \4 C
if (remainder who 5 = 2) [set c who
: j7 T0 E) h; `. A% I+ h                          set x ( 0 - Wid / 2 ) ; b, A0 e- ?: c, q* m
                          set y (0 - Dep / 2 )  ]
6 C1 A3 F7 G+ n+ ?( w6 B7 d                          set d int (c / 5) * 51 m" Z. o# k7 j, K5 R' o
   setxy   ( xcor-of turtle d + x )
4 _/ \) d+ e/ _           (ycor-of turtle d + y ) & b$ N9 ^* g3 X
         
6 z- Z1 n+ R8 K/ L3 z            
0 B5 l+ S# P! c+ l1 I# dif (remainder who 5 = 3) [set k who0 ]5 H  N. |; F- _, D9 d& \
                          set x( Wid / 2)  9 G( J7 q* _: L6 w( g. n1 P. \* X
                          set y (0 - Dep / 2 ) ]
0 A+ P+ |# L% A% R4 T# b                          set f int (k / 5) * 5
' C! M- I0 H* G8 Q  setxy   ( xcor-of turtle f + x )5 U0 }* s; q& Q" a5 j) w* L( f  g. \
           (ycor-of turtle f + y )
9 R; u% D* B* E5 J$ a& l5 B$ \' Z           
; o+ i3 o/ j0 z) C' l9 B& G           
" h  `" |% B( Q8 J. Sif (remainder who 5 = 4) [set g who
: D/ Y$ O7 t& T1 o% X                          set x Wid / 2 1 F: @% T7 D" n: Z) v& c& Z8 F
                          set y  Dep / 2 ]2 K! R, \4 i0 e6 w+ v$ _
                          set h  int (g / 5) * 5# B! W: m: k) |9 N7 L: Z* \- n
  setxy   ( xcor-of turtle h + x )+ ~* v# H1 D+ U) u( g, ^+ {
           (ycor-of turtle h + y ) 2 o- N/ l0 m: j# {' d3 V& z/ {
                          ; ?1 c6 H, f5 b
                          8 E$ d# g. g8 B7 R
                          ]
$ G2 x" ^0 a& ]- W3 u; O9 ]2 lend
! }' g6 l- F7 A. k, D9 A; m! U6 ^6 K8 l+ w9 P
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
7 p" C$ Y4 F4 ^$ o应该是
; {" A3 o! i) Z# w0 c; |ask turtles [7 X8 c- S# T" X* F$ }- o
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) * M7 U1 ^% C) n. h
                          set y  Dep / 2 , x  n' n* n( f  ~! @0 O
           set b  int (who / 5) * 5
9 m. c3 d6 X- _) k$ a9 p    setxy ( xcor-of turtle b + x )/ f3 u2 O3 w& [7 L, z1 g5 O
          ( ycor-of turtle b + y )]]$ v, f8 s9 ]+ q! J) b" R2 Z# C2 N6 x
end( K( [  U, k( @( U( p
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-24 00:16 , Processed in 0.019477 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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