设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8065|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。+ ~0 J/ y8 z" }9 d4 @9 X6 k
; e6 }" ?/ S  i! C8 n
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。5 \/ v! @: ^, ?: Z8 K- `, G1 \; {$ H' G

6 a6 R- P9 \; [2 o+ W$ z/ j3 Yturtles-own [a b c d k f g h
: @1 c7 u$ W$ u  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 6 g4 b  h/ z, f- i
]
  Q/ g9 J: r  D1 K$ Yto new0 H4 k! M6 i. R' `: d5 n5 _
  ca
$ B$ Q2 l& p& E5 f: p, L  crt 5 * num_of_building( v, l. y, y7 X% {9 c2 a
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]' G: P$ q: ]+ L' s
  scatter     ;;keep center-turtle random positions
2 i( ^  g. x2 O$ I) C/ A. N  unit_plan   ;;make up the building plan- C% H6 [4 T6 o& M; s
end6 T1 \3 h- \2 z9 q; G8 ^
to scatter) S, S8 T/ `& g4 a
ask turtles with [remainder who 5 = 0]
3 y9 Z8 ~# H3 K[$ s- @! D% ^( |+ j. v- p
set xcor xcor - 6 + random-float 15
! ]/ w' X4 x" {' H4 b' d7 Uset ycor ycor - 6 + random-float 15$ q) ~$ h$ a1 w/ X
]
- S0 F) l4 @7 w5 E" _end: _0 g  M: z3 g
to unit_plan % B, {: \0 Y7 N  z+ P
ask turtles [9 H* a3 f  J5 ?8 H9 f
if (remainder who 5 = 1) [set a who
" F; `) J% ?& Q                          set x ( 0 - Wid / 2 ) 8 s8 G( h% b5 l0 k4 ]4 {6 N# r& C
                          set y  Dep / 2 ]
( m& c$ f' P" V( a1 }" v; a           set b  int (a / 5) * 5
6 a' \/ o- b* l: G  @    setxy ( xcor-of turtle b + x )
7 h0 K1 j- ]4 M7 _$ M          ( ycor-of turtle b + y )
' m$ z1 q. c8 }. f7 F' bif (remainder who 5 = 2) [set c who
1 e' p% W" ^& C8 R7 C; d! ^% j                          set x ( 0 - Wid / 2 ) 0 c  K- u2 H' ^9 p  I# R. Z
                          set y (0 - Dep / 2 )  ]
% G5 b/ B5 B$ }$ V% _                          set d int (c / 5) * 5! e5 y+ `, M. g
   setxy   ( xcor-of turtle d + x )6 i# Q8 o: v+ @
           (ycor-of turtle d + y ) 4 E5 h* C) }6 \, k2 [
         
3 h1 l4 |: i$ l6 q6 d- x            8 Y; S. A  d# Q$ Q& p3 ^
if (remainder who 5 = 3) [set k who* y, l( t# V) `3 z6 G* }8 Z% J: J$ q
                          set x( Wid / 2)  4 u) A! ]) b: H& R5 @4 t
                          set y (0 - Dep / 2 ) ]
- h9 S" L; }9 Z1 c/ z* l                          set f int (k / 5) * 5$ D$ h) ?5 P/ |; @: Y
  setxy   ( xcor-of turtle f + x )/ ?$ B4 r0 i. A
           (ycor-of turtle f + y )
+ e! }! N) [) ^) a0 A8 o$ ?           
" \- p( {* U; }! T$ x- J7 u  A" q           / S! e# n; c% g. w
if (remainder who 5 = 4) [set g who9 U% u& ]  e7 W! D; n) L
                          set x Wid / 2 / i# [' W% S' D, X! e8 x3 W. E, E0 f# q3 C
                          set y  Dep / 2 ]
6 d# a8 \( Q$ m7 D                          set h  int (g / 5) * 57 C. ~4 T, `. U5 G  l2 u
  setxy   ( xcor-of turtle h + x )$ K; m# K) K& {9 T  C
           (ycor-of turtle h + y ) 6 o0 s& ]: ?  O- }9 ]- r
                          
) H+ I$ ^$ e1 N5 {                          7 h- q, M7 i, X& P) C
                          ]7 [1 {, A( \- W0 Q% ^( N1 Y
end( o" L% W8 p' B: @8 b  r% z
) W4 I; T+ B! H& l" m+ g
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,7 A4 n' H& g/ e7 i
应该是
" z9 d- ?! O9 mask turtles [
$ ^* _- Q; v/ u3 Bif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) , P# G* r$ W% l  }$ x* n
                          set y  Dep / 2
  \, U$ k" C/ f5 @- k( T4 E           set b  int (who / 5) * 5: \8 D3 f( G0 y* V& I
    setxy ( xcor-of turtle b + x )1 F9 I4 s: G& l& D: p% V& N2 S
          ( ycor-of turtle b + y )]]8 r* J$ {+ m$ U# ?, a
end, y4 _5 R- |0 y7 k" n5 d
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-3 04:08 , Processed in 0.017990 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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