设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7428|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。) M# L( x4 s; U. j; W; s- o
. I) T3 X; W5 H& m
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
9 `+ X& Z# L! S( }1 @: R) S# o2 @# ?
! z% e' q& l% I5 Rturtles-own [a b c d k f g h$ Q9 s, y" Y$ E2 u1 O! T
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ; r% n. X+ K' k! Y0 I# p2 J
]
# b: @& t9 X; h1 G4 W$ Qto new
# ^2 L% c3 X2 i0 g* `: e+ n  ca
' F+ d! U# C# c& E. i  crt 5 * num_of_building4 A: _* t6 X! C0 B) H3 a7 f
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]  b: D: N  q1 u6 g9 F/ J
  scatter     ;;keep center-turtle random positions ( R5 y& J* H! g) u- i) W3 L0 j
  unit_plan   ;;make up the building plan* R/ Z% m% e' o- l$ e$ C2 \( q
end
; F1 G: z% U; x2 n) v9 b0 s' xto scatter
0 A2 B# p' x5 y: I7 ]$ O4 sask turtles with [remainder who 5 = 0]
0 G9 u5 h9 _4 \2 }7 l! E! A* K# e7 b# u[
6 t: N/ n  r0 Y( ]9 d0 ^  Aset xcor xcor - 6 + random-float 15
8 E- e9 E; I, a) Xset ycor ycor - 6 + random-float 15+ e. W! a/ a7 }  f& Y
]5 M3 `, ^9 L# U; [' \% W
end# E& K/ \0 l' l" ~5 J
to unit_plan
5 R  o9 V# p. p* }' c! Q' A% gask turtles [
, v; x" K. d$ rif (remainder who 5 = 1) [set a who
: ]9 F  A* C" p5 y/ f. ]7 L" ^1 [                          set x ( 0 - Wid / 2 ) : u' x6 E. k) F, Z; y9 f  S
                          set y  Dep / 2 ]/ s% \- D; d3 G  f. K: K, @
           set b  int (a / 5) * 5
: l6 n- q! X" m" c; _    setxy ( xcor-of turtle b + x )
) q- j5 p* j1 S" n; r5 d4 N          ( ycor-of turtle b + y )
! o+ U6 W9 y8 Z" W0 Mif (remainder who 5 = 2) [set c who& J! g( ~- ~( Q' z2 u/ q1 X: E
                          set x ( 0 - Wid / 2 ) 8 G3 C3 F1 O& P4 X/ z2 I/ M7 @- [
                          set y (0 - Dep / 2 )  ]
& |  M  F& S# J" q                          set d int (c / 5) * 5  L& X6 h$ }4 B2 ]% M
   setxy   ( xcor-of turtle d + x )2 |& F8 E+ h* b6 ]" Y2 T
           (ycor-of turtle d + y ) 1 }( j+ B5 W& j( g- [9 I
         
, [* l1 n) A  |) F            / P+ v2 `& U! N3 k+ }0 {: v  E& o
if (remainder who 5 = 3) [set k who- s! U( n- |3 N4 O2 o
                          set x( Wid / 2)  
$ M. S( M4 H$ K1 r; F  B7 B                          set y (0 - Dep / 2 ) ]* N& ^6 n6 L$ _& d
                          set f int (k / 5) * 5
; E4 l6 S) W! h4 A- a( ?  setxy   ( xcor-of turtle f + x )
; ?5 _$ u9 ]2 q. q: n1 {           (ycor-of turtle f + y )
/ s1 Z: t# i& ?$ a7 g0 y           
6 O' `! I9 d5 @: [4 J. K           
8 B1 r2 ?5 I& O) R( u* h  y. bif (remainder who 5 = 4) [set g who
- y5 w1 P; t9 O4 R                          set x Wid / 2 8 [4 y5 _+ s, ]' M/ O! J
                          set y  Dep / 2 ]8 U6 }2 y, e( R: }& s* d" a$ y) ]
                          set h  int (g / 5) * 5% Z! A6 g, J; j" ~% Q
  setxy   ( xcor-of turtle h + x )
, N8 @# }6 o# Y: ?           (ycor-of turtle h + y ) # N/ T5 }# M; j7 q2 ^/ m
                          . L- P* P/ i6 i6 [( Q' E, G
                          5 T0 {6 x4 u5 M2 S0 f
                          ]# v; R0 F5 t- {, _# M
end+ G% b) Y$ P) E- j) f
  I; m7 E3 J) f& k
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
( s, B2 f, u" ?/ _5 Y应该是
8 l5 \9 X7 W: y, y3 j3 sask turtles [4 x: l  `5 L5 E; l; Q4 x+ L0 ]
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 6 ^5 a9 V% Q' [; x7 B' M
                          set y  Dep / 2 ! W: x8 g5 F! X5 B) C
           set b  int (who / 5) * 5* V0 C$ Z7 B. J$ n; F9 P8 q
    setxy ( xcor-of turtle b + x )
6 L# o$ _3 `  I6 }$ G4 S          ( ycor-of turtle b + y )]]
' R/ \/ c% M+ r) f# x4 xend2 O$ O9 P6 Q, [9 L- A
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-10 08:56 , Processed in 0.020950 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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