设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7737|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。3 f+ h/ Y$ s2 a: D6 V/ x( p

5 k! I/ _8 g+ _. I# i2 I3 U1 {但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。! G% L1 A$ _' _3 i& F

$ Z/ t/ s: Q: A7 m' Jturtles-own [a b c d k f g h
+ ^) j- E0 b* ]8 v  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
+ T8 b8 G4 a2 S, r$ n/ u$ b. _]
" A8 l3 v( M3 D2 z: Z% A: q9 A* }- ?to new4 Q0 w( w4 G" w4 n# W
  ca
& f. |/ K5 C  L" t, G- _6 u  crt 5 * num_of_building, [2 ^) T5 X5 Z8 E0 L  x
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]0 Z  t2 B1 E: y7 a
  scatter     ;;keep center-turtle random positions 3 N, p$ z$ W; d, t( d, s/ |
  unit_plan   ;;make up the building plan0 m( j/ _- h5 q
end
7 z3 L3 [  M( a- Jto scatter
& P# C+ N' m' C& s( r; h" }ask turtles with [remainder who 5 = 0]
- `+ r  R5 \/ ^. l[
3 Z/ b2 E/ ~) l( @set xcor xcor - 6 + random-float 15+ |( W* j- A8 W
set ycor ycor - 6 + random-float 154 R* I+ j2 [, I
]
; W# `. ]) R( G' d, O7 W/ E  h1 bend% X5 p  P, N+ x5 Y
to unit_plan % g: g% W; M$ D9 h
ask turtles [
- O) A# E* D" J; B' E5 [if (remainder who 5 = 1) [set a who
( N2 m+ A5 Z2 G5 q* w                          set x ( 0 - Wid / 2 )
3 `7 x8 y! S, j4 `- c# X, p2 A                          set y  Dep / 2 ]
' r/ M3 t$ S# [           set b  int (a / 5) * 5
0 ~5 \3 n3 N! X% Z% X1 m  h# S+ I    setxy ( xcor-of turtle b + x )
- u" g$ F9 `7 P  n          ( ycor-of turtle b + y )9 }4 w) d& T) y1 J' `: c9 x9 I
if (remainder who 5 = 2) [set c who6 B% }  e, E  R
                          set x ( 0 - Wid / 2 )
- @4 `# @( I6 D, n  T- ]                          set y (0 - Dep / 2 )  ]( c5 m2 N  N6 ?( m0 i& m
                          set d int (c / 5) * 5
2 e+ p( B  N5 A) G* a   setxy   ( xcor-of turtle d + x )
! g# G, Z: }; F8 W7 ?- |2 \/ {           (ycor-of turtle d + y ) . b% F3 K0 c; D0 w
         
& Y- w1 e! r, G            1 R9 H9 F3 G2 E; \+ J# G
if (remainder who 5 = 3) [set k who) K6 R( n4 s+ }& x% A# O
                          set x( Wid / 2)  1 G8 B6 o! Y- m
                          set y (0 - Dep / 2 ) ]" c, C! m$ y/ \* F- c0 y
                          set f int (k / 5) * 5! P' I6 U! l* I& L- [+ R! y, S
  setxy   ( xcor-of turtle f + x )
& V2 R( N) F( p% u- f           (ycor-of turtle f + y ) ; R. F( A; O1 t1 k6 G# d1 z
           
) o9 c5 g! q6 d. B0 b+ M           ; {+ i% X/ f* R. Q; b# u7 A" t
if (remainder who 5 = 4) [set g who
$ B0 J6 m) z0 n& t' B9 C0 p5 n$ G  U                          set x Wid / 2 , V6 D9 Q  ?; A" ~# f$ X
                          set y  Dep / 2 ]* B' G+ V# N" @. `3 o
                          set h  int (g / 5) * 5+ r- L8 `! c+ V; z
  setxy   ( xcor-of turtle h + x )
6 u9 ~+ M) J7 ?! B+ {2 y. F8 C. w           (ycor-of turtle h + y ) 5 T) }( u5 t5 w8 c% e* y9 J/ c$ T
                          
8 U7 e& F% y7 v                          
* [' j$ S5 S" X' E# w8 [3 J% ^3 g! |3 j. D                          ]. c! V* L6 x- C& M. |- h  ^
end1 }" a! X. {( a( M6 y

7 V' n. U! v+ S- n# M[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
: w2 j4 `( ]0 g- ]/ K应该是
1 i. z" J1 Z4 X. v" hask turtles [3 v" ?4 Z) G& ]8 `
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) / Q" G7 {2 T- ?3 e2 o  j+ e& b
                          set y  Dep / 2 ' X1 m8 h/ K2 F$ N8 J* ]
           set b  int (who / 5) * 5
4 P$ u+ \/ R" I6 \9 f' m  M    setxy ( xcor-of turtle b + x )
4 N/ A" x, J* j$ [3 T          ( ycor-of turtle b + y )]]
" {4 p( x: r+ q: g& l# uend2 U1 E9 W- R& J7 y. t
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-21 10:13 , Processed in 0.032046 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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