设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7272|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
  Y$ I. r5 i6 }- \/ C, O8 B0 F; K/ ?, w4 J3 L9 @5 H1 S
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
! X2 g! R# X3 W2 K8 I5 M: p) F0 ~( t4 u. m
turtles-own [a b c d k f g h; d" _4 E0 N  r$ ?& p
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
, X* p' c( G# q; s% F( F]
0 G$ Q% l/ m' X7 P. {: mto new* \# r1 Z- s4 y% e" _3 F
  ca, i% e$ Y5 n+ W) n0 p" L
  crt 5 * num_of_building# A- b5 b) ^& T) |5 @) V; V7 L% l2 h
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
9 k5 a$ V& \! C# H/ F2 U- M  scatter     ;;keep center-turtle random positions , @$ i& D) f9 E! A3 Q$ N
  unit_plan   ;;make up the building plan2 h  _3 V; \& S9 B$ G# {- H
end# P# e8 `1 R" l" y1 U# n! M* m
to scatter
7 o  e( j' S" o* lask turtles with [remainder who 5 = 0]( G) }& F1 J6 j9 b1 R" O  ^
[
# Y$ J# @$ L2 `% E% h+ J' D0 Pset xcor xcor - 6 + random-float 15
1 r" ~4 P" ?$ @' yset ycor ycor - 6 + random-float 15" {7 e6 R4 p5 a% a0 h
]
/ t4 W+ G+ W' @" H+ `9 Gend
4 ~* |4 {- l* x! I/ j. d$ L& Mto unit_plan & `9 C- M5 e  S% }8 R3 [7 m5 {
ask turtles [
6 F, J: \* f- G# ^if (remainder who 5 = 1) [set a who
" B% u# G3 B+ A$ Q! p6 S3 h: P* j                          set x ( 0 - Wid / 2 ) ! O7 |2 C* J. a0 T) |5 F' Z
                          set y  Dep / 2 ]/ k3 z7 H0 L9 x% D  D
           set b  int (a / 5) * 51 A9 @& _  J8 ~+ h( j" @4 M( }
    setxy ( xcor-of turtle b + x )
4 H& ]% G5 c  c% F8 m3 f7 A          ( ycor-of turtle b + y )/ D2 m4 \& s6 a- X1 [
if (remainder who 5 = 2) [set c who
0 v- v5 }' z9 [1 d6 x                          set x ( 0 - Wid / 2 ) : r6 Y9 _& I- U. c/ F6 x
                          set y (0 - Dep / 2 )  ]
: g/ D6 c# W* N! f                          set d int (c / 5) * 5
' s. j3 g, M; c7 l! `   setxy   ( xcor-of turtle d + x )
: @6 |1 n  p$ R9 Z- w$ J* c3 C           (ycor-of turtle d + y ) & G4 h& e) }; d6 N3 v! s! L
         
& f# N+ ^' V0 i0 ]  d            # m' ]3 K2 T6 n- N, j  k$ Y, `& X# V
if (remainder who 5 = 3) [set k who5 V7 k  y1 z' _. l" r  g
                          set x( Wid / 2)  
! w; |6 C; E$ `; w, W( Y                          set y (0 - Dep / 2 ) ]1 }$ g5 N9 O# C4 v! l
                          set f int (k / 5) * 5
( b0 U# l" V: N. _5 ~. m  setxy   ( xcor-of turtle f + x )
; j6 U3 p* `" h1 l4 V% ]- v           (ycor-of turtle f + y ) ( K4 w2 H" K  S5 `& H
           
0 G( ?9 r* x5 {2 Z           
3 D) S* O5 C+ `1 dif (remainder who 5 = 4) [set g who
) v+ B( |' G% i4 Q# M- p1 y+ l                          set x Wid / 2
' i0 T% ?% p8 v0 t9 }                          set y  Dep / 2 ]7 h; e5 {% ]) G8 V# M4 J
                          set h  int (g / 5) * 5+ C- t# U" S& k. }( K; H" a
  setxy   ( xcor-of turtle h + x )5 b1 {4 i* L' k; v# y
           (ycor-of turtle h + y ) * `' r$ f, {8 E4 l/ L; ~( U" B0 ?
                          2 ^1 d. m# c* `1 Q6 N- J5 I5 F
                          
: x7 N. O) u( s                          ]* I3 x7 N8 {. h/ u0 e
end! ~- B. |/ q3 E
9 [: J+ n$ }2 X9 j, g
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,7 H) A1 m7 b, V6 _4 U+ l
应该是
" k* G9 S8 a% @1 w1 `ask turtles [& m5 g( a2 N( m* H* h
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
) _  D6 k2 Q1 U                          set y  Dep / 2 2 \3 }2 [1 ^- _
           set b  int (who / 5) * 56 [6 a4 p1 j& U  p* b2 T( o
    setxy ( xcor-of turtle b + x ); Q! o6 U# j' i5 s# q! P0 N
          ( ycor-of turtle b + y )]]
- L6 v& \6 l$ h2 b: lend
. B9 ^, B4 f4 |. d之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-23 18:18 , Processed in 0.020230 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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