设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7232|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。7 o6 M: \" g  Y+ b/ u: K7 e& g
7 D. J" j9 ~) C! M* R4 c
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
2 t& M9 _( ]- W( E5 R4 p
5 E& @$ k' j$ W& eturtles-own [a b c d k f g h
/ e: N8 T1 k( h% q) [5 P/ l  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
- }6 C! i+ o& \' I) k]- {+ w8 S) j" A9 i
to new$ T- n% O  S* k7 H! G
  ca
/ Z" a9 O: _7 M5 \6 X  crt 5 * num_of_building
" c9 A. B& R$ |) Z% ?% A  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
) B; S4 d# f; E2 N; b- y  scatter     ;;keep center-turtle random positions ' q8 J2 e- q8 w; u1 @
  unit_plan   ;;make up the building plan- y; T: @# M" P; k, ?4 d. y2 I
end
# E8 N: m# e  a) o0 ?6 Q2 Jto scatter- B: D1 I: ]9 T9 X
ask turtles with [remainder who 5 = 0]- @$ w: _( T' O6 k
[, T& _4 G# J, U6 F( {. c
set xcor xcor - 6 + random-float 151 E8 S" Q1 a- c: ?! ~, X  ~
set ycor ycor - 6 + random-float 15
# ~. m$ N* K) @# y' W7 W* h]( h5 ~: U: ^- \; u. I
end% @! S. x5 G# f; s( m& `
to unit_plan
+ [7 Z9 l7 U/ r1 i: m& [& Wask turtles [
! p( C4 }' ]  L; D, q1 y2 [8 e6 aif (remainder who 5 = 1) [set a who : X3 u7 o2 D# Y" A4 n7 g
                          set x ( 0 - Wid / 2 )
* \2 z7 B/ K. ^. w. F                          set y  Dep / 2 ]
6 c4 z5 G, l4 D  n2 E4 z           set b  int (a / 5) * 5
! l2 z7 H! l( N& M    setxy ( xcor-of turtle b + x )0 X5 K7 H. c6 D6 h% e
          ( ycor-of turtle b + y )$ T; t2 y  t# }* _0 K
if (remainder who 5 = 2) [set c who
  z9 s( U% K+ p$ G& L" p4 ?                          set x ( 0 - Wid / 2 ) " C! ^0 S! Z1 I) v2 G8 E. T
                          set y (0 - Dep / 2 )  ]) h1 v: c, c# L4 p# W) w. Y% v
                          set d int (c / 5) * 5# C# ~# A/ O* i# `
   setxy   ( xcor-of turtle d + x ); m( e) \. K& h3 S
           (ycor-of turtle d + y ) ! v5 n8 u; Z6 b9 {- a0 B! _1 R
         
5 o- h0 w7 b. S$ a' V) [2 p- |/ s            ! w, n% n' l, P" U
if (remainder who 5 = 3) [set k who
/ X! |6 c/ j+ Q2 K( S) Q                          set x( Wid / 2)  
: j, b, i9 D' |% d4 o- `9 _7 E                          set y (0 - Dep / 2 ) ]& M/ G. k1 ~" |- F% e$ _0 H
                          set f int (k / 5) * 5" ^, ~4 u' G  `( b$ a/ U
  setxy   ( xcor-of turtle f + x )
6 p9 u& E* t3 M3 q1 E- q/ x           (ycor-of turtle f + y )   U5 i' @% G7 m  U
           ( X$ x- B+ \8 l( a; }/ U
           5 ~: c* `( p- d0 O) I  u* X
if (remainder who 5 = 4) [set g who& D& e3 z  e; F8 _; ?
                          set x Wid / 2
  W) g3 u" G  C6 z  n                          set y  Dep / 2 ]. g; f: q* F& C3 U
                          set h  int (g / 5) * 5
' J7 n0 E, F# o2 ?! _  setxy   ( xcor-of turtle h + x )- @$ m' R& C1 w) e7 p3 A( M# W
           (ycor-of turtle h + y ) : w: G: Z9 U9 ]% A8 l: Y; {
                          
/ ?, m5 F* C. k/ V) \                          * R" G' M6 B, i7 q9 j+ q: d
                          ]
( @, P1 S8 d( x4 [9 [end
% n% Z9 t6 X+ G/ h! y6 Q9 T$ e$ ?
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,7 i$ h/ q; E+ C
应该是) U2 Q! r1 K2 y# u8 R4 R, W7 \
ask turtles [' o( u7 S4 U* P2 g  Q8 s
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) , ]0 a7 \+ g- B
                          set y  Dep / 2 5 o  s' f, T/ w7 u- v
           set b  int (who / 5) * 5
7 f+ V' e9 f+ B4 M7 G+ e' o    setxy ( xcor-of turtle b + x )
9 A1 G! C4 k" @* H          ( ycor-of turtle b + y )]]+ z5 a) ?# @. m/ q, D9 k6 e
end( b2 s5 W5 c  K0 W6 N8 G
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-19 16:17 , Processed in 0.033213 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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