设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8937|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。% y3 R* V, ^6 q* y& V4 F% u. N
$ p, E0 U7 o; b) w
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
0 P$ R; Y) G$ B4 ~2 K+ Q* z* [2 p0 s& Z
turtles-own [a b c d k f g h
: [7 W. q7 [! A( `7 m, g4 e* m  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ( d0 J3 Q1 R$ r, L% \  q$ |9 o
]5 T$ q! S; P8 v5 z) E
to new% c) A0 m( w' v; b% \! o
  ca; x, ?0 }( A' t7 t
  crt 5 * num_of_building. ^- v0 Z. Z+ l- q
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
; p6 F+ ]# Q8 `( q7 l) C  scatter     ;;keep center-turtle random positions $ ^  ?& T9 N6 P0 Y
  unit_plan   ;;make up the building plan
9 q- r- a& Z( @  S) |4 eend
/ ?  x3 v( n" {6 O4 Q% ^9 M7 Jto scatter
6 B6 |& S) X2 q/ ?: L6 E" lask turtles with [remainder who 5 = 0]$ x/ g6 [/ D  r$ S9 D! E
[  v& q- j/ D' t! [
set xcor xcor - 6 + random-float 151 o( y* A- Q" [+ X
set ycor ycor - 6 + random-float 15- W4 R* [( a/ w" b
]9 V1 P$ Y, R5 C& s, a4 |9 a$ \
end+ a( H0 h& |! m' c0 B3 H) u/ a# k
to unit_plan
& G( |: j+ `5 T, z+ Gask turtles [  L& g$ {1 d1 T, k' }
if (remainder who 5 = 1) [set a who
# _; V5 u8 k1 A7 @                          set x ( 0 - Wid / 2 ) - S% |/ n" f9 L
                          set y  Dep / 2 ], H+ W# s$ T% B4 h
           set b  int (a / 5) * 5
. k; I& u& o% ~& Q) {    setxy ( xcor-of turtle b + x )3 u' o9 @, U; B$ e, @& N* @; p
          ( ycor-of turtle b + y )
7 k, f: g; v2 ]! H- `" R( K/ A% @if (remainder who 5 = 2) [set c who0 c$ p- Y8 h& w+ b: m8 Z
                          set x ( 0 - Wid / 2 )
' G; w2 r/ h7 F. i/ X$ g7 Q                          set y (0 - Dep / 2 )  ]
' [% C4 Z5 M. [% T, Y0 Q' Y                          set d int (c / 5) * 5
& J/ D" i7 x+ u   setxy   ( xcor-of turtle d + x )
6 n) R. W9 j" o5 Z) V/ H7 L           (ycor-of turtle d + y )
* k4 ^' y. ]. j  o4 K: o/ K+ A          4 ]2 ]) f: h& M/ {; `2 R9 @5 }4 }
            4 \7 G/ p% R7 L3 H8 D$ y* W
if (remainder who 5 = 3) [set k who
+ [+ v/ c& W( a4 j& z  {                          set x( Wid / 2)  7 x, u9 F: [: M, ^) ?% ?; `
                          set y (0 - Dep / 2 ) ]7 T1 |# s3 m8 ]- @5 m
                          set f int (k / 5) * 5
' B; T+ u- [. s  setxy   ( xcor-of turtle f + x )
6 p; U* O1 s) t           (ycor-of turtle f + y )
) B6 S5 e- z+ D+ E  V           
* W# t9 i! i3 K: I- K           : b0 W8 c; E# u- R' I+ |
if (remainder who 5 = 4) [set g who8 C% o) s/ D$ s. M$ q) M" _
                          set x Wid / 2 . h/ B$ p& F4 ~4 d' l# S! D
                          set y  Dep / 2 ]$ e+ J6 [- E2 l4 [6 u! M- Y
                          set h  int (g / 5) * 5
& Z: J; h' _4 Q3 j8 t% e" Q  setxy   ( xcor-of turtle h + x )
* r& Y! ]+ `0 K/ y           (ycor-of turtle h + y )
+ `; [0 i% x7 F7 j% s                          
$ r8 N$ Y! z# t  ~8 R                          
* U' y  ~6 i; Z7 t0 o# o+ _                          ]
, `9 r  P" G+ C( P1 y8 Bend$ H% P8 K7 Y" V- e& ~4 D( Z. m
1 b$ ~& I( [& ^  c
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,$ e$ j! R0 h/ [* G: n) A& i
应该是
* a+ h* T( ~  t1 aask turtles [
% `" ^' |& v( bif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) : O/ r: p+ k, o) k& y1 C
                          set y  Dep / 2
6 Y9 j  Z7 n; h) a           set b  int (who / 5) * 5. ~* ^1 [  Y, \  y5 y- p' C3 t
    setxy ( xcor-of turtle b + x )
3 s+ Z& f& b; k0 x) q/ }3 b- l2 U          ( ycor-of turtle b + y )]]1 V: @* W: l* g
end, F' c4 _  J* o+ K: C5 I6 s% ]+ X
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-26 22:18 , Processed in 0.018935 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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