设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7437|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。* u) T  h* |/ n/ w/ I

3 N$ I( q. K# U& Q但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
/ H) c& O# m: O' _5 t
6 A% F* j1 a% x) L! S9 sturtles-own [a b c d k f g h$ y% S  R9 z7 V6 f* b1 G0 o* `
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle - j& ?( W4 Y* @( q6 A% l
]
) r2 R, G( n% ^1 N4 X5 x- p; zto new: [4 L, p6 V& _. g$ K/ J- M
  ca
" u( N4 {! g" {. j  crt 5 * num_of_building& |5 o( R9 v! [& c
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
) b5 g; f+ E2 j& W( ?8 \  scatter     ;;keep center-turtle random positions 1 ^! C/ Y0 x+ W. O& P7 h* M
  unit_plan   ;;make up the building plan
, }7 w  w& q- F# O6 m. Vend& {; [& }. m4 f" f% n
to scatter
" `, u- Y4 ^' f& D, Vask turtles with [remainder who 5 = 0]1 \: t# j: Y5 {$ P; Y% m
[
/ E4 I! r# h# \) e/ sset xcor xcor - 6 + random-float 15+ l1 r! T+ n. l; r# ]4 I
set ycor ycor - 6 + random-float 15
) @2 \$ B! ], S]5 Y9 ?3 m% x" p: a7 w1 G9 ?, D
end
7 J; u: |# O* v6 k; }1 `$ gto unit_plan ' n' q' h" b9 c' l& b
ask turtles [0 Y9 |+ f3 l: V+ L9 ~% x
if (remainder who 5 = 1) [set a who
3 f7 P& G+ v* O1 S; y" v                          set x ( 0 - Wid / 2 )
% F; x5 C! b8 F8 A1 Q+ Z8 |; ?9 k                          set y  Dep / 2 ]/ g( V, a1 O# e! X& L7 g
           set b  int (a / 5) * 5' r  W2 r8 {! K
    setxy ( xcor-of turtle b + x )
3 r  E* Z/ f' S2 y0 z          ( ycor-of turtle b + y )
" U* ?7 @' w; J) Tif (remainder who 5 = 2) [set c who( S4 H& p6 b4 |+ Y
                          set x ( 0 - Wid / 2 ) 3 w0 R9 w; l0 v2 I- B
                          set y (0 - Dep / 2 )  ]
# s% v' h7 g. G                          set d int (c / 5) * 5) |7 ]6 G3 p- E( D* m) e' O
   setxy   ( xcor-of turtle d + x )
. z$ P$ y$ Y* ]  p           (ycor-of turtle d + y ) $ R; h' P' G9 `( n5 n. D0 u0 u
          $ j# ~. J% Z! j7 q
            
6 q9 @6 w! l9 c; g" F/ Eif (remainder who 5 = 3) [set k who, U/ _% o3 g: H, V
                          set x( Wid / 2)  
2 h$ F: v( s0 h( v+ ^                          set y (0 - Dep / 2 ) ]
. ~* f  n- L: s                          set f int (k / 5) * 5
9 l1 h6 {4 D* M- p1 f  setxy   ( xcor-of turtle f + x )- I, P; n. j3 S0 g
           (ycor-of turtle f + y )
( w, ^# M- m4 I" T2 V* C           
% o2 T) t- R& W9 n. I: f           & h3 e$ G/ q! i
if (remainder who 5 = 4) [set g who
$ g0 N4 k/ l  u+ i1 I3 R* q  V4 f                          set x Wid / 2 ' R7 P& k4 b% I5 H3 V6 l" T" `, R
                          set y  Dep / 2 ]
& M7 I# H( U$ }5 f9 q( J! k                          set h  int (g / 5) * 5
* V4 r% z% G7 `7 O6 Z  setxy   ( xcor-of turtle h + x )9 R2 y' Y, Q! B8 ^3 V
           (ycor-of turtle h + y )
( Z; [% U7 z' L4 E                          
* z9 m+ s; `! x1 A/ I                          
! t" ]- k  O- o9 g3 x/ h+ `- k, K                          ]8 r$ @* J. ]6 U7 [3 m0 u7 I; y. E
end
6 X. U6 U) k( v
# W: {) [8 t4 I+ s# S! g2 p. n[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,* r: R2 r8 D# d$ K' e
应该是
9 E! V2 y- N. Z, vask turtles [& h; r# j- @3 v9 M
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
/ w6 M+ s8 j# e* Z                          set y  Dep / 2 " `! h0 {7 c, T7 b; N: Q
           set b  int (who / 5) * 5
4 q& }/ d  A( N0 H8 u    setxy ( xcor-of turtle b + x )
2 x" F0 I1 S8 X& @& y- e3 |) D          ( ycor-of turtle b + y )]]
1 s1 [* ^0 d/ h0 U% Eend- o+ I# E% `4 e/ I" a
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-11 08:37 , Processed in 0.018539 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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