设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8435|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
4 @2 M5 O6 Z8 g& m5 ]8 s2 O1 F# ~# z+ P1 A
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
) Y* a# S* _9 @- k  U- p6 X: Y6 u# w, _7 `' a4 m' m
turtles-own [a b c d k f g h1 ^, V2 g& r) D0 v6 N& w
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle . z* ^" I* ~. _* y5 e" f
]+ ]9 [4 U( W$ r% V2 o- [6 `5 m
to new
% v$ D' Z1 _+ a: r$ R1 I  ca
6 _$ ]8 ?, ?+ E- Q' _8 S! n5 C) O  crt 5 * num_of_building
1 v6 ?+ Y& p, }' Q4 G+ Y  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]4 J4 C3 S# |8 H1 R# L9 d
  scatter     ;;keep center-turtle random positions
+ e6 `0 S( b2 P# d  unit_plan   ;;make up the building plan
! Y$ L* l; w$ C* n  cend+ e, t  W; W0 Y% W# @" }( Y
to scatter; m  ?: Y9 F- T3 F
ask turtles with [remainder who 5 = 0]
7 h$ {, r9 G6 Q5 h% N[
  D- B8 X& }5 L% b1 nset xcor xcor - 6 + random-float 15
4 |% U2 o0 r% E8 x3 eset ycor ycor - 6 + random-float 15
1 a% }5 _: a) S- O# R0 Z9 ~], e. O% p/ T1 L* {# K( N
end
% `( J, r* x4 oto unit_plan
; H4 I! S% N! R9 Gask turtles [
9 ~% _* |4 u9 J+ cif (remainder who 5 = 1) [set a who 9 ]8 ^9 W, X: G
                          set x ( 0 - Wid / 2 ) 5 p7 {( T# l2 X. @8 j: E
                          set y  Dep / 2 ]
- x  V) T% |3 C: S           set b  int (a / 5) * 5& F5 f9 g. s4 i; j; V' P/ o
    setxy ( xcor-of turtle b + x ), _4 l6 {1 F. q) n
          ( ycor-of turtle b + y )! d% U+ K0 W, i; v: E  [: ~
if (remainder who 5 = 2) [set c who
& o: Y0 r( p5 _3 N, n                          set x ( 0 - Wid / 2 ) 3 {) J, j, r9 @+ x4 V5 j
                          set y (0 - Dep / 2 )  ]
& x- P8 e5 {- I1 P4 ?                          set d int (c / 5) * 5
# G# U$ h1 W6 X8 ]   setxy   ( xcor-of turtle d + x )
3 Q0 e% A! F9 I* ?4 q( R           (ycor-of turtle d + y ) : ^5 D! Q* _& h( ~5 D
         
: r. z. p) S1 |9 j            ( G4 V9 A" K0 j0 A" n- U
if (remainder who 5 = 3) [set k who
' W2 j' Y3 e* _) l/ q% [% @4 B                          set x( Wid / 2)  , [$ n; Y  c$ y4 G. P$ {: q# c
                          set y (0 - Dep / 2 ) ]* m' x% A+ Y" D( q' G4 }- R
                          set f int (k / 5) * 5
0 c. v7 w' B7 V5 f' n$ a9 u  setxy   ( xcor-of turtle f + x )
% u* K6 G) x* W3 m. v           (ycor-of turtle f + y ) : m& E3 E0 J* L1 L7 k
             y" Q1 X) B0 q) f1 x5 @( ?
           
. o# K" {( P) s3 Z4 K" Q# a1 N; Jif (remainder who 5 = 4) [set g who
' ]! s+ ?8 B- \                          set x Wid / 2
/ i- y  x# u# m5 l& J  X. N8 d1 L                          set y  Dep / 2 ]
" }0 J) x: t; z" z. K                          set h  int (g / 5) * 5, \; w* S7 e6 \6 t3 ?
  setxy   ( xcor-of turtle h + x )7 b$ b6 X7 N% f' ?1 X. k- [
           (ycor-of turtle h + y )
, w: `3 @" s- J5 N" ]; \                          . T" R9 m+ L4 h/ V- @
                          , t3 r% s( }5 b" @8 o3 }9 Q# j
                          ]5 y8 I; V, ]* ^# ], k
end  }. V4 o6 x# u4 W1 B
( ~. b* }2 ?: A
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
" U+ `7 }: u7 h+ _应该是5 `: D& t1 Z3 L2 j4 D
ask turtles [
8 B: }* g! R# M2 eif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
2 w4 F' `) e: U                          set y  Dep / 2
% C7 k8 q- B7 c4 ]           set b  int (who / 5) * 5( ^+ G1 i/ |$ F7 m2 H
    setxy ( xcor-of turtle b + x )' H, @. Z8 R, i! D& M
          ( ycor-of turtle b + y )]]
" b' P& E# s( R$ G7 J. Rend
3 ^6 [" S5 \% r, N之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-25 22:45 , Processed in 0.015144 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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