设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7859|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
. S- ~2 F, P  j6 [5 y  a2 d
- T) D4 y& y3 c( U  _7 f$ x/ b但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
! ]* \: v9 J) b- e7 |' l. K4 a. K% H) Q
turtles-own [a b c d k f g h
& ?5 X- T4 S. l* H& G  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
$ r2 V( V8 s/ D0 P5 z]3 E/ b* J$ l: s& I, [7 A
to new8 V; t, M/ \2 \1 ^! S
  ca
  \" u8 _8 t( Q! A  crt 5 * num_of_building
) J; F6 r0 d/ |1 t: ^% t  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
/ I- u- I' C2 f3 ]* F- Z  scatter     ;;keep center-turtle random positions / ^0 X" g: j2 H' o* @9 Q
  unit_plan   ;;make up the building plan# _. h# D* C( Z! i5 Y0 o, c9 \
end
$ ^' l' `, a; n9 G$ z9 b# Q3 mto scatter
' o4 `- [1 Q, x" nask turtles with [remainder who 5 = 0]% p2 B# d- X- {
[7 }" Q+ w$ r& k2 \/ {0 m
set xcor xcor - 6 + random-float 15
+ p/ h6 n- I$ w: C8 Eset ycor ycor - 6 + random-float 15
7 J! ~" h0 r( r0 _8 }]
" K% r& A3 s8 Zend7 s1 J& p* n, p4 F
to unit_plan
6 D' I' x. l" s: A! D0 F+ iask turtles [
4 M+ c. ^5 @6 _. c0 t" Lif (remainder who 5 = 1) [set a who
$ k. e% r! n4 ^; p4 Q- ^                          set x ( 0 - Wid / 2 ) 8 U5 E" W7 y" G2 K& O
                          set y  Dep / 2 ]5 O6 X% z' e3 Y, A
           set b  int (a / 5) * 52 h6 [" o$ I! b$ q5 {
    setxy ( xcor-of turtle b + x )* o+ K5 p) U2 e/ O1 y
          ( ycor-of turtle b + y )' B! p8 B6 f: I* v! S- R0 M. m
if (remainder who 5 = 2) [set c who0 ^% H2 }: s& n) F  l
                          set x ( 0 - Wid / 2 ) $ V' c  c0 I% \2 K4 F& d7 m  K2 d
                          set y (0 - Dep / 2 )  ]+ a$ q, o) T/ o0 @6 u. `
                          set d int (c / 5) * 5) O- z4 @. C; X
   setxy   ( xcor-of turtle d + x )4 e; p) J: ~* \# L2 T. W9 \
           (ycor-of turtle d + y )
, N0 P3 e+ L) @' J7 ^( t          * t" s3 r- d% j3 n7 j
            
. U) e! z; @. a0 }3 Z6 t8 Pif (remainder who 5 = 3) [set k who
3 j/ g8 b6 J, n" b                          set x( Wid / 2)  + r  n, S6 H9 d* ?  X
                          set y (0 - Dep / 2 ) ]6 k3 M2 T0 N  O/ Q" z$ T* b
                          set f int (k / 5) * 5
! Y; v! x6 C; n  setxy   ( xcor-of turtle f + x )/ K+ m; d) Y5 B8 v/ q0 t) ]4 }
           (ycor-of turtle f + y ) ; a2 h* o0 B. @% s5 w# T
           ! z# A9 k1 h& @; a6 s( ?3 g& v
           % _$ }! w2 H7 N+ A
if (remainder who 5 = 4) [set g who
2 e! H$ T# @2 y9 b6 j; ]  V                          set x Wid / 2   l- `, M6 ]9 Z/ U5 \; E& U8 q9 B
                          set y  Dep / 2 ]: Y( p  J" {9 U+ V7 P7 z+ L7 u
                          set h  int (g / 5) * 5
3 M8 q& Q  I# ^" r* A0 X9 e0 z6 J  setxy   ( xcor-of turtle h + x )9 |+ C+ P% l; [, m' y
           (ycor-of turtle h + y )
( P  o, e# S# e* p4 m6 @                          
# {1 N6 v; Z8 j; h( C                          / r3 s! v2 g; ^$ [  z' P
                          ]0 _  G# Q: ?7 {; V$ R9 x
end
. S" D" \8 w# ~" g2 d! Z+ ]0 L1 p$ o  _9 s" o0 `# G
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
0 Z3 C$ ?3 s$ x7 M/ o% f应该是
/ Z9 k2 w+ n: `) ?5 N1 Rask turtles [
" f3 [  D6 V( N2 s( @% x6 P/ Kif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 3 |, `* C! j% [! m1 B3 J4 O9 V3 Q
                          set y  Dep / 2
& _2 ~& `) {  v/ P           set b  int (who / 5) * 5- j4 m9 Q( f" M2 W
    setxy ( xcor-of turtle b + x )- w  [, |, L( j( m0 P
          ( ycor-of turtle b + y )]]
4 c1 L6 Z2 p) pend) N( Z/ z2 z$ v
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-11 16:50 , Processed in 0.023026 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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