设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9099|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
' T9 `' O/ S% g: Z+ Z7 w0 q7 C" B5 R& g
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
9 z. i- Q- W3 I2 H4 a) l# I% D
2 ~7 N, n( K6 [8 e6 d% U4 D# Dturtles-own [a b c d k f g h
* `* |) X9 f- l! _. [: u! S4 O' D+ H  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
; z0 S1 g' E/ [3 r" ^. z; l3 D]* G$ Q$ U+ p; k1 P$ A4 ]1 `( e, }
to new( T5 s! s/ C" z& T: B. f/ V
  ca. d' h" O8 s! ]: s& X- l
  crt 5 * num_of_building0 o1 W8 l0 J; O) O+ M+ d6 E
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]], G; R; Y" M" d  C, ~0 ~
  scatter     ;;keep center-turtle random positions
/ q- G! `9 M+ U' s  unit_plan   ;;make up the building plan+ U, f5 @8 n/ G% g: i8 j2 v
end
( z  A. y8 r/ ?% y- Y6 p8 y) Sto scatter& V; u) j" ?3 Z$ n: x% \& P
ask turtles with [remainder who 5 = 0]! t/ X" o. i2 v6 k1 G
[
" `; |/ h' K" `  B: \7 w7 oset xcor xcor - 6 + random-float 15
/ @* _5 O( z& Z$ U- Q  J* @3 uset ycor ycor - 6 + random-float 159 D9 y8 s/ ]) P+ D- g4 ^
]3 F* j/ E- A% Z8 B% m1 w0 u, n
end
2 j, C0 e% q  Y% e' S# F  K8 fto unit_plan
( y! q- F% W% u# Y- c" _ask turtles [
+ u/ ]" |* s& E$ r% x1 k- N' T# N0 Pif (remainder who 5 = 1) [set a who
2 X: V* K: H6 ?9 B( ^$ r; f                          set x ( 0 - Wid / 2 )
  N! r5 i6 s( o. _% T2 a                          set y  Dep / 2 ]
7 u- Q4 ?- |( H' W$ y' t           set b  int (a / 5) * 5
2 R! ]: _- v4 P    setxy ( xcor-of turtle b + x )1 p6 p+ Y: r7 d1 W
          ( ycor-of turtle b + y ): ~; y# \0 I) |$ X+ Y+ q% P
if (remainder who 5 = 2) [set c who
, Q8 S  T/ h$ M" ~' }& E; l& m# Y# f; X                          set x ( 0 - Wid / 2 )
0 O- U8 y7 L1 U) l* S6 _) a                          set y (0 - Dep / 2 )  ]' P( G% r" s; K& D9 h0 @
                          set d int (c / 5) * 5
- `' }- t4 A3 ^7 _) l* Z# N   setxy   ( xcor-of turtle d + x )( v8 ^- H$ A6 ]$ n
           (ycor-of turtle d + y ) " ^6 w  J4 t' B
         
' D  H: f# a8 R0 E9 L; u( s            , m& s6 |% Y# y% L' d0 f' _" {/ V
if (remainder who 5 = 3) [set k who2 g+ O* ^, Z5 C$ o) T' H4 g  f
                          set x( Wid / 2)  
' T2 E* V8 g. Y6 p) I: W4 h                          set y (0 - Dep / 2 ) ]" k  G$ W1 d6 G
                          set f int (k / 5) * 5
( T/ e3 E* Z9 `/ C0 ?* k  setxy   ( xcor-of turtle f + x )0 [* Z; j  @# h1 _
           (ycor-of turtle f + y )
9 h' t& g4 m0 T! j5 [& M! a# Q% [           
" J% S: Q9 g" {( Y6 c           
! H; r& ~6 z2 yif (remainder who 5 = 4) [set g who
' B0 ~# A! }9 z1 Z  t                          set x Wid / 2
- Q5 _% B  G. K4 }; V+ K; f                          set y  Dep / 2 ]! P% `1 h- p% E* K9 q
                          set h  int (g / 5) * 54 ]( {* I* K$ f- u! r
  setxy   ( xcor-of turtle h + x )+ E* C. c% W7 l( N
           (ycor-of turtle h + y )
4 P  L# y, e9 o' U+ E8 E                          
  j+ O. d9 Y" Z) D3 |9 l6 r3 K                          ( l7 J' ^) F+ Y5 ]# C
                          ]
0 M0 [( z; [6 R+ }/ Pend% d# v8 |0 @% Y- P5 s
  h! G' @+ r  S2 W
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,+ z& e5 G, E7 j3 A+ W% y) p
应该是
+ t( J- w: B; c. U/ Rask turtles [
5 `. c# c; J1 p5 X1 J3 @if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 7 C/ |5 d! g/ u- l9 J+ M! [. j
                          set y  Dep / 2 & H9 @- Y4 P# g! w+ D* \
           set b  int (who / 5) * 5$ t& @! @- D1 Q0 E
    setxy ( xcor-of turtle b + x )
- s  `, o# t$ g) j. g, d3 f( w5 w          ( ycor-of turtle b + y )]]
6 `' C1 J- I' \3 u" wend0 ^8 g' Z. l% `1 o& p9 Y
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-17 18:58 , Processed in 0.015881 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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