设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7269|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。8 Z+ a3 W: i/ G# L; h, g: a% y: D6 E
8 c4 a6 b/ k0 L
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
' l( Z7 Y' z' z$ q' s
$ k% u/ [2 w$ X8 g# P; u( y0 fturtles-own [a b c d k f g h2 @; P' Q7 D3 S, G  Q" u
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
8 w. l3 j# R/ z" Y3 V. o]! P- T$ l$ X: }( ^/ s' [
to new
2 B/ T+ L& J: W  ca% _* D% \+ S, ]
  crt 5 * num_of_building) j4 e# J" S7 O# g. t
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
0 `1 K" e6 m5 n& K- }) T  scatter     ;;keep center-turtle random positions
# X3 v* g! g6 R/ w5 O5 m. V  unit_plan   ;;make up the building plan
6 H3 S! P; O! e# m8 wend
. Y, ]/ ^+ b) k/ {# o, hto scatter
: ?& }9 ^; ?) O& B3 Mask turtles with [remainder who 5 = 0]2 r8 A6 Q. V0 o$ x3 C3 K
[
7 \$ b% X2 e; E( dset xcor xcor - 6 + random-float 156 f' J5 I" I' {' M, w9 z! N
set ycor ycor - 6 + random-float 15+ N5 c; E, ]& Y& ]- X# h! O
]
7 Y$ U  I% D  G& n% Tend" g/ o5 f+ H4 g& i
to unit_plan % t9 A5 j  A1 z
ask turtles [
1 `8 Q/ K3 [/ c0 l  Sif (remainder who 5 = 1) [set a who
5 @, Q) O2 b) F) ~9 n- c; c7 \4 d) F; n                          set x ( 0 - Wid / 2 ) : L6 l6 d6 C5 E' y; G
                          set y  Dep / 2 ]
! a/ _9 m, X# [           set b  int (a / 5) * 5  H+ r" x6 l( y4 f3 O0 M+ z" }  i
    setxy ( xcor-of turtle b + x )% N+ ~! \, S; `  l# K4 n' t, _
          ( ycor-of turtle b + y )
! M- G. V# C; j5 o) p! Y, Yif (remainder who 5 = 2) [set c who8 ^" r) B6 ^5 w% T+ h" a/ b( C% i
                          set x ( 0 - Wid / 2 )
( F2 v) W8 j! p" G" d                          set y (0 - Dep / 2 )  ]" Y9 g5 }3 e* n
                          set d int (c / 5) * 5+ ?3 U6 w8 Z4 G. s: `& O+ R  T, Q
   setxy   ( xcor-of turtle d + x )
4 T6 i4 \& W8 s8 o4 p           (ycor-of turtle d + y )
- W7 _0 N9 Z6 N" H5 ~2 E( m# S          ! C" K7 U' W7 {! `9 L; S
            
- S5 J! P' Z: |% {- @if (remainder who 5 = 3) [set k who, U; m* E! \" n0 H3 f
                          set x( Wid / 2)  3 l) a" E: m% D1 W: \) N) l
                          set y (0 - Dep / 2 ) ]# \: o  P4 T0 S9 Z
                          set f int (k / 5) * 5
% R1 K) @$ j- o  setxy   ( xcor-of turtle f + x )
! X" N# r. j0 b% L3 V! x; t           (ycor-of turtle f + y ) , y4 D" B6 d9 A/ i& ]
           
( s+ z5 N8 W) N+ m           & E. e! F7 C3 w: I. `
if (remainder who 5 = 4) [set g who* o! a$ [& v# P! t
                          set x Wid / 2
( z! [' k. }3 e8 w                          set y  Dep / 2 ]
6 F5 ]. O, m( W  z                          set h  int (g / 5) * 57 ]; J6 r8 W, T; M* L# ^
  setxy   ( xcor-of turtle h + x ), a8 I- M; W0 t
           (ycor-of turtle h + y )
  A. U8 S& Z# R$ U  W                          
0 ^8 W5 M# _- \( _- j; A# t+ D                          
, s5 o- ~( m4 M* v- l0 p8 [' Z0 |                          ]
* r" k  G! P( \, Send* e( u  |, \% r5 M

0 V1 x& K4 k: F; B  w[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
5 G. Y- C% p& d( s应该是1 b# B& \7 K4 J& c  s" k4 M) T
ask turtles [
- Y, k; o! G" R7 D* h/ vif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
& z& c! T, K* X( f- f( h) R" _                          set y  Dep / 2
' f1 D1 W' V$ a3 q           set b  int (who / 5) * 54 p: ^& R- T1 q/ S% f6 h  o7 B. d9 `
    setxy ( xcor-of turtle b + x )
& k# a% _3 I2 b: t, \$ u          ( ycor-of turtle b + y )]]/ {8 f1 \% n" R2 v; d  J$ Y
end
7 F; Q0 D& a$ C+ f6 c/ L之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-23 06:54 , Processed in 0.017380 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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