设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8213|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
  j. q4 a$ ^/ q4 F9 {9 a+ E/ K3 p! _5 r
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。# i" p: f! L, F9 y+ G% N
* g5 L* b9 K/ V  {( \0 F) ]3 E
turtles-own [a b c d k f g h4 @6 U: t% [* d' M% b
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle * C9 o& M3 L0 L9 z, x2 M
]) q9 O2 N' H$ J, A- y; z
to new  J: _; z7 n* |. X8 d
  ca
5 |" S- g3 ^% Y' _$ \  crt 5 * num_of_building
! ?4 x1 J" P. ~  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]- [5 M9 |4 O& \8 b
  scatter     ;;keep center-turtle random positions : x& P/ A" V5 U! O# [7 ~# \
  unit_plan   ;;make up the building plan1 M& k3 w# S/ ~$ Q* W, V( ~* Z
end: R) w) x$ w5 M7 Y- j
to scatter' k& T; Z4 V6 L  [  }6 }
ask turtles with [remainder who 5 = 0]9 o- o% _2 a% k
[
& H6 [) Z/ l3 n: vset xcor xcor - 6 + random-float 15/ y: h& ?# ?  @- _( n3 @8 @
set ycor ycor - 6 + random-float 15
) O; S' m2 D! Q+ i4 x]: h: z4 |# r" i5 |/ h; A
end
8 l% Y! Q) d! b6 |( k' T( n3 @to unit_plan 1 Y! n# k* Y/ W
ask turtles [" Q  ]. R2 U% Y: Y# B' w& I3 r2 v& t
if (remainder who 5 = 1) [set a who 5 e! Y" s/ m- Z9 q# l4 v6 U
                          set x ( 0 - Wid / 2 ) 8 K& P2 l' t3 d9 j
                          set y  Dep / 2 ]
: G# s# }# \! M4 a, n+ A! P           set b  int (a / 5) * 5+ I  u) B6 u! _" s& i$ d$ V: Z
    setxy ( xcor-of turtle b + x )
& b% K" u7 \6 I% l/ v% f          ( ycor-of turtle b + y )
# V) A% F1 I. U: F3 R+ W4 |if (remainder who 5 = 2) [set c who
. e# q7 F7 _4 s2 c: u8 o6 v                          set x ( 0 - Wid / 2 )
& J; w7 A; D5 D8 z. g% B                          set y (0 - Dep / 2 )  ]4 u# Q3 C/ {4 L! x4 V( @
                          set d int (c / 5) * 50 @- Z# ~7 j7 a9 Y, }# D8 }# k
   setxy   ( xcor-of turtle d + x )
' N' C4 \3 V0 M1 {9 a7 O4 H           (ycor-of turtle d + y ) ' ^2 Y; R9 ~5 i
         
$ W; I1 b( ]  D4 d; C            2 e4 d- b5 J$ \" R7 s
if (remainder who 5 = 3) [set k who" y( u3 B. F1 H5 O$ Y
                          set x( Wid / 2)  
7 g+ D5 w: P4 n/ V                          set y (0 - Dep / 2 ) ], |, a0 G4 u2 p  a& E) m
                          set f int (k / 5) * 5
3 `3 \- j# O6 M8 ?7 R, @1 Y7 @  setxy   ( xcor-of turtle f + x )
  |2 e) ^7 \7 H8 i+ e           (ycor-of turtle f + y ) & U* S0 X5 ]/ b8 P, \  y
           
) t1 \" U) _8 l& K# ~$ E* t" G           7 Z2 G; t& h: k: x" V4 d
if (remainder who 5 = 4) [set g who3 R0 O3 D- X, S& q
                          set x Wid / 2
% u1 ]5 L1 m% F, v                          set y  Dep / 2 ]
' s# K$ V6 [$ ]' O8 l                          set h  int (g / 5) * 5
6 ~% E& e& X: z; X  setxy   ( xcor-of turtle h + x )
- f9 O1 ]  X& ~% T! E           (ycor-of turtle h + y )   R; C" D% M- [; e1 v% F0 \
                          
- I3 {" o! r2 R' y) @                          
% U( J+ x( J' ^6 `+ f                          ], I( l! X0 A$ {3 A% v
end
$ y, V5 b5 _& }9 W+ ]6 P4 c* t9 s5 ]& ~
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,/ x% f# P. c1 Y
应该是
. t0 v# B+ U% C" [* L0 C5 Mask turtles [! t# g* ?$ O0 K. x! N1 `* Y
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) % a7 \( {) R; P9 v" R
                          set y  Dep / 2
9 N3 T4 _& ~7 H           set b  int (who / 5) * 54 s* q, B: H. W% K2 g% O6 B! l
    setxy ( xcor-of turtle b + x )# `2 M" [$ c4 K/ O0 |7 C2 |
          ( ycor-of turtle b + y )]]
7 k  T3 L" X+ o9 S. Jend" J4 ]! D- L+ f2 Q% ?. ^
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-19 22:19 , Processed in 0.016519 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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