设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7882|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。8 o6 [; P6 V4 b/ V4 J/ P8 r! w
4 {$ o- k' s9 U2 t. V. ?0 |1 J$ G
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
/ v. t4 n) k6 a+ l7 A
- s: o" D* ^4 W4 }; Qturtles-own [a b c d k f g h- [# A5 _9 m' d" y4 `
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 6 h# ~6 c+ V- l4 g  u4 J1 v% H7 V
]
' U& N& w0 m% t7 r. Jto new% g  `" ~, B5 w' P5 i& Z
  ca9 L) J0 O5 B4 j$ F' v9 c; k. p+ q% P
  crt 5 * num_of_building
/ J; p' b) o9 y3 @! G  M. d4 J1 x- s  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]+ C6 a5 r, S9 Z- K8 T- \+ ?, I% N
  scatter     ;;keep center-turtle random positions 9 k2 b$ L+ r, o! W' q: o. h
  unit_plan   ;;make up the building plan. [; T1 D- Q$ N/ |; l7 q7 ~8 u
end! x! A7 I) i. R
to scatter
7 b- v, Y1 ~5 A- Y# I9 wask turtles with [remainder who 5 = 0]
* y; \( E5 U$ E! e+ p4 {& g' `[+ U5 X' e' U4 s" X
set xcor xcor - 6 + random-float 15* I# f6 Y4 x" I* X
set ycor ycor - 6 + random-float 15
2 L* @/ T6 u5 O]# t( w2 N9 R% {/ |! i$ m
end
6 h/ B& D. l, a- ^; ^to unit_plan 2 y( ~  n0 R4 I4 f$ J; j( M1 {
ask turtles [2 m# y2 I" a4 v! Y; ^
if (remainder who 5 = 1) [set a who
# R. a" h  C7 |2 r$ N, `0 I                          set x ( 0 - Wid / 2 ) & V2 f2 M+ |. R  X4 |
                          set y  Dep / 2 ]
+ w/ E7 r0 v0 `2 ?) q" i           set b  int (a / 5) * 5
0 a( Q1 I' _8 x" |    setxy ( xcor-of turtle b + x )
7 |* V" u, p5 M) S8 p          ( ycor-of turtle b + y )
+ Z* Y4 M% ?* Xif (remainder who 5 = 2) [set c who! p2 A3 V6 \/ N  K7 ]
                          set x ( 0 - Wid / 2 ) ; b0 r, }' A6 _
                          set y (0 - Dep / 2 )  ]- t0 N% M! G* ?3 f& m
                          set d int (c / 5) * 5
, y4 G' \. Z+ q# f! L) G& m   setxy   ( xcor-of turtle d + x )* a9 _. z1 Y4 j0 I
           (ycor-of turtle d + y )
+ ?- T+ K; t) ^0 C8 t         
4 ^" j' @" j& d# d            
. Z2 l$ |/ I+ u. C; I  k) a+ Yif (remainder who 5 = 3) [set k who
0 ]4 R1 E' j+ v; L+ {8 e                          set x( Wid / 2)  
1 \7 b( a1 s* h# J2 ~                          set y (0 - Dep / 2 ) ]/ I& V" R0 }: k+ ~( }1 Z% R, ^+ W3 I
                          set f int (k / 5) * 5
" M* V  y6 W3 L" A' t1 s! h  setxy   ( xcor-of turtle f + x )
2 G% q/ h9 ]/ a* m           (ycor-of turtle f + y )
6 F! H( o: U; s9 a0 ^           
1 h5 y5 c! ^% @' R- @9 Z* n           
* p" G$ e. B- E1 Xif (remainder who 5 = 4) [set g who- v  K8 @. T' C$ C+ N, R
                          set x Wid / 2 ( U% {- T( W7 m$ N5 ?
                          set y  Dep / 2 ]
4 |7 F3 ~" f( K+ J                          set h  int (g / 5) * 55 `# O8 E3 Z' A) x8 U3 L, J
  setxy   ( xcor-of turtle h + x )' G; F6 B2 d. M% T0 {1 M
           (ycor-of turtle h + y )
& ^4 k6 v- t" H$ y5 d- O% {5 N5 X                          ! g' s$ t/ ~" Y
                          
( M9 p# U7 `6 e/ `; Q  B# I                          ]- G, O- X  k( h- G/ V
end* Y( @6 N1 q4 S. \

; l# T5 t" k6 p1 k[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
0 o" O4 E3 D5 V应该是
1 V$ l* J: f( q* U' _4 C7 {2 Iask turtles [
) v& j: n$ O4 W) h& @if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
" F/ c, Y* u2 f$ \. {  a& U                          set y  Dep / 2 : ?  T$ B$ {* ?8 W# a0 V
           set b  int (who / 5) * 5
: n. V3 b. V+ q" U( M  J, S0 }    setxy ( xcor-of turtle b + x )
" R  R, s) i! @          ( ycor-of turtle b + y )]]% F- d( `( Q$ e5 B# O3 T9 O9 h$ |0 ]
end
' \2 ^% b0 ]2 ~& z之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-14 20:18 , Processed in 0.033740 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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