设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8884|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
, [9 }" U+ f6 E  h8 d& Z
7 C+ O) G) {! r, N9 \但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
# F& o7 S& E$ K( B$ q# f
1 N' q8 y' V! W0 pturtles-own [a b c d k f g h
2 ~4 H5 i; O; P2 Z6 l! _" _# d  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
' r) |7 w+ P7 Y+ v0 B]
. m5 k2 F) v+ uto new* Y3 y1 S$ q5 D6 M
  ca" m9 }  I5 y* R0 T
  crt 5 * num_of_building7 e6 L: u( k! Q- p
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
% E& z' b$ R5 b; z1 q) f! [  scatter     ;;keep center-turtle random positions
( s% S3 g/ ?  l* K  m9 p  unit_plan   ;;make up the building plan7 _, E7 d5 f$ K. m. T  s
end& q  ]8 g" Q6 y) h% k8 h/ L
to scatter# t% o; W+ _6 X1 ~. |3 D  f2 j  C# P
ask turtles with [remainder who 5 = 0]: V2 h$ N6 Y9 h& {
[$ s5 k# I( U1 A" q% B
set xcor xcor - 6 + random-float 151 ^$ T# W" U* u3 P" ~7 a6 y6 P+ n+ l# p
set ycor ycor - 6 + random-float 15
; d$ P1 e9 Q3 P3 u9 O/ R& R) T]
' J! T: d: Q( ^end9 v# z3 I4 |. t7 z! N3 a( P
to unit_plan ; C  J8 @5 K% ]- t
ask turtles [- A  Q' \3 |4 Z
if (remainder who 5 = 1) [set a who
3 J0 _, m) Y5 w* ^5 J                          set x ( 0 - Wid / 2 )
2 S( `4 d; o2 S9 ^2 o& \) m0 f: b: k                          set y  Dep / 2 ]
4 |& Q% H/ Q3 b3 M           set b  int (a / 5) * 59 i7 K7 W0 @* O( H9 ?( e
    setxy ( xcor-of turtle b + x )
- f2 h& W' G) N( b( z3 f5 Z+ D" U( T          ( ycor-of turtle b + y )6 K8 \7 M" d$ G6 g5 k
if (remainder who 5 = 2) [set c who$ z* q: X% N& ?; ~0 ^2 j( m5 Q
                          set x ( 0 - Wid / 2 ) , T8 M# x  M% _
                          set y (0 - Dep / 2 )  ]( J- S7 d# s6 @$ i. ]
                          set d int (c / 5) * 5
& Y4 z1 h& s6 O! a. {   setxy   ( xcor-of turtle d + x )/ H* t7 L8 O9 s4 L/ q/ F; B
           (ycor-of turtle d + y )
9 x: G, T* C4 n" P, i         
, |5 H# B4 T- ^7 P            
8 N  j7 [) p1 Wif (remainder who 5 = 3) [set k who
9 V% ?% p! C" Z! K9 e6 y9 h2 T4 P                          set x( Wid / 2)  
# Q+ L, Z1 S2 e7 d                          set y (0 - Dep / 2 ) ]' F. O3 Y4 m3 O' P( Y( G
                          set f int (k / 5) * 57 c) m3 V) ]0 R% x5 B0 h# v( [# x! ^
  setxy   ( xcor-of turtle f + x )
) k. ~- D0 K% n           (ycor-of turtle f + y ) 3 Y; w  p3 x1 u& h) U$ R& B& Q
           
2 ?' s" Q! ^* Q* M. {5 t           6 N9 Y, ]1 V- v4 ?0 y/ `4 O' G/ N
if (remainder who 5 = 4) [set g who# I5 U# D2 F9 J
                          set x Wid / 2 % k1 P5 U. ^  t5 C* l
                          set y  Dep / 2 ]
: m+ B, M9 m, s3 M4 k6 ]: E                          set h  int (g / 5) * 5% j3 W. u1 ^; A9 y  I
  setxy   ( xcor-of turtle h + x )7 V1 K  Q* b. t; i8 D
           (ycor-of turtle h + y )
' O, S- @. `* ]9 j( T                          
- D5 ^. s" D  q$ Q' j2 s) g                          
& j+ J" h* K! U" j( o3 \                          ]5 p& n5 q: q0 A: S
end/ c  ^, d) c; l
+ m2 K6 a0 V/ H" p9 D
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
! q3 F: q: O5 z7 E6 J# E5 o应该是
: |* u; A* _( Q! X5 Q, g! R. O* `ask turtles [
. P3 F% g  h" f' A1 o3 n- w; j7 [if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
/ B, [& }. r  a3 L+ s- _  p                          set y  Dep / 2 5 j4 M0 Q4 `2 @; i. O2 Z
           set b  int (who / 5) * 5  `- X: O  |: z) ^$ @" ?3 U& w1 @# h
    setxy ( xcor-of turtle b + x )
# p) E/ V3 C4 }# k          ( ycor-of turtle b + y )]]* A) A9 \# l8 y. G' f+ z# k, \
end
" g4 J+ G  W' @之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-16 16:58 , Processed in 0.017164 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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