设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7138|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
. o# i: n+ D$ i( \( ^0 `% A, R- b4 S" \, y" g3 d& d( f
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。& o' I$ X/ x, {# P2 o

/ G! J( `7 N# S3 U  c4 vturtles-own [a b c d k f g h- e$ g: h+ c. v7 J" l
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
- n+ [  v3 Y& O1 C- []9 J1 F' @+ n1 D: N
to new2 Q, A+ _  I# j" Z+ C* R' b" G
  ca3 v2 H/ U; G, q; G# U
  crt 5 * num_of_building8 Z  D; ~/ z( K2 ~
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]1 U. @( P& T/ B: N
  scatter     ;;keep center-turtle random positions " x' `6 d- Y' J7 ?
  unit_plan   ;;make up the building plan
  A2 l+ l4 z% Q6 E0 s4 k/ O% Rend
" v+ b; v6 [$ D* eto scatter
, Y: M* F( _" `1 Dask turtles with [remainder who 5 = 0]
& y, A% O3 J$ I, G# W. o' T$ u- B[! U  o0 B' b3 {" C' T2 }7 Y4 r* m
set xcor xcor - 6 + random-float 15
, T& @- \" `' H1 r" eset ycor ycor - 6 + random-float 15
. [' ~* ^3 A' m' s" B/ M) V9 s1 i]  Z- T9 p2 o) `/ h8 P" }
end9 |" C$ i* d# w4 z2 u
to unit_plan
" X) T" o/ Y/ L) n; ?; Oask turtles [
' c4 G: m! m3 f. Fif (remainder who 5 = 1) [set a who 9 y, p6 U  \0 L" ?2 g" b
                          set x ( 0 - Wid / 2 )
/ S" `2 ?' h0 J! X3 }                          set y  Dep / 2 ]1 [' R. h+ _1 _1 b0 ^8 o
           set b  int (a / 5) * 5
9 e' I$ e0 v4 G7 }- m, g$ a8 G    setxy ( xcor-of turtle b + x )
  h7 u$ p+ V$ v" i          ( ycor-of turtle b + y ), [0 p+ S* \+ m- t+ a
if (remainder who 5 = 2) [set c who
; H: m( C3 m% `6 t. o4 i                          set x ( 0 - Wid / 2 ) ! Y1 Q$ D" D  ?! u/ U2 l
                          set y (0 - Dep / 2 )  ]
+ f! z$ F) m9 f6 s1 p( n                          set d int (c / 5) * 5+ V1 y. g! P( m, {2 l8 ~5 w" o
   setxy   ( xcor-of turtle d + x )) H+ j6 P1 q- W2 J& j/ v: \
           (ycor-of turtle d + y )
. B) A& `, n$ @/ U7 }          . {; l) S2 `5 ~
            
/ C7 e- g" F) w$ v3 Eif (remainder who 5 = 3) [set k who) z' y9 _4 s% E1 N  V: S
                          set x( Wid / 2)  - G; x" ^' {) c( b
                          set y (0 - Dep / 2 ) ]7 j2 @+ H5 w" q, ?  a7 ~7 [0 u7 s
                          set f int (k / 5) * 5
% w8 R" }: K5 L/ ^0 E9 S  W. e1 H  setxy   ( xcor-of turtle f + x ). m+ ?; T1 k$ D4 f1 |) w. N5 |
           (ycor-of turtle f + y )
: a; F( T+ _3 p. C           
0 {. e. n. D$ V- w           
; z9 F7 u4 u& r, D$ [) V* vif (remainder who 5 = 4) [set g who
2 m0 D- Z7 u, k1 N, Y                          set x Wid / 2 8 O  c- a* d. K4 S8 P8 K
                          set y  Dep / 2 ]
; V0 U8 h: j) J6 Y) Z5 u8 Y                          set h  int (g / 5) * 5
; z  v( D, }; {* T" |  setxy   ( xcor-of turtle h + x )
9 |3 x: M# \5 N2 O& ^3 b8 V           (ycor-of turtle h + y )
# G# Z# G! _5 l0 q% ]. {, p% ^                          ' n! j# i5 `( d3 J. M
                          
# s  O0 U' L7 `0 _0 [7 |                          ]
0 D  G4 g! |6 }; P  y% @end6 I& H$ q/ [: x1 e

# ?. c5 f7 e% ]1 z" `- b[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,: a! q9 ^& u) k! n
应该是
4 l& m- t3 i* ]4 Gask turtles [
' m3 J; A. x9 w2 s: G8 gif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )   T5 W$ D# Y( r1 Z- F0 P' M0 o" _
                          set y  Dep / 2 " L, g/ V* f6 E
           set b  int (who / 5) * 5
- K$ l+ h& h% a. C    setxy ( xcor-of turtle b + x )% V4 P5 X' A4 p
          ( ycor-of turtle b + y )]]
; E0 U( e5 S; N2 |- yend
$ }: K+ }7 R4 P之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-4 13:03 , Processed in 0.018922 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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