设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8176|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。1 e- @" _( T( Z$ e
2 C/ s. _) d. L0 v% u, t2 o8 ^8 V
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
4 X3 T" h) C; I' _% p( K! a7 ~  g# j' R* Y, N
turtles-own [a b c d k f g h
; j5 n) `- I  r! o, `2 X  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
( ^- i, t! J; X; J  F]( t: I  z! ?$ n4 u! r  q0 O% `& Y
to new
- y9 d: H7 e: l5 L1 `; h# L  ca* r; [& J* R) V& S
  crt 5 * num_of_building. k9 _4 G2 \4 U+ W1 S
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
( Z. i5 n- x3 Q! U; p& B  scatter     ;;keep center-turtle random positions 2 I8 o7 {$ j( C/ n
  unit_plan   ;;make up the building plan
+ t- C/ u; {; M! S$ ?: M1 q- C  lend
: ]" S- F6 _4 K; ^3 B# o! yto scatter0 J! _" j9 v/ z6 M8 p5 K
ask turtles with [remainder who 5 = 0]- v$ |9 I+ H, d: Y! g& [
[
3 z' G3 z0 G' `set xcor xcor - 6 + random-float 15
3 X3 N' t, }( o6 c& S: K2 Y9 yset ycor ycor - 6 + random-float 15
# K. m/ A( W9 S: Z! U4 Z+ k, h]
( z3 }" G" J/ _1 Kend
  S0 g# _; {2 F& {3 ]2 y6 D6 E7 A' uto unit_plan : y. l. ?5 d( Q  p+ l5 G$ r
ask turtles [
7 O2 K/ Z" }4 H- Tif (remainder who 5 = 1) [set a who   L+ [# V7 ]+ z- T. b
                          set x ( 0 - Wid / 2 ) 9 X0 c8 I9 D9 h: M' x0 o
                          set y  Dep / 2 ]
1 C# Z0 g0 O- f2 H. J           set b  int (a / 5) * 56 ^# E1 S0 f+ y) `& c
    setxy ( xcor-of turtle b + x )
1 S. a/ ?5 C7 |: w  f; {          ( ycor-of turtle b + y )
7 e2 p; n  u% n; ^3 i4 ]# [' a! Oif (remainder who 5 = 2) [set c who
5 o" p% M$ ~  b3 }; j' i1 l) n                          set x ( 0 - Wid / 2 )
. z5 r8 b) g5 u# Y8 N# n                          set y (0 - Dep / 2 )  ]
# ]7 W1 y7 n- r: g                          set d int (c / 5) * 5
) @2 ?, d9 ^  {' A+ H   setxy   ( xcor-of turtle d + x )
  @) k; Z  Y. m: H( v           (ycor-of turtle d + y )
4 E0 @) \; V& M& C* A+ `          " S# Z9 D. ~: Y5 S7 O6 A. y0 G6 Z( X
            
. J# @+ ?+ r1 cif (remainder who 5 = 3) [set k who
. p1 O9 W2 G  g% X7 [# r/ o- p                          set x( Wid / 2)  ! u  }! Z9 R0 e2 _
                          set y (0 - Dep / 2 ) ]
1 \$ n- b; x$ U; `$ ?# M8 v                          set f int (k / 5) * 59 Q6 _3 P2 I  i9 {- `: L5 ~# H0 d
  setxy   ( xcor-of turtle f + x )
  |" [1 Q8 P' g* n$ E           (ycor-of turtle f + y )
9 o8 J5 v" i! D2 J           6 R1 Q# B5 o" G- r
           
* x& e/ G8 |& Bif (remainder who 5 = 4) [set g who" W( E, k% C+ B7 y; K% k
                          set x Wid / 2
% x$ ?- j6 r, ?. u3 f  g5 s                          set y  Dep / 2 ]
; \- O% i* V8 @                          set h  int (g / 5) * 5$ O6 ^, H+ v; F7 C
  setxy   ( xcor-of turtle h + x )
: s  p# m4 N( m3 P( T" O           (ycor-of turtle h + y )
$ l# |3 ^) Z; U) y! y7 a$ m9 A                          6 {3 g0 J* }- h' g# _6 z/ H
                          3 X& t$ G5 a) p6 O! V$ s: O
                          ]/ _5 Y  D, U# K; }
end
9 t$ W( m9 \  c2 W- u
# g7 z6 {+ n2 r5 C9 h( [$ e[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
4 S' v2 e0 e) }9 y1 j. ]; v应该是" q- h/ m) T3 ^  e
ask turtles [( Y4 H0 m8 [. c
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
8 u/ P; o9 k$ B3 Q2 k& O8 {                          set y  Dep / 2
  `: Z, \+ R8 q( F9 c; E           set b  int (who / 5) * 59 ~: e# C, m+ p0 U! n( n% i
    setxy ( xcor-of turtle b + x )
% u/ y: Y- G2 e( ^" U/ M          ( ycor-of turtle b + y )]]' l1 t$ N1 l5 w8 k$ S4 u. N, W
end. j" E% P# N" g( @
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-14 19:38 , Processed in 0.023972 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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