设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8448|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
  C; `2 m* q* _7 _
4 N- `$ a/ F& r) N3 T  ?4 Z; U  b但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。8 }' I6 R2 g$ Q9 P0 P7 v0 R

& I# x3 ~1 d, N. h+ Oturtles-own [a b c d k f g h/ L. }5 G& I% S- \0 a
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
. ~3 W) T" S2 Z]$ G- |% Q, h6 Z) t' Q
to new2 V. n2 Z( v) m$ f4 Q% {
  ca* x6 x' Y* C5 b0 Y
  crt 5 * num_of_building
% x" a- F( p) `+ o5 S5 I( A0 C  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]' ^+ z6 ^5 x0 q- c
  scatter     ;;keep center-turtle random positions
4 ^. y( Q' S  [( }2 O& {* P  unit_plan   ;;make up the building plan  m& u4 g. l7 ~8 i* a0 b4 y, l8 ~
end
  B3 l. {6 C, \1 h5 V& e  |to scatter
: [& o  X2 x0 S2 vask turtles with [remainder who 5 = 0]
. b: J1 i7 B: l* }7 Z[; Q4 f" u! ]5 S
set xcor xcor - 6 + random-float 15
# o( y: d3 S- W0 I6 t0 U! D' Cset ycor ycor - 6 + random-float 15
2 }: X- @1 y' g3 g! E0 Z( u]
% P5 ]8 W6 x" C1 a; ]# @( ^1 Zend" D# t0 u5 {1 O2 {" K, N
to unit_plan 0 V2 k& D4 L. X3 s6 P0 B9 }# d/ h
ask turtles [
8 y$ v2 K  G0 Q7 W& G% `if (remainder who 5 = 1) [set a who
4 v6 Y- s/ q( ~5 x9 o9 A                          set x ( 0 - Wid / 2 )
& _( Y' {1 B4 Y9 w                          set y  Dep / 2 ]
. X# h7 R+ X( Z  F           set b  int (a / 5) * 5
3 P; b8 e) ^2 q* y    setxy ( xcor-of turtle b + x )( }/ y+ q" Q+ L1 L$ Q+ R
          ( ycor-of turtle b + y ): z* h1 B6 j2 S: ]) A7 j- Z
if (remainder who 5 = 2) [set c who# B/ M- H5 U2 ]# D4 a
                          set x ( 0 - Wid / 2 )
4 V  l  j, s0 F7 `0 A  a8 x. c' d8 n( Q                          set y (0 - Dep / 2 )  ]
) ^/ x) \1 A$ u" t! }, Y                          set d int (c / 5) * 5. {) Q6 I9 r) ]1 n4 K8 G
   setxy   ( xcor-of turtle d + x )6 [6 k0 f2 T7 n/ @2 w( o' V
           (ycor-of turtle d + y )
) k& A) R* [' ^; U- p3 w. B2 a          0 {6 }* {6 s4 o9 ]) e; \- O
            
2 b3 H- c- a, U8 L; Q" e* zif (remainder who 5 = 3) [set k who
' H9 _  A* P" S: ^" b+ R                          set x( Wid / 2)  
8 I2 `0 p# C9 K/ R9 o                          set y (0 - Dep / 2 ) ]; Q, T, s) P* R3 L  ~7 Q
                          set f int (k / 5) * 5
& J$ }3 u  V2 l. @6 s  setxy   ( xcor-of turtle f + x )& B+ B9 Z+ O. I  N
           (ycor-of turtle f + y )
" c0 l  G/ D/ b& r( ^3 m0 {% d           9 R8 J, c7 j; M8 m, ~8 w4 o/ @
           
5 x7 [5 l7 \& B3 e0 E8 ?if (remainder who 5 = 4) [set g who
% u  S1 [1 l: F; X7 c0 @                          set x Wid / 2   V/ F0 [( j- x  B8 d/ N# _
                          set y  Dep / 2 ]
) m  j4 D0 w2 Z' d6 g& d# O6 H                          set h  int (g / 5) * 5. N) L! q2 [& d+ R. O
  setxy   ( xcor-of turtle h + x )# q7 b$ H4 H4 a# A* }: k
           (ycor-of turtle h + y )
+ K/ M6 O5 P( |4 b6 K5 C2 Q                          ! ]7 U6 S# b$ n, G. B. L
                          " j% D, ~; X* D- j$ |& e5 M$ P3 g
                          ]# n$ Q7 N4 T9 r# i( `% a5 I
end) h# e! }2 d9 ~6 W. w, y  a; x1 t
, |) ]4 `) j- S4 H
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,6 V5 a# N  x1 I" [
应该是
; O3 ^9 V7 ~$ {ask turtles [
! T7 y: [8 Q, j4 O$ u- `, lif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 2 L' ]# U1 _. m& q
                          set y  Dep / 2 ) u6 U% [  Z  b3 V6 K
           set b  int (who / 5) * 5/ k7 D# K; y4 T  Q8 U
    setxy ( xcor-of turtle b + x )9 [; l1 U( ~" _; `# w1 ^
          ( ycor-of turtle b + y )]]+ T5 P2 j( i9 j4 \( H$ Y6 F
end/ G" T6 Q+ N$ Y  U" Q6 t  H
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-27 04:07 , Processed in 0.013268 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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