设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8507|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
4 ~. q6 a. X- B5 T+ Q. x' W6 `
2 a6 ?% H& T. P但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
9 e/ ~0 [- L9 X9 b5 P& Q9 F. X; }) N1 P
turtles-own [a b c d k f g h
2 O$ \7 F" ^5 ?  L: v  x y     ;; these are the leaf-turtle's offsets relative to center-turtle $ Y! X+ I& L! U8 z, @' w
]
  g6 u2 r4 M! C+ w5 O( j8 Ito new
0 K/ J% {7 j( p  ca: Q+ O4 e8 O# V+ v3 I+ X7 M
  crt 5 * num_of_building
* o# ~; y0 [: H" C  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
/ K+ z/ z8 o+ p! l" p. B. L  p  scatter     ;;keep center-turtle random positions 9 R) G0 o3 H7 X! C; \& |  t' t
  unit_plan   ;;make up the building plan+ Q* |* a) W/ j8 z9 |
end1 U' K4 w- V& A( p) a
to scatter
6 ?) ^( i. u5 w. Q3 ~) W6 Cask turtles with [remainder who 5 = 0]6 ~" Y+ }  W. G
[
& G# S  ~& c9 I5 Gset xcor xcor - 6 + random-float 157 |# k- D1 U; B# t, b
set ycor ycor - 6 + random-float 15
0 ~- v* O$ s5 R! r4 Y  U# Z% j. a]
' ~7 O- s' S) Y; y1 Yend
, F4 ~. R- }2 u# f. ~' Ato unit_plan 6 o. o% E; v; k6 N% e/ }# N
ask turtles [/ g* C, W5 I* O6 `' ~9 }" C' B
if (remainder who 5 = 1) [set a who
; w! X2 v; ^* K: a* x, T& K                          set x ( 0 - Wid / 2 ) 2 [; L; m5 {( p+ t# _# r
                          set y  Dep / 2 ]# T: {/ i, |/ T) J& L) {; K
           set b  int (a / 5) * 58 K, W6 w4 o) a' ?, s
    setxy ( xcor-of turtle b + x )9 Y/ p) M( g* q& V1 C
          ( ycor-of turtle b + y )" Y$ H1 u: l0 C; l8 d3 Y
if (remainder who 5 = 2) [set c who
' E" I, F% v5 l, X                          set x ( 0 - Wid / 2 ) & B# ]( ~1 Z% H+ K7 A: c
                          set y (0 - Dep / 2 )  ]% p. b$ Y' T9 N7 T, I, O
                          set d int (c / 5) * 5- E; |( s* {% q+ h9 S0 P$ Q- ]
   setxy   ( xcor-of turtle d + x ): I' j8 P  S' R: V2 I- l
           (ycor-of turtle d + y )
3 q# U5 G" i9 X( m4 K' g         
/ n: ?5 w9 H0 t, y; A            
# p: t. Q% }% ?  A% fif (remainder who 5 = 3) [set k who
4 x4 R2 h1 T/ B, W                          set x( Wid / 2)  * k% {: b) s7 X5 W. H1 @. D: M
                          set y (0 - Dep / 2 ) ]
6 _) t  A- U& r                          set f int (k / 5) * 5
- w5 z9 }2 A5 K) ~0 ]  setxy   ( xcor-of turtle f + x )* x1 h- W( |$ [, b' @. L  D; [
           (ycor-of turtle f + y )
5 K0 R2 h0 ]5 {1 s7 C/ M" x5 }           / b5 ~+ }" r: y+ U6 z+ ?, H: W9 B
           
6 V$ C; N( I% y) xif (remainder who 5 = 4) [set g who
; \; k4 j+ s1 \$ w                          set x Wid / 2 % s1 X2 O4 I: v$ n% U3 V1 W
                          set y  Dep / 2 ]4 e! {# ?" g3 U8 \$ w
                          set h  int (g / 5) * 5
9 a% K: v# ]! M! r/ I( _2 O- T" E$ t  setxy   ( xcor-of turtle h + x )
* S$ s( C* n; w% @' ]           (ycor-of turtle h + y ) & S- E/ e3 ^6 v& e6 U
                          
; H( {3 u' R2 C+ U                          7 S1 {3 |5 W2 `1 u- q
                          ]0 e' X0 H- p- `. O6 v
end1 i2 b& w2 N9 {4 c) H

1 K# C5 t* ~5 q4 V; e[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
/ l5 r$ u0 t  M7 I5 c* T8 Z( h应该是9 @9 E' l) `7 Z& k$ j
ask turtles [; F% W+ Z- e$ R7 C! B& `: h! E
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 1 I! `5 I+ E! v* z0 g  U# W
                          set y  Dep / 2 6 b' u+ s. ]9 x- B" w, _4 a; ~
           set b  int (who / 5) * 56 G( n/ n" T' o0 G5 j3 M
    setxy ( xcor-of turtle b + x )
% b+ M. a8 Q  T* C          ( ycor-of turtle b + y )]]
9 |1 }. U: i( C. dend0 C; h1 ^4 i9 Y5 x! S
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-7 07:28 , Processed in 0.013606 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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