设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7638|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。* v4 a) i; d/ s- Q# I9 H, d3 ?0 I
9 v0 B9 R9 `5 [0 m
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。  I( _4 \1 l& I7 m" z3 \! |
3 c/ }/ R! {# W8 V: T
turtles-own [a b c d k f g h
. ~# y' K$ W3 _. M  j! {7 w; s  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
+ T/ W0 x4 }% r  E6 ]1 ?  Y: `]
  `8 y3 u( G2 s: r% M2 y' oto new
1 M+ ?+ l' K5 a$ S1 o' k  ca
! Y% h+ t& k( \- `5 I  crt 5 * num_of_building
2 [: x- E5 H. W  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]; o7 K6 w  g' Q
  scatter     ;;keep center-turtle random positions 1 n5 ?' Y0 p! Z" e$ M/ H! v
  unit_plan   ;;make up the building plan  ]% P, h$ [" B+ b
end
, X$ U/ e: F, K7 M9 T9 k9 Wto scatter8 a/ a9 n/ `$ @/ R+ x
ask turtles with [remainder who 5 = 0]% C) @' x$ e) D- L" V: G$ i" t: g& L
[* [" V0 d: J2 [) o4 F) Q" i) U
set xcor xcor - 6 + random-float 15
* E. j4 @4 U( k. t& S/ Yset ycor ycor - 6 + random-float 150 E7 w1 \# f0 q
]5 Z5 b  w8 b- v- b2 a0 F* o
end4 t; w9 O$ {0 n3 Y. m+ ]9 [) x
to unit_plan
) u" Q+ x( ^: S2 l8 Q* m' V  dask turtles [9 H1 V6 M; p* u8 C# {. g
if (remainder who 5 = 1) [set a who
) K8 ~! h, ?3 }% Y& _, g' u$ t3 d                          set x ( 0 - Wid / 2 ) 4 @1 U, V! Z4 k% O$ i: k/ F; B! K
                          set y  Dep / 2 ]9 \8 N5 V% [; E$ O. w
           set b  int (a / 5) * 5
3 k& b) O: |% |! D, u8 c    setxy ( xcor-of turtle b + x )8 o- ?& ~7 {$ b% x, j
          ( ycor-of turtle b + y )
7 j5 t' [4 g- \% t; S7 N, yif (remainder who 5 = 2) [set c who
7 p  C) U& E' C+ V6 Z0 _3 S7 h1 Y                          set x ( 0 - Wid / 2 ) ( ]: d! m- }0 m1 @, D% B+ \
                          set y (0 - Dep / 2 )  ]
( @- f% v$ |( X- {                          set d int (c / 5) * 5
' c0 E( J, M+ J$ z2 Z+ ]) T* P   setxy   ( xcor-of turtle d + x ): L+ ?( t1 [9 i/ J6 T; z3 E: F
           (ycor-of turtle d + y ) & q( c. v; @0 k1 @
         
( G; m% {9 z  T- |9 E! z" v5 a5 v            5 z- r$ m9 }! h0 E9 i" K- |
if (remainder who 5 = 3) [set k who- u) ?2 U. |& J/ j
                          set x( Wid / 2)  # Z' q1 Z4 g" ^3 g
                          set y (0 - Dep / 2 ) ]8 Z# b. }8 X9 j3 Y% B9 K+ G
                          set f int (k / 5) * 5
: Y$ ^5 z' z0 G6 \% p% e3 V  setxy   ( xcor-of turtle f + x )
" r. R: D; M/ j' b3 _) g& F           (ycor-of turtle f + y )
& c0 v5 d( {4 b6 G1 c& B- `. A           
- [- m% A2 n6 t: B2 i2 O             h& X+ q' W4 Q1 _8 F: Q
if (remainder who 5 = 4) [set g who
% f/ H6 B' M) l. k7 ~$ }" T                          set x Wid / 2 ! |3 w9 x! y6 M* \3 {/ O+ {
                          set y  Dep / 2 ]: f! e! U1 T3 h( p
                          set h  int (g / 5) * 5
. m8 i( i" M& s4 V) j  setxy   ( xcor-of turtle h + x ), g8 [" k, Y8 B. ^: w5 z. M: o( c
           (ycor-of turtle h + y )
! n9 x& w: L3 ^1 {. J2 P9 G$ Y( Y                          1 F! t7 I( u; }2 o
                          , t% l. \" `! e% a, a7 C) z% [6 `
                          ]
* s/ ]# u) I: jend1 ?+ D* d  {+ d3 T

) I% O# [; u) b: X1 H) y  [1 f[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
; T7 R3 \& n# ?1 H' r1 b' O. G应该是
: `9 i* y# |( X% `7 ?, r; fask turtles [, Z' e' v" L7 Y1 H+ E  Y
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) / X- T7 L) {% Q; n0 R' A3 X: M
                          set y  Dep / 2 4 R! _$ H4 o# G' ^8 Q7 T
           set b  int (who / 5) * 5# R) O, O" {) k: Y
    setxy ( xcor-of turtle b + x )
1 R9 \" e1 q6 F6 [5 h. @3 Y          ( ycor-of turtle b + y )]]
" k+ y% t9 N" A% ?( e/ @: O0 \end
" n5 g0 E0 ?+ l( u2 O- R: h* j之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-10 00:54 , Processed in 0.016657 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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