设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7500|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
" T' @- `2 L" x
: c6 q$ j  ], ^; P$ l) p( s& y但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
! G/ T" U$ S) u6 l5 o/ f! E
4 R  L/ n0 v8 k7 `6 l) U0 @" xturtles-own [a b c d k f g h' n' ?  q5 h7 v
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
# |" t& z4 P8 _& g/ a* []
4 x+ t) z2 c/ uto new
* m8 x0 O) P! F. Z( J5 _  ca
9 T; Y# d! |# U8 H: Q. y  crt 5 * num_of_building# Y( B4 x' V& U9 f0 X' t2 q9 W
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
4 T" n% n4 t( {' i2 q  scatter     ;;keep center-turtle random positions # O2 X  h  o4 y: {/ {. [
  unit_plan   ;;make up the building plan
. a, |5 A* {$ f6 x) W: `end2 L8 U) P$ F) c$ k' N) U+ I
to scatter9 q; U6 ~! J+ ~/ a4 v
ask turtles with [remainder who 5 = 0], C: G/ N+ h! R: K0 q/ [
[
; f! n& ?) S- q1 n  iset xcor xcor - 6 + random-float 15% z% K  K" R) T. d
set ycor ycor - 6 + random-float 15
3 V$ J0 D. Z6 Z( Y# c7 R0 |]4 j  `7 W4 I/ ]- ]* B- Q& }
end% k7 J# x% i# [2 e
to unit_plan $ @$ s! v# }  [- `
ask turtles [
/ p- ?4 _- {3 ?& hif (remainder who 5 = 1) [set a who ' Q% a: c! w" K1 t0 Y" k- a& m
                          set x ( 0 - Wid / 2 )
: X5 P7 i: k# c% R; h( r0 B                          set y  Dep / 2 ]
. s2 F4 Z$ A5 W5 u/ F' A) h/ ?9 q           set b  int (a / 5) * 58 B8 `8 K& o8 }  W' I! z
    setxy ( xcor-of turtle b + x )
$ w9 ^; A% h8 x3 V* C( M! B          ( ycor-of turtle b + y )
% D1 j. p3 @- O" D3 ]: Oif (remainder who 5 = 2) [set c who
% H+ B4 ^6 z  C" R0 f1 b                          set x ( 0 - Wid / 2 )
/ b7 O( J2 h* ~' \- S( t: p% T: K                          set y (0 - Dep / 2 )  ]
: c5 z. z$ C7 ~                          set d int (c / 5) * 54 l) x) \& m& Z+ q
   setxy   ( xcor-of turtle d + x )
1 W8 Z0 {+ T- D( g7 q( Q. B! ?           (ycor-of turtle d + y )
  B6 D% h4 V! ~3 s( y, Z9 R  N          1 E* B( G; d- |4 v" k) T
            : S$ X& o# r3 d7 D1 q3 w4 G1 k
if (remainder who 5 = 3) [set k who4 a- G' P- N# c/ i% g
                          set x( Wid / 2)  3 Z! G* f2 k# V. X5 Y. i) R7 h- E; O
                          set y (0 - Dep / 2 ) ]
* `& X& Z1 g) P                          set f int (k / 5) * 5, k) `5 }) Z: E% T
  setxy   ( xcor-of turtle f + x )
3 ?4 I# X7 N6 R7 O9 b/ b           (ycor-of turtle f + y )
8 A2 _- G' L( X5 q& l% f+ Q           
. N1 n5 x2 [- C" ]( u8 h, l) K; p           6 r( l" x$ z* q& H! _) k
if (remainder who 5 = 4) [set g who
* u6 q; N- U; I' a" `                          set x Wid / 2
2 R- x) m  V+ q                          set y  Dep / 2 ]/ B9 h3 o) v6 a( D( y
                          set h  int (g / 5) * 5' f% \, o- M% S1 ]+ Y) ]
  setxy   ( xcor-of turtle h + x )
0 K/ V9 I1 r7 ?/ n           (ycor-of turtle h + y )
0 V- k9 \0 Y. }$ I4 D4 W7 ?. K                          2 I- D& b$ b8 D* S! I$ Y4 B5 a
                          3 [# c" p& T/ `" I' i
                          ]2 _, k% n- c+ Q" @: L& E
end2 G  @; e2 \0 q
! ]! g' i- r' C3 o0 J9 l1 m1 i( {
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
8 d8 U5 a% M9 Z$ I应该是0 j! u' ?* ?+ ^! c
ask turtles [
0 Y5 Z6 F3 O* I; s3 [, z, V. aif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) $ Y! i: U; q& K7 g1 P
                          set y  Dep / 2
; D' q6 e  l1 M& `+ T           set b  int (who / 5) * 5# r, P8 ~* b9 R6 p' O
    setxy ( xcor-of turtle b + x )
6 {3 z! T; `; ]' W3 r          ( ycor-of turtle b + y )]]9 M: ^1 z0 c7 Y3 O6 I
end
7 t0 F# d9 |5 }$ Y/ s  f+ c0 U之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-19 01:23 , Processed in 0.017471 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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