设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8869|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
  ]6 |+ E; L, B# j7 e; x9 ~. s5 `
& ~. g$ }+ ^8 F. N) J但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
7 ]9 t0 w4 `! a2 i5 ?/ c9 c) ]) V/ M- [9 K) B1 E/ y
turtles-own [a b c d k f g h% a, K8 R! Q. _: b0 h
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
0 P% a; ~- {, B( m- i- J) |]
7 J! d4 I  B% ^1 s8 q% k* P' ^to new  J" |2 t  r9 \. p
  ca
1 E" e# h! z" @& C) P  crt 5 * num_of_building* X9 O4 Y. m% K; @
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]. z7 d. J- H9 q( y
  scatter     ;;keep center-turtle random positions
- E. e- z( a9 S$ Q2 J$ t9 i8 A( f# s! k  unit_plan   ;;make up the building plan
4 B. r' j5 B& N$ T' M% z5 Iend  J6 l6 b; ~7 `& f. u
to scatter' h& O0 T5 B8 j
ask turtles with [remainder who 5 = 0]9 X, f* v! R% Y0 k
[# @8 ~2 r! s7 |5 L2 J/ ?! j
set xcor xcor - 6 + random-float 15
. T. U: ^3 r3 ?# m0 A. Q" ^set ycor ycor - 6 + random-float 15
- ?$ n6 d" ]4 {2 Q! a# n+ ]" u$ a]
, [6 ~9 a4 s( Aend
- z& J* h3 {' ]9 n: a! y$ T3 jto unit_plan & o! E4 B/ X: F4 @$ h9 N
ask turtles [
9 k9 }0 B' ?3 U/ |: n, xif (remainder who 5 = 1) [set a who
: k0 i9 I% `! f/ ~0 F* O% v7 q                          set x ( 0 - Wid / 2 )
0 m; n  ?7 V0 o: d$ ^                          set y  Dep / 2 ]
5 Z& {* E, [0 W# `           set b  int (a / 5) * 5
2 b6 t: P0 s' V( F    setxy ( xcor-of turtle b + x )
- B2 K5 V, q, G5 c          ( ycor-of turtle b + y )( G. G8 d7 t( Y# `) ^; r
if (remainder who 5 = 2) [set c who
% Q7 h. H# b# p7 V; Y                          set x ( 0 - Wid / 2 ) 0 j. P# [. ]0 a- \" D
                          set y (0 - Dep / 2 )  ]
$ S5 V2 O. L1 g                          set d int (c / 5) * 5
" W! s: Y1 B9 v: f: m   setxy   ( xcor-of turtle d + x )6 _1 X' n: ~5 Z$ P
           (ycor-of turtle d + y ) 6 F# t' z6 `7 c; d2 c
         
3 S. j1 `7 i8 a# z7 U3 d1 \            
$ E. m8 _) G! ^9 J# w8 Oif (remainder who 5 = 3) [set k who' D1 i, o4 `' p6 @
                          set x( Wid / 2)  5 H2 n" g2 `( Y0 n
                          set y (0 - Dep / 2 ) ]
. p* R6 Q: N8 Q' N. d4 B! x) T% t                          set f int (k / 5) * 5
  y2 f+ h5 h2 q" l( C  setxy   ( xcor-of turtle f + x )
2 T! S' e' ~+ L1 u           (ycor-of turtle f + y )
1 \: N: l4 F0 E% A           % U. y3 h4 n& o' P
           6 q2 p- ^- T; p; F$ f  ]
if (remainder who 5 = 4) [set g who# s9 C( |; C' P: w3 ~
                          set x Wid / 2 * k  L& u* S/ b" V$ @7 L
                          set y  Dep / 2 ]
6 f9 d$ G8 h0 v8 f. i0 |1 G' b                          set h  int (g / 5) * 51 Z# M" v+ X4 k3 Q& O" t2 H6 e5 |  J% S
  setxy   ( xcor-of turtle h + x )6 G% r" o- z0 ]
           (ycor-of turtle h + y ) 5 Y* N! Q  j6 X  X( [# g
                          . [% N, l7 w) ^2 |% E6 t
                          
  f1 O/ d+ D' H9 S3 }                          ]+ s6 W/ s1 p% @) _
end) B: i/ Q: \& _! F% ~
' ]/ n+ t9 {* `6 [* d# J
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
9 @1 ?5 V( ]+ t' A应该是- m- u* \" d$ ?( A
ask turtles [
) r# h1 [7 j+ A* Zif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 0 r- u6 S' r( J$ i* x
                          set y  Dep / 2
# B  }' u9 M2 z. h           set b  int (who / 5) * 5
# |+ a5 e, i; k% e    setxy ( xcor-of turtle b + x )% Q: ?' n7 n! i: ?
          ( ycor-of turtle b + y )]]
) f' r% g: M( S  w- W; _7 \, ]2 Dend
# p; b$ a$ P5 r) K之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-14 11:19 , Processed in 0.014536 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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