设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7722|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。( C; G6 W9 L0 i3 t" v1 U6 j- G5 L

+ A: }# I0 m2 S3 `6 S$ h但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。* q* ^& t5 h/ K

3 X% e- F7 W4 @) Kturtles-own [a b c d k f g h
# k, @$ g, i2 U4 |. X- G  x y     ;; these are the leaf-turtle's offsets relative to center-turtle " h6 C/ M; R1 B3 P" _8 L6 K4 E5 O) _
]
+ A. W! ?0 e8 Y1 r8 p* Vto new0 [' i" e5 R/ b! f; \
  ca
0 D5 U3 D6 \4 c& T; ^  crt 5 * num_of_building
+ C6 h9 j2 {1 o  f  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]/ j$ h' p. W, W3 y' f5 t
  scatter     ;;keep center-turtle random positions
9 T+ n6 d/ O' u) P! e9 Q  unit_plan   ;;make up the building plan7 n/ a1 j4 T+ j
end' y! M6 d0 ]0 r$ z6 c
to scatter
. d$ u2 X4 w0 [9 Q! d3 a$ l5 o/ O" x( z6 }ask turtles with [remainder who 5 = 0]
5 ~8 L% R# `4 |- M8 b$ S9 O" h[
7 t$ k( k; @( a( p2 cset xcor xcor - 6 + random-float 15
. W* n- x1 F$ e, Qset ycor ycor - 6 + random-float 15
! _1 Y% P2 D7 \, @]
8 s! P0 _5 y  Q1 p6 zend6 L0 d0 i- T" N3 N; [* h1 x
to unit_plan 8 D! L& v1 Y* r1 M9 ^0 L
ask turtles [
3 `; H$ z$ s* T. [if (remainder who 5 = 1) [set a who : m3 P6 f5 _, ?0 V
                          set x ( 0 - Wid / 2 )
) c, w) c: l6 Z' ]0 \. g' L                          set y  Dep / 2 ]
) [1 {; D" W; n           set b  int (a / 5) * 5
. q2 b9 B1 x7 q$ e" w    setxy ( xcor-of turtle b + x )
* }: @, b; p0 s* A# B6 Q$ O* n          ( ycor-of turtle b + y )4 h. j2 y6 V$ L7 w
if (remainder who 5 = 2) [set c who, i' P. {& t7 T$ F: O; e
                          set x ( 0 - Wid / 2 )
2 @$ i) m2 o6 W( K3 U0 g+ I                          set y (0 - Dep / 2 )  ]
- i5 v  u+ \# j/ u$ |8 c                          set d int (c / 5) * 5! L) C- G7 j5 [' M8 ?7 F( w
   setxy   ( xcor-of turtle d + x )$ k( F7 L. c: T) R
           (ycor-of turtle d + y )
" R" f3 B+ U, g* ?8 W          + u/ P* b/ ?3 R8 k) j
            
. D8 q( Y! B4 v* y% Z% v9 Dif (remainder who 5 = 3) [set k who
7 f" n# Y( P8 L; t. G# m                          set x( Wid / 2)  
7 j4 |# X# I# i& x" o/ b) ^  s                          set y (0 - Dep / 2 ) ]
9 F( e) q' g0 J                          set f int (k / 5) * 5
. W. b) j. G* c  setxy   ( xcor-of turtle f + x )
! O2 G' [$ Q3 h, u, ~# f           (ycor-of turtle f + y ) - e5 `( e8 n4 S0 ?. o
           
) q3 Y6 c' Y: n; C2 y" \) r& K% g# w           
% M) M3 Z' R2 tif (remainder who 5 = 4) [set g who5 n( r& S" k: }" p! N8 x
                          set x Wid / 2 & p  Q9 c0 F1 @8 u* B$ c
                          set y  Dep / 2 ]8 R( ]: B+ n: X9 V* J' @
                          set h  int (g / 5) * 5
3 K4 g/ j$ w" R% U5 i  }* T" N/ P3 c- d  setxy   ( xcor-of turtle h + x )
3 x- l5 ]; k  z; i+ _# }! U           (ycor-of turtle h + y )
1 ~! }! l2 S0 y% t$ m- S6 m5 C                          
" ~9 F: j* K1 H( f5 i5 Z, v9 \                          
" L  E4 |3 p7 p# w                          ]( O9 U% z# H5 Z( |7 b$ H# t& M
end. P5 Z0 t' z8 Z
! S( ~5 O) ~+ g/ [
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,4 m. d1 ~# _0 S1 b3 M4 A
应该是& [3 |$ S* P' y0 x
ask turtles [2 N4 j6 R, [" h  `$ ]6 e$ w2 n
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
" u1 j* F1 V5 R                          set y  Dep / 2
2 f8 N3 O( _5 K# m           set b  int (who / 5) * 52 S! E" V9 k' W% J  e
    setxy ( xcor-of turtle b + x )
# o) }9 Z* p/ N7 T1 C          ( ycor-of turtle b + y )]]
2 l9 g7 S: i! E( T0 B2 n0 |end# O8 E9 i) k+ z2 I  f# J& P  P7 U8 I
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-19 17:43 , Processed in 0.015625 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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