设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7619|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。# \, ~1 l9 x; n0 X
$ X5 e' k2 T) M
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。. V" I7 d0 @: L/ h3 P: K& t
6 x" B6 u7 g6 y. \. |0 z% B! E! u5 L
turtles-own [a b c d k f g h6 p$ E6 d9 g6 D# H
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
; y! X6 N+ u, L0 X' l]( N) T& m7 v3 p5 L3 w0 t" F% b. Q
to new0 B" @$ u) d4 r$ G5 {9 ~
  ca
- ?- C8 H, m# s$ @) W) U! l1 {6 C* m  crt 5 * num_of_building6 v; ]9 ]( i* \4 X  R$ D7 J6 k
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
3 c4 O8 `/ k; U7 w  scatter     ;;keep center-turtle random positions
) s; ?* O1 }4 |4 k3 @  unit_plan   ;;make up the building plan
! Y2 G0 ~5 Z/ ]end
; m. z5 y& H% i. T/ Tto scatter5 a: T6 p( P  C( i; a: c
ask turtles with [remainder who 5 = 0]
1 X- [& [, }9 ~, x3 e! E[
: r  {+ f# P1 V' }! `1 u2 kset xcor xcor - 6 + random-float 15
# |( E0 L3 f1 vset ycor ycor - 6 + random-float 15+ y  ?7 G) n. @8 B5 G  d
]
. w" y$ N; c) \7 ?1 V7 @1 mend
: Y* S& T/ d- U9 c* m. D1 a' Dto unit_plan 4 S- B! J0 u, X" o; O! V: Y
ask turtles [
) G! V6 \6 r( [. R6 rif (remainder who 5 = 1) [set a who 7 H3 z2 l3 l+ l- i: q: I! A4 z/ `
                          set x ( 0 - Wid / 2 ) 0 }3 D& y6 G5 p% v
                          set y  Dep / 2 ]4 k& V  {( o" V$ v" ^  S% E
           set b  int (a / 5) * 5% c0 W3 S- @# A. o9 [) j
    setxy ( xcor-of turtle b + x )
# J: K- B- h, g" n9 I% R1 F2 {          ( ycor-of turtle b + y )9 X3 s% Y0 w9 r2 X2 Q% e, ?
if (remainder who 5 = 2) [set c who  ?# M& [. y  `6 o+ Q( R1 f, @
                          set x ( 0 - Wid / 2 )
7 |% ]2 N  e+ n2 O0 }" r0 x                          set y (0 - Dep / 2 )  ]/ h7 ?% R- [9 |7 c0 O
                          set d int (c / 5) * 5. I$ @3 U( K. A& L* O' m
   setxy   ( xcor-of turtle d + x )
* ?9 W/ `% |, U& L$ l           (ycor-of turtle d + y ) * D, q& b( g: J0 O
          / X% G6 K6 Y0 B' H- K0 e8 I; J. x
            - D4 b9 W- J1 b2 d  ~$ L- f2 \
if (remainder who 5 = 3) [set k who' b; N) }# \9 P* p+ K2 T
                          set x( Wid / 2)  
! {( L1 n2 Y% w1 b                          set y (0 - Dep / 2 ) ]" i: U1 i- F/ M, L1 P" l2 ]
                          set f int (k / 5) * 5) S% V  Q# M9 L1 c
  setxy   ( xcor-of turtle f + x )
0 C5 E% U, B1 G5 v           (ycor-of turtle f + y ) 5 l: b" p& _3 t' i4 v
           , K( z. N- E, O: n9 U# s" c4 B5 `' @; t
           
9 d9 H1 S; X) f9 j& ^! Zif (remainder who 5 = 4) [set g who1 v/ Z& |. f3 B" a9 d7 |  u
                          set x Wid / 2 ! ^# H+ B( {% w  a& f+ q4 ~! s
                          set y  Dep / 2 ]
; U3 p" p8 H* K                          set h  int (g / 5) * 5
5 c8 M( f7 O, O$ t  setxy   ( xcor-of turtle h + x )
# E! M) C) k8 k) C           (ycor-of turtle h + y )
! d* N+ F) ^' I6 Y                          
* ]1 N6 k$ Y+ q9 h$ H  K                          
! X  h/ N# v1 I' |" j1 x                          ]
1 ]. M& ~1 ?2 [4 O  cend
" Q) {: c% p5 j5 e6 }
9 H& ?' u  {4 X( o( X3 J[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,, K9 f: f8 \6 R) Z& {3 i
应该是: V/ b$ @  F) K) W6 X9 L
ask turtles [% }+ A/ @. I# m- c0 P' h
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 7 o' H; c8 N5 o( ]0 f" l( R( p# ?
                          set y  Dep / 2
" }" P7 s5 ?$ e+ H           set b  int (who / 5) * 53 X5 g' B+ K- a: d6 B- }; O
    setxy ( xcor-of turtle b + x )
8 e/ h5 i, E/ J+ b; k+ ]          ( ycor-of turtle b + y )]]- j# e1 ]3 F. j, P& D* s
end! B' ^# V5 O6 V5 P  j4 f
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-6 12:47 , Processed in 0.014427 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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