设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7918|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。! n% w- H6 l' n( _
" P, `$ o, |- n. H
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
5 H* R$ S5 v$ C/ l4 s/ k3 V! g/ X6 q7 ?* Z/ d0 Z
turtles-own [a b c d k f g h2 t& u9 G; r& j7 A5 I& d7 P$ r: Q
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ' K) k+ S* K' h6 f+ I# N6 l& g8 K
]' X1 i# x6 C7 g
to new
# O; t5 W2 e/ i: H  ca. R- n; g& F, T' d2 X' k7 N
  crt 5 * num_of_building
. G, y2 y( d, Z; K  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
9 F) I  ]+ D# n* t5 V' J# U  scatter     ;;keep center-turtle random positions 1 _, W" W: o1 u$ y6 j5 Z5 w
  unit_plan   ;;make up the building plan
. \. [! l9 p  Z9 l5 c5 Qend& n1 a, v$ j  h; c& L
to scatter( H8 M# F! _+ k3 V! O1 h
ask turtles with [remainder who 5 = 0]3 H( d; I; u6 K( A  K+ A( {
[; V1 a. Z& {6 y9 w
set xcor xcor - 6 + random-float 15+ t8 M/ e. V3 {6 d- R
set ycor ycor - 6 + random-float 15% P: n6 D# v! p: k; H& }
]
4 a; a/ |. P5 A7 y3 W8 j2 zend
0 L( X- b/ q# P, {8 j% uto unit_plan " r) j3 b1 M, d' j
ask turtles [* k8 W- B+ a: ^8 U
if (remainder who 5 = 1) [set a who ' ~& r" P0 \- H, w" C$ D1 y
                          set x ( 0 - Wid / 2 )
( d; P4 I( C8 \! ^* Q                          set y  Dep / 2 ]" v  V; z9 V1 x4 U5 z' e5 V
           set b  int (a / 5) * 5
4 q- P  O1 C/ J3 J7 q    setxy ( xcor-of turtle b + x )' ^& d& n) `7 Y; r) t3 k
          ( ycor-of turtle b + y )5 D5 X% z; a+ R- q5 ]( \
if (remainder who 5 = 2) [set c who
4 |- H) m- H0 y$ P. u8 V                          set x ( 0 - Wid / 2 ) # x& Z, t, v. e* t
                          set y (0 - Dep / 2 )  ]9 k# v! m2 j) E" k
                          set d int (c / 5) * 52 B/ q" y  \* y
   setxy   ( xcor-of turtle d + x )* {0 U* S& ]+ E
           (ycor-of turtle d + y ) $ w4 b8 u* L- G0 G: s- [/ ?; M
         
% V: k- L& U+ f: b% N            1 n- Z. `3 S1 V9 b; i2 `
if (remainder who 5 = 3) [set k who
1 z0 G- e& ^- }4 Y& t' z  M' r                          set x( Wid / 2)  8 Q3 b; k  Z3 g3 w  n8 Z
                          set y (0 - Dep / 2 ) ]
% P2 C2 ~- R6 P2 Z" }( r' l                          set f int (k / 5) * 5: z$ Z& F$ c6 Y" x" t) Z
  setxy   ( xcor-of turtle f + x )
, f* _9 p( G4 e1 e/ ]           (ycor-of turtle f + y )
+ q+ z) \8 b8 p. ]/ q5 b9 O/ P           
' A6 t5 N" [% h; U8 d3 P" \3 u2 S           
& H. F* G) h) L" Cif (remainder who 5 = 4) [set g who
0 K" N( K5 F9 c7 v; c# j                          set x Wid / 2
  F/ d/ L& C* N3 n1 f                          set y  Dep / 2 ]
. N2 f$ f4 j3 p; K7 g                          set h  int (g / 5) * 5/ Y- P! M/ a# C: G
  setxy   ( xcor-of turtle h + x )
( Z. o2 j( d& |$ H1 u4 R+ U9 b4 Y           (ycor-of turtle h + y ) 5 h4 D" J+ I5 K. N7 D4 p. g, d7 _* j
                          1 D. f% ]: P* F. }$ v
                          
3 U2 j9 n9 b9 |4 v2 _' g( P) D                          ]
3 T( S+ K: i, D6 P6 Mend
! I7 r; A1 }2 T0 W0 m! [3 Q0 J1 ?  S
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
" C3 P! t( W% X; j应该是
4 n' N) N0 J) h6 B# Eask turtles [
: c% |4 n& ?  @& ?$ yif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
3 \4 g3 z9 w8 j3 V$ L- }4 }                          set y  Dep / 2 2 G, B( x" j# F* p( h- M
           set b  int (who / 5) * 5
8 R1 U; d) @5 S. X+ o    setxy ( xcor-of turtle b + x )8 \- K, r" {! a2 E- F/ H
          ( ycor-of turtle b + y )]]
3 a+ H6 r* V, qend
8 H9 Y3 E- R, q之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-17 18:01 , Processed in 0.017003 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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