设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8717|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
2 w  R/ W$ X* {& M. |! Z) o( o5 t5 j. c7 J' W8 g/ O0 s! ~+ p
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。' E/ H) P0 ]6 v% [2 C# ?% a+ |& i( A' ?
1 d  ^8 f' X5 _6 H6 z% j
turtles-own [a b c d k f g h4 w. l( [9 u4 y
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
) y% R7 y3 U8 R0 T]0 q3 h9 `6 [% ^) `$ R. f
to new- @& R# q: B% V7 E1 b& @0 w
  ca/ \2 U- Q1 F8 n7 m& i9 t$ L: {1 O
  crt 5 * num_of_building/ r  |6 v4 Y) _4 \# C1 b  P
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
3 R3 v& [+ `- U+ I: Q  scatter     ;;keep center-turtle random positions
" I+ `+ e# r& l6 y! \& M  unit_plan   ;;make up the building plan/ X" U5 Z! p) g
end
) f4 c  k) i9 @7 @to scatter
4 q8 ~' h6 k& L7 c7 ~* M! |  Task turtles with [remainder who 5 = 0]
; u/ B5 |& R& ~) a[% s) ?% V0 V+ U% D( n9 U$ z
set xcor xcor - 6 + random-float 15, F  |' }8 Z) X2 C: @
set ycor ycor - 6 + random-float 15
/ \! p  S) ^3 ]; M& [  C& X6 d]
' W3 f& G7 }3 L! j  B0 rend
; ~3 m4 }1 M, V- Qto unit_plan   }9 D4 |9 m" q4 P9 W& w
ask turtles [
  H% T9 b( L* o9 jif (remainder who 5 = 1) [set a who 8 d$ P- A# ~6 C! v" `3 S: ]# x
                          set x ( 0 - Wid / 2 ) - V, v! O+ o* h! Z' ~, k% {
                          set y  Dep / 2 ]
) Y( f& }# l0 J+ _# b" p) u           set b  int (a / 5) * 5
6 C6 \. o0 V( z' ^$ w8 U  G* s% P5 V    setxy ( xcor-of turtle b + x )- [, j- H5 A1 S7 D! r2 H
          ( ycor-of turtle b + y )
  O; ~* y6 K* K3 x4 D" iif (remainder who 5 = 2) [set c who
9 s# r# }6 a- ~4 r4 ]2 `0 A                          set x ( 0 - Wid / 2 )
$ e/ {$ X0 t+ ^                          set y (0 - Dep / 2 )  ]
7 N' I9 \9 S8 c) v                          set d int (c / 5) * 5
7 z4 t# L2 w" k: j: G   setxy   ( xcor-of turtle d + x )' b3 P) O9 m6 s& k1 e1 `2 |
           (ycor-of turtle d + y )
: z5 U  }5 o4 k' g5 ]          2 Q4 W* G1 j# e; u/ X! m9 E
            
1 `, S& p: S1 v; D' [if (remainder who 5 = 3) [set k who
# Y, P' w$ Z/ v                          set x( Wid / 2)  ; U: n! ]+ Q: ^( @
                          set y (0 - Dep / 2 ) ]
3 B8 F4 ]1 p8 K                          set f int (k / 5) * 5: O* _& z( q3 x: ]/ W& D
  setxy   ( xcor-of turtle f + x )4 m4 ^+ ?7 V/ d2 R
           (ycor-of turtle f + y )
+ l7 r6 j' B! ]! J* ?" @           
9 t2 N+ Y1 D3 \- r* }) e           ! n( G3 t+ }7 F0 G6 c) A
if (remainder who 5 = 4) [set g who( w2 D4 d5 h6 [
                          set x Wid / 2 * F5 W: V: e' k" ^5 I
                          set y  Dep / 2 ]
' ?" }! r0 ]4 {                          set h  int (g / 5) * 5
& z' y  q* S! W! d" X2 h8 n0 I3 {  setxy   ( xcor-of turtle h + x )
6 y* h& {1 a, d' N) Z           (ycor-of turtle h + y )
+ f0 m7 X; x. L4 }3 h: O' u* t                          4 f9 W# d; L7 i! G
                          & t3 X; `8 _! l2 T. v* R
                          ]
4 H1 @$ \9 I9 I  `: o7 z- Gend
8 y  R& L% c+ w# H- ~8 ?/ Y. O& x
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,) U+ k7 r  n% m( G- _1 ?# q. Z9 i
应该是1 R) K6 B/ _* h$ i) m
ask turtles [
, n- e1 g9 d8 O* P/ {+ sif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) / q* {% C! I$ `* h: s4 @
                          set y  Dep / 2
+ h& D# d3 e5 Z2 W' ^           set b  int (who / 5) * 5
  k) Q! @, G/ H2 I. [/ d' T2 `" w    setxy ( xcor-of turtle b + x )( R4 y1 w1 S& f" {
          ( ycor-of turtle b + y )]]: A, A3 T- |. u) k) x+ t
end7 [+ [3 L8 H( U' S; f' \7 O( \' w
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-29 00:17 , Processed in 0.013401 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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