设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7336|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
" e" J5 J( H. L/ d: @7 s! u4 x4 O$ R8 l8 j% K
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
" W  _  ^' S5 d7 b  r& |
, Q) O+ o; B# I! b" m2 _* Eturtles-own [a b c d k f g h* N& r$ z  Z/ W% B
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
1 `' J: p- k: c5 ^]
7 R& H& t3 s% n, qto new
0 W6 }& Y) C- o$ V5 Q  ca
: e3 m+ v8 y; ]  crt 5 * num_of_building$ t2 c( X, f" w' f5 _
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
7 B" v7 `* ?5 A5 S  k  scatter     ;;keep center-turtle random positions + u3 |' q, W1 o
  unit_plan   ;;make up the building plan$ }3 m  Y& S. L) B- c) m3 o: u+ o# A. q
end
! `% U% d+ o# I5 ?- fto scatter1 G) }. C8 Y# K1 ?6 Y9 J% ]
ask turtles with [remainder who 5 = 0]" Q4 w4 ?' \% d* p
[
$ Z) i4 o% `: y9 p/ A) iset xcor xcor - 6 + random-float 15- b, P- [5 D- a# D' L1 O+ V3 @
set ycor ycor - 6 + random-float 15
# t7 v5 s- t" p% P]( @% V6 R7 W: c" c
end+ m4 }- m! E7 a! X: F( n3 z; R. K
to unit_plan * y5 b, k% T* Q+ e2 Q
ask turtles [  y$ f/ X/ R: P4 J
if (remainder who 5 = 1) [set a who . M; E$ \. _8 }/ z4 Q5 Q
                          set x ( 0 - Wid / 2 ) ; i5 Z9 D3 P7 K& A; I) a# d
                          set y  Dep / 2 ]1 e9 R3 _& w$ |9 t9 [
           set b  int (a / 5) * 51 A  d) i, @/ F; E+ ]! J
    setxy ( xcor-of turtle b + x ). S8 i$ T$ x' Y7 n
          ( ycor-of turtle b + y )! l) V3 o1 E! E6 K( P3 u3 o
if (remainder who 5 = 2) [set c who
$ C/ c# f' o# W) A                          set x ( 0 - Wid / 2 )
) V$ b* m1 l, B+ j& g                          set y (0 - Dep / 2 )  ]
( H6 h9 D( i7 V6 `: h* B* }3 c                          set d int (c / 5) * 57 m: y% I# H) U8 D
   setxy   ( xcor-of turtle d + x )
( w2 d& @# b9 O1 p3 F, m7 ]8 v( b           (ycor-of turtle d + y )
- U" D7 d# e$ n( B' C+ ~6 o' h          7 \9 t2 S* j" _
            / O1 S. t$ j9 q. D
if (remainder who 5 = 3) [set k who
8 Z, ]& p7 w' c                          set x( Wid / 2)  
  G8 n( Y$ s0 J' b) N. r% [# s                          set y (0 - Dep / 2 ) ]
& M5 F9 G+ f# A1 w2 h7 K+ T! B( ?# r                          set f int (k / 5) * 5, ~; b( l; z' e5 ~' u# {1 Z1 e2 R
  setxy   ( xcor-of turtle f + x )$ a- f1 h, D7 R
           (ycor-of turtle f + y ) - {  }0 x, i2 z* a  A4 p$ U
           % x! y% q( r; E. a' v7 i
           
; O8 {) y1 \- `if (remainder who 5 = 4) [set g who
* J7 z# I$ l9 B/ H6 ~                          set x Wid / 2
( N, Q! T- A; q& O* r                          set y  Dep / 2 ]6 {/ _+ `- T' b7 b
                          set h  int (g / 5) * 5
! d" @5 U1 V7 [  setxy   ( xcor-of turtle h + x )8 O$ I  H$ ?/ I& |; ?
           (ycor-of turtle h + y )
) c0 Y$ s+ K* D+ [+ e, W/ F, U                          1 R; D7 e$ o% L
                          9 X7 P; G9 A5 ?1 e- Z1 ~
                          ]
" I0 A6 ^: q# J5 V' Y: Zend
/ j; P& {2 z  i/ O- L, p3 T" p
/ j- |; b- X0 [5 `  Z6 U[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
" f2 B6 Z1 [9 K0 j6 [8 O6 V1 C应该是3 N, q9 X' o0 X9 T, U' _& r) Z
ask turtles [5 ^4 @/ w, I' e( ~
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )   m# p% K; T  T9 o+ U5 K# v! ~1 J
                          set y  Dep / 2 2 c) u  k0 e5 Z, @: [! N
           set b  int (who / 5) * 5, \# e6 t2 \4 ]/ Y! U; d
    setxy ( xcor-of turtle b + x )+ g1 x- S: D4 s" ~, b" S: A
          ( ycor-of turtle b + y )]]
8 \% _  I  E. j+ Q6 L" z! _end
6 h9 j# U$ a% e3 r8 B/ i/ r: V6 |之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-30 18:58 , Processed in 0.017802 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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