设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8324|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。. r/ J0 G6 ^2 R5 _
# [8 k" p4 J  v7 @
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
- V1 X/ g. E# D/ G8 \# |- X3 {1 `
turtles-own [a b c d k f g h
& l! _1 g$ q7 b. i: W/ V* z  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
1 u( w1 M/ `6 s0 o: K  Y]
7 T) V) z5 [3 N7 q: ?) e) G. h* n$ G1 H9 ~to new; T" X$ M3 R; D- H$ g4 s4 b
  ca/ E) ?- ~! O3 K: o3 S. n8 e
  crt 5 * num_of_building, V% \" |9 I6 p9 k5 A6 [
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]' j, @; _0 Z- W: @
  scatter     ;;keep center-turtle random positions - k1 }/ j, N( W- W0 A
  unit_plan   ;;make up the building plan
2 x/ L  q. |& M( c( P9 m4 B; Bend
$ m" p: R  C; `to scatter" C6 v5 @% o# _& M. b, }- P
ask turtles with [remainder who 5 = 0]
9 Z9 e2 ^9 }. C, W2 D[- m) U$ X  S  w* d2 M( O8 x' c% \
set xcor xcor - 6 + random-float 154 B& T% n% i& A7 Y( r
set ycor ycor - 6 + random-float 15
; ~; s  h0 N: {5 F2 I]1 h$ q, ]" F6 S5 v
end" W3 c2 Z$ R- E3 d& ^
to unit_plan
  b$ d$ r- Y& s4 S. G2 Jask turtles [
, }6 |8 a) }0 y! x. C* sif (remainder who 5 = 1) [set a who
- ]1 o& W1 ]; P                          set x ( 0 - Wid / 2 )
( u# e) {* y7 r+ Q4 ]- C                          set y  Dep / 2 ]
1 o; g" [$ a* r' t           set b  int (a / 5) * 5
# J1 h% H8 Z2 _' e  Q    setxy ( xcor-of turtle b + x )
) y. n, \4 E4 p, u! K; }          ( ycor-of turtle b + y )4 h- Z, f* F1 a1 y% G" G/ [- w
if (remainder who 5 = 2) [set c who, h5 R* \4 B  B" y, N* q
                          set x ( 0 - Wid / 2 ) ) F1 r* M& U/ |) T% Y9 p- D
                          set y (0 - Dep / 2 )  ]
5 z$ e" e0 \3 N                          set d int (c / 5) * 5
) D5 O" B1 Z( V   setxy   ( xcor-of turtle d + x )
2 q0 Z5 {6 w% i) R  l7 Q           (ycor-of turtle d + y ) 1 h% M  X/ H( n9 |! I! D
         
, v( K5 p1 |8 [+ L            
5 Z9 Z, t8 m8 h* o+ r" A" o+ n$ uif (remainder who 5 = 3) [set k who7 x  F( J' k+ ?4 ?9 c- w
                          set x( Wid / 2)  5 P% g  ?7 Z" i8 K9 k. Q' G
                          set y (0 - Dep / 2 ) ]! u) L/ c. N  L* \3 g' a
                          set f int (k / 5) * 54 W+ V6 p0 l4 M/ E
  setxy   ( xcor-of turtle f + x )
" B4 u5 ]! t  L) }$ I- j           (ycor-of turtle f + y ) ' z& K, E9 \6 R
           
! P3 r( K; K/ o0 [           
+ ^: {3 E) v0 u2 cif (remainder who 5 = 4) [set g who4 f2 M* ]# w& @7 ~7 B2 \2 Y; \! n. x
                          set x Wid / 2 1 i* k0 |3 ~) V  c( W
                          set y  Dep / 2 ]
4 v$ _7 ^7 f0 P2 n6 u" }; F                          set h  int (g / 5) * 5
* g3 F: }: T+ j) u# F1 \/ ]$ W7 f  setxy   ( xcor-of turtle h + x )- R. m5 e: A, u5 o+ ]
           (ycor-of turtle h + y ) ( L, q' d+ \. T) i
                          . ^+ j2 h. s# u* y) D' l+ S) }& A; w0 B
                          6 l# U! ]) W7 h( o: G/ u' n4 k4 v
                          ]
+ a6 w( O3 @, H1 F# B/ cend
, M5 L$ d+ |; \6 e' ?' e; a
- I5 w) W2 R) i  S% d1 o[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,# E! R4 X3 M1 ^) ]) g% N  H
应该是
; s7 ~- c1 E1 Lask turtles [
" {. c, D" r0 N. ?) m9 xif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 5 w. C1 l5 n! b3 f7 q, j* k+ x
                          set y  Dep / 2
5 _1 {  `% F% t% j* w4 y2 l           set b  int (who / 5) * 51 G% N% Z# [2 Z3 F* y2 N
    setxy ( xcor-of turtle b + x )
) G0 g. Q7 ~8 K# [* R3 v' L, f          ( ycor-of turtle b + y )]]8 A) \8 M3 W: W1 \9 {& _% s, T
end9 L4 A9 p: G0 b0 [
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-7 11:02 , Processed in 0.017758 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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