设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8506|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。+ U& ]0 T% ^9 y3 O. \  H, k

. k5 s0 @) U. z0 f- ?8 _0 |但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。0 T0 \+ S) n# l
+ e) X) R/ C; b; a" p2 ]7 j
turtles-own [a b c d k f g h
2 h+ _% N/ o. q- b% Y  s  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 3 k% {, G5 G5 ]% B
]& ^# d$ k! f: d# Q* x
to new5 N  s" ]5 t& S0 d( F, d9 O
  ca
1 g8 t/ y" m* d3 E5 b( j  crt 5 * num_of_building
6 g( d/ X4 V" n$ I  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]: ]8 v- c- c0 K/ Y& o
  scatter     ;;keep center-turtle random positions 4 B' J4 P, q- F$ D, W8 L# O
  unit_plan   ;;make up the building plan
$ u, m2 ?5 c! V) O+ D4 L- X9 Wend! y% G( t  Q* F+ _. u8 m1 _
to scatter
% T6 T" j8 M9 H' O% yask turtles with [remainder who 5 = 0]
3 x2 s# j7 R6 V3 y8 @! b9 c8 x+ z[
) t4 \6 r# Z0 D) M; Hset xcor xcor - 6 + random-float 154 A1 C; o. s+ P. J+ Z- B
set ycor ycor - 6 + random-float 153 `) m. ~* q1 c, r4 T# n( z
]6 V& E8 R, `( a) o9 ~$ {/ y2 O
end2 @3 N5 t, Q4 e# @5 s7 l  T
to unit_plan
& N* F! u" L' Xask turtles [
- f" V% E9 w% `' [% Sif (remainder who 5 = 1) [set a who 0 A5 K5 s% n; r' k, w
                          set x ( 0 - Wid / 2 )
( ^5 H) y! y: q! V2 z                          set y  Dep / 2 ]% _/ q2 n. T! u" _! I3 l. r3 Q1 S
           set b  int (a / 5) * 5" r% e( S+ @$ z
    setxy ( xcor-of turtle b + x )) R( h* R7 l# Z! d7 x3 w! v
          ( ycor-of turtle b + y )! v# Y: y; R" C; ~: D
if (remainder who 5 = 2) [set c who" E, a+ X8 ~( V3 F
                          set x ( 0 - Wid / 2 ) - a& N: y- w) q# R  {
                          set y (0 - Dep / 2 )  ]
* i7 O& t! ]5 A  F0 M3 K                          set d int (c / 5) * 5$ ?2 b; z( Z7 T0 T  z5 X) s
   setxy   ( xcor-of turtle d + x )4 J- b( J/ P1 O9 e4 e! E
           (ycor-of turtle d + y ) 6 a% y% f0 j' s$ P
          & F8 k/ u" X0 h( c9 [4 L  t
            
5 q' j4 g. U  f6 s/ _+ kif (remainder who 5 = 3) [set k who3 Y: J! P. @! A7 R3 i
                          set x( Wid / 2)  
& G' b6 t8 K* d/ N, T, }5 U                          set y (0 - Dep / 2 ) ]
/ g( {% G4 ^- H7 X, A                          set f int (k / 5) * 5
& a. e/ ]' G8 q* n1 l  setxy   ( xcor-of turtle f + x ); ]" B/ A- R( \3 I; o
           (ycor-of turtle f + y )
4 [/ f  C8 X- x/ G           
7 y! G* ^5 O, D; t+ W. l           
6 {) `5 @! c& {1 Pif (remainder who 5 = 4) [set g who
  k! M1 w' P- V8 E! Y7 o                          set x Wid / 2 5 x, X) s1 `  i. ^; Q
                          set y  Dep / 2 ]+ U+ r5 p/ s: m  d0 C/ w
                          set h  int (g / 5) * 5
4 D  N  B8 [* i6 N8 C  setxy   ( xcor-of turtle h + x )6 v; N# A' e: }# C) {
           (ycor-of turtle h + y )   Y9 a& a- e& p! V( i; Z6 a9 H- c
                          , q& H+ M( j- X9 @2 C+ F! r! A
                          
1 L7 e0 G* B$ l( F0 d. p5 k                          ]
, W- _5 A  Q; U) P# R" J, Lend" M0 U: W  g0 U' {2 Q8 X

' a0 L- b% e* G& H+ E7 T4 g& S[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
8 J* `, s2 [6 `4 O应该是5 P$ w1 ^4 d! y. a& Y1 Y, _$ r
ask turtles [1 s2 o4 q% y8 ^+ D7 ^& t
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
2 K: _$ C! J/ ^                          set y  Dep / 2
6 L+ k% f; M# S* A* z% G  V           set b  int (who / 5) * 5. B( E1 i$ A$ n! F3 m- g# P6 [9 u' l$ [
    setxy ( xcor-of turtle b + x )# X+ ~' f) z! v+ e
          ( ycor-of turtle b + y )]]
; F% w# @& ~; m- ^8 ~end
9 @1 ~; y3 j) A之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-7 05:29 , Processed in 0.013834 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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