设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8035|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
- g0 k' U- r" M+ ^- e' [  {2 Z; q
$ J0 k/ z# x3 C1 m4 m* o- K但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
9 @' }5 R0 L( Z- o, H9 q/ }9 D! A, E2 u1 g7 h% [5 |, ]7 V8 N8 |- p
turtles-own [a b c d k f g h
1 _  u$ _; C# b$ N* U0 i9 @- Y  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
+ B7 c& o: Z# Z  O4 f$ G) K1 @. }( H]
% i" J  d, A9 X/ W3 _# Eto new
" F% O  i! j% ~$ m% F2 q# t; M% l/ x  ca
# i+ g3 g, e: w0 I1 A; L  crt 5 * num_of_building
) O& r: s9 o" @  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]0 C, [' G- D3 A/ O
  scatter     ;;keep center-turtle random positions
" ]+ N" @& f& I* G( ?/ ]! M: F  unit_plan   ;;make up the building plan/ S2 E+ r$ S" [* K5 v5 L  L" I
end: G. W% C3 ~4 W: c1 I/ s
to scatter
7 c1 B4 C$ P1 ?4 n: ~- j( sask turtles with [remainder who 5 = 0]
: e4 n+ W0 R! ?/ y" e. b7 e& N+ E[
& D8 g# J# w9 Z9 a1 l3 s* ?set xcor xcor - 6 + random-float 15. n0 P0 f5 x" ?- L: x5 z
set ycor ycor - 6 + random-float 15
( X9 l# s6 V0 x/ p  k, ]]
1 ]1 q( T  S! Uend
  E5 D0 P7 N: z- k8 I% Z  t$ zto unit_plan - h6 e( d+ L1 }( v% Z
ask turtles [
& p3 q5 j! ]) X9 \6 d0 Wif (remainder who 5 = 1) [set a who
2 Z6 F. r0 y# T6 k7 c. b. _2 L2 p' a                          set x ( 0 - Wid / 2 ) ) E0 k1 `9 K) E/ {) B
                          set y  Dep / 2 ]
$ a1 C$ A3 M% `8 X5 V) F  V           set b  int (a / 5) * 5% T' w# {+ k/ Z
    setxy ( xcor-of turtle b + x )
5 o3 H9 l6 p8 w  R! {$ y          ( ycor-of turtle b + y )4 t2 \% m; x' f: n1 N3 D( f
if (remainder who 5 = 2) [set c who9 {8 z7 t; t8 t" o9 e: @
                          set x ( 0 - Wid / 2 )
# Z- q! m: W5 g2 R- F. k                          set y (0 - Dep / 2 )  ]
2 N7 u8 s/ v, k6 T8 h                          set d int (c / 5) * 5
/ T3 T/ H: l# }: N  ?' P6 V   setxy   ( xcor-of turtle d + x )
1 K  c# c8 z0 N# a           (ycor-of turtle d + y )
2 [3 O1 p4 [0 z0 S- D1 N5 W          9 E  ~6 t/ e, _2 q/ R; t
            + N4 g# [- ~  J; T5 p1 b4 v
if (remainder who 5 = 3) [set k who
0 `( [* v: A% g) G5 t  S                          set x( Wid / 2)  0 p0 K! G3 j, F# }( |( Z% z5 V( h
                          set y (0 - Dep / 2 ) ]- C# ^# h. r9 F/ {0 C
                          set f int (k / 5) * 5. t% J9 m; @$ L' w# P: z
  setxy   ( xcor-of turtle f + x )
6 f2 L5 ~; ~  p  b7 o           (ycor-of turtle f + y ) + t" `. M8 j5 g) S
           5 y0 I% p5 U# @  J
           , g" X: g) k' g
if (remainder who 5 = 4) [set g who
4 b' G$ P" j0 v9 y" U# m, D4 O                          set x Wid / 2 - h2 J% I4 K+ n5 ?6 m0 T- \
                          set y  Dep / 2 ]
% x8 [  ]3 C- n! ]4 T4 V                          set h  int (g / 5) * 5
3 ^/ T8 ^0 l  ?+ F* V7 B  setxy   ( xcor-of turtle h + x )
; k; @* \6 ^5 B# B# n2 s. M           (ycor-of turtle h + y )
$ z/ A' F, B" [" u4 R                          $ B+ f4 }" D0 g# C3 \; d5 h
                          - x! f8 J  W, _6 h+ K: x* l
                          ]
9 K0 s$ c2 W5 D$ `2 H) u5 f/ eend
5 n& ^& F9 ^: v5 G3 [" N* Z* {4 u7 a) `# _1 B3 b
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
% ^9 p% B% j, J  r+ g9 b, z应该是2 f5 w# E" \6 w; G  ~$ B
ask turtles [% B# I8 R, e  n7 W6 h1 w) p
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
4 L: }7 c0 P! i$ k1 e8 @1 i8 u* F                          set y  Dep / 2
' H$ R0 `$ a' N  ^" O6 F! ~           set b  int (who / 5) * 5
2 \$ V- I$ [% h+ n/ [! O    setxy ( xcor-of turtle b + x )
; W2 k5 r) L( K/ M3 w          ( ycor-of turtle b + y )]]
$ e- W5 L4 {' W- J7 Cend" C0 V  w0 ^. z* ]5 f. p
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-30 18:23 , Processed in 0.017474 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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