设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8901|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
. }* `) U  T. M$ E& ?6 q* V# G/ g: y  Y0 f9 h
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。: @0 F6 [: p3 s6 x" c! S8 q- Q7 ]
+ t/ G2 E5 P6 x9 u
turtles-own [a b c d k f g h" d! u- K# }- w
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle * i+ V( x' C5 _+ T3 l& _+ g8 g
]
0 c4 ?( l, H( c+ z3 n9 cto new
8 ?( O; T# P+ k  ca3 f+ N- I; i5 l& ?+ ?0 A
  crt 5 * num_of_building! M2 @: ?. J( y; m+ t: L
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
) {9 {! c) M3 F1 A) w. t5 l5 D  scatter     ;;keep center-turtle random positions
6 ?5 u+ q& u! C$ o  I3 G9 [1 @  unit_plan   ;;make up the building plan. u% [. C: y3 t+ h
end
- E9 g, V" k2 c( c7 Ito scatter
/ I( H* b5 X% task turtles with [remainder who 5 = 0]" S' e/ R2 k2 o; A- q/ Z, x
[
& z( X9 @  q. I7 P5 aset xcor xcor - 6 + random-float 15! ]  t7 M- [. ?8 A
set ycor ycor - 6 + random-float 15
" l3 s0 y2 p0 d! ~& o]
: Z& l( Q. X, Vend
! N9 r: y+ Z" K- B- @8 X) hto unit_plan
$ Q' W# E, x# I* yask turtles [
% U# S/ z4 ?6 |1 R0 l7 dif (remainder who 5 = 1) [set a who ! v/ F$ @4 {1 r, B+ a5 \
                          set x ( 0 - Wid / 2 )
* q% z1 g! X, Z# N* J) t1 T                          set y  Dep / 2 ]1 r5 J* w6 K! z- E/ x7 P
           set b  int (a / 5) * 5
- w$ z  z/ X1 S- @) Y: y    setxy ( xcor-of turtle b + x )/ |; V, e0 Q- |7 q
          ( ycor-of turtle b + y )
* A$ n- @6 ~0 }% sif (remainder who 5 = 2) [set c who- G/ {  P1 I- ~1 f
                          set x ( 0 - Wid / 2 ) : r% j. s& J$ A4 s0 |, e' f$ f
                          set y (0 - Dep / 2 )  ]
2 [7 \( {: m2 }- s5 u- r! Z2 ]( w# B2 d                          set d int (c / 5) * 5
! i8 ^2 V# v) l, B! P0 `6 K   setxy   ( xcor-of turtle d + x )1 g/ @" E& m7 {1 v5 A" w; C. |
           (ycor-of turtle d + y )
! v  C8 c+ M) u         
( |8 P$ Y0 O/ k& p( {6 ?            2 m8 ?3 }% h* a5 [4 p- q
if (remainder who 5 = 3) [set k who4 D. o! X& b6 _- L. x
                          set x( Wid / 2)  
6 f) ]5 p- [6 Z1 J                          set y (0 - Dep / 2 ) ]1 H% V. H4 F5 n7 u
                          set f int (k / 5) * 5
1 g+ ?. s& U; ~! C  setxy   ( xcor-of turtle f + x )
) q$ s3 L3 Y2 A' p           (ycor-of turtle f + y ) - Y6 r0 J' \. k7 D, q
           
% K: S, g8 r; `           : o; g6 m$ e. _6 h3 p1 a8 O! O7 Z
if (remainder who 5 = 4) [set g who4 D: }7 X+ e# n3 e0 y8 M
                          set x Wid / 2
) R) X. D# p5 }3 O0 @5 ~                          set y  Dep / 2 ]' @% O" T% K9 ~" l/ b9 q( {8 n' W  k
                          set h  int (g / 5) * 58 m: |. g$ H9 ~# Q# Y" s
  setxy   ( xcor-of turtle h + x )
: D# S. }- ?  Y! N! k% T           (ycor-of turtle h + y ) ( p7 j& @4 _; L: F" `
                          5 Z9 N2 I5 X, i; z8 }
                          3 X9 l; e6 I9 X) c/ B, R
                          ]
8 w0 K( W+ w9 @5 g2 t/ hend
/ S6 N7 q* M/ r2 f) O6 w2 ~7 V' x; a; w" @
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
! B6 j& _1 P8 b9 O6 u6 _, w) T应该是9 D. a9 q5 U: M0 f
ask turtles [& T& ^% Q' e# v2 @5 @: j
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) / \! o. q5 Z: C- g1 t8 |
                          set y  Dep / 2
+ N$ b4 t: [! c9 W# w9 Y( f) {           set b  int (who / 5) * 5: ~. M5 K- I* Q2 ?
    setxy ( xcor-of turtle b + x )" Y! u) t" `* R; N3 y; u
          ( ycor-of turtle b + y )]]- N* [4 \9 V0 T* |* b" k+ W6 j
end
- j4 g, W2 c6 A% s' D1 z2 m之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-20 08:10 , Processed in 0.021005 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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