设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8920|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。' N8 ]2 u  |. @+ K; }

' y: w9 r: E& U. {4 R7 s( l但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
9 S6 p, U  S! e* @. O4 X7 e& t" m" {# D" @
turtles-own [a b c d k f g h1 e% C7 R# S. \$ @; N3 J7 p
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
7 r9 @& ]: i) J" c2 j]  f) v- w3 m' v2 z
to new8 L# Z9 G3 b* d; K
  ca! u4 `: d  u% S3 x" A
  crt 5 * num_of_building
- k3 g, p: @, H$ O% p; k- [  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
2 V) q0 h& f3 C" J; w  scatter     ;;keep center-turtle random positions " s; t" z6 H. a$ b
  unit_plan   ;;make up the building plan, Q8 ], \0 G$ R8 `+ u/ m  e
end/ g6 M) x2 |/ V% ?8 L
to scatter" n1 \1 Y/ c: {4 l+ c
ask turtles with [remainder who 5 = 0]' c. t. a, [1 F6 T* C, o
[
: |+ n4 F4 H- s. h1 ~set xcor xcor - 6 + random-float 15& x( F, W! `; I4 v6 H
set ycor ycor - 6 + random-float 156 A) z* X1 M: E8 b( ~
]3 N0 \/ w6 B- v3 h4 L8 t" p
end% D+ B9 d4 ~8 c8 M9 ^, Q/ C
to unit_plan " F9 X3 Q/ T" }0 j5 H8 K
ask turtles [, d4 F: H# M* a) F* B! k. V9 Y
if (remainder who 5 = 1) [set a who
: Y- p# r& D5 N3 j                          set x ( 0 - Wid / 2 )
' c" h9 N4 ^- m/ S4 b% ]                          set y  Dep / 2 ]$ z8 a$ h" U1 ?7 ?6 ~. g
           set b  int (a / 5) * 5- t  e' U( K6 f2 |( Z3 {
    setxy ( xcor-of turtle b + x )
. d: C# z+ ]+ I. _4 _( c          ( ycor-of turtle b + y )& W# q+ F7 Q" n5 R1 s
if (remainder who 5 = 2) [set c who" [6 L/ h+ [* |" g' z. w
                          set x ( 0 - Wid / 2 )   m: Z' s& o' W: s8 d& p7 X. d" w
                          set y (0 - Dep / 2 )  ]5 g3 A$ k, |( }. ~0 O
                          set d int (c / 5) * 5+ D" h! M, M% a( M0 x
   setxy   ( xcor-of turtle d + x )# q  O/ k1 T5 x+ X1 N+ T
           (ycor-of turtle d + y )
, ]' |" j- e" V8 H          2 t# t" o" r: |+ }) t# i$ t- j
            
/ t& k# e& H1 K# g6 }, O3 ?0 Qif (remainder who 5 = 3) [set k who
) a6 s$ o  r# \0 e" M+ j" K                          set x( Wid / 2)  $ t2 w6 `: ~  w7 c
                          set y (0 - Dep / 2 ) ]
8 o" G/ i* o2 c6 j% p                          set f int (k / 5) * 5# V" k* D8 I0 j- C( J+ X
  setxy   ( xcor-of turtle f + x )9 E! x) w1 _2 q( S% m( Q
           (ycor-of turtle f + y )
& V% a0 @; Z9 [           
, e) Y4 g! a2 T           ) }& n$ [9 c- S) p. c& |8 G: ~) @
if (remainder who 5 = 4) [set g who# R/ X- W, N% M
                          set x Wid / 2 8 _6 I  _4 A3 }6 w: ~
                          set y  Dep / 2 ]3 w- g! m: r$ ~9 F3 t
                          set h  int (g / 5) * 5- `# c) U2 R4 N
  setxy   ( xcor-of turtle h + x )
" a4 @6 p0 |) T           (ycor-of turtle h + y )   v* n  [, X( G8 Z" q+ A4 y$ K0 |
                          " ]$ Z# U; |# [  E, ^7 ~
                          $ S2 M( [4 \4 B$ }0 `5 j! F
                          ]
; F6 c6 h8 r4 L9 H/ K1 xend, n) c0 a$ y1 v
2 _* P4 x  o$ N
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,0 G( p1 Q; _. n9 N& M
应该是1 s/ y& _; [/ v- M
ask turtles [% s9 y1 j9 E! Y5 u- C9 K& Z' g
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) : L& [0 P+ G8 F1 ~; O
                          set y  Dep / 2 8 |" P# C+ x. u, t' M2 T
           set b  int (who / 5) * 5$ J* X, h' h, `
    setxy ( xcor-of turtle b + x )
/ d9 f- G1 r+ G+ G          ( ycor-of turtle b + y )]]1 t/ c6 t5 V, r6 X
end8 H. p/ j- ?1 F, Y8 e
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-24 17:30 , Processed in 5.739018 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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