设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8581|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
1 D8 V$ z6 Z  W* B8 |6 c; g6 |! Y$ ~7 o
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
, y, W5 A5 c% p9 z' K
+ _! k9 p8 l2 R) A7 @" _, kturtles-own [a b c d k f g h
8 ]" r3 `8 f( p6 u3 A1 \' \  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ! e% i$ g+ ~4 J
]  W# j/ |6 k: M+ \# U" B  w8 @+ X
to new
; }0 {0 {0 N4 M. X# Y  ca
2 {: r2 Z, U" D& E4 K. M7 k( \  crt 5 * num_of_building- D# a2 G* K" i7 n$ h) N# I3 K4 [1 _
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]  s% s) b7 W- C$ L& |4 x- j3 g
  scatter     ;;keep center-turtle random positions
2 t% @+ h* w. `+ K1 [; M0 ?) Q  unit_plan   ;;make up the building plan1 x, u; C% D& o+ h
end7 @+ q8 L3 c4 f3 |# p
to scatter
& j. x* l1 b# X6 r7 {4 gask turtles with [remainder who 5 = 0]- L3 y! ^0 i) q
[3 x+ F/ ~' V3 f9 V% B: L* A9 ^
set xcor xcor - 6 + random-float 15+ L$ z% p3 |9 B
set ycor ycor - 6 + random-float 15
& ~+ A9 V0 w" V/ L0 \]
* d2 O" }& o. ]end
9 _5 L# q8 }0 \, _1 u$ Q* E; |to unit_plan
% D0 l: U- T; d7 Xask turtles [
1 _# ?& R1 w' {4 _if (remainder who 5 = 1) [set a who
  M4 P" e: D9 u* g3 x                          set x ( 0 - Wid / 2 ) - [  N9 h1 v( M( }- w- A8 z% o
                          set y  Dep / 2 ]5 q: b: b& o5 n' {! i# ^
           set b  int (a / 5) * 5
' h4 F  P5 q' ^! U+ B$ k1 q    setxy ( xcor-of turtle b + x ), D* M4 z; g( ~0 ]: {: o
          ( ycor-of turtle b + y )' C& A: t  W$ o/ h
if (remainder who 5 = 2) [set c who+ c, {0 b$ ]3 d6 ^3 E/ n/ v( `: D0 U* o
                          set x ( 0 - Wid / 2 ) , R9 o1 w  F# m9 w2 n. e: Z
                          set y (0 - Dep / 2 )  ]
# V( S, A* Q/ {& F                          set d int (c / 5) * 5& N4 f2 C4 e0 i- q0 t! r
   setxy   ( xcor-of turtle d + x )% B6 J  a. o9 }! s, x$ @8 c, ?+ y
           (ycor-of turtle d + y )
* Y( T0 ~% F8 a! z          ; e9 s' {' {( m! }
            
8 _- u$ A5 ?6 ]# Y* p" y; @if (remainder who 5 = 3) [set k who8 N/ F" e) K# M2 ^
                          set x( Wid / 2)    L- W5 p! T1 p5 F, s' c) j. Q
                          set y (0 - Dep / 2 ) ]: s" j. y4 R4 Q/ I  _' n
                          set f int (k / 5) * 5
4 O5 f$ [% U" l  H1 k  setxy   ( xcor-of turtle f + x )% z" H4 o  q, @1 }
           (ycor-of turtle f + y ) 2 [5 ~3 c( h+ A6 h5 X
           
& p( Z7 l7 c7 F0 u           ( z# q3 F6 D9 {% m# T- T- a
if (remainder who 5 = 4) [set g who
+ s+ s! C# s' ~* O% l% ^5 }* z                          set x Wid / 2
4 L  z6 t( V$ L                          set y  Dep / 2 ]) S- V$ w, g, ~/ ]: _
                          set h  int (g / 5) * 5# N1 O. b5 T' B& x( r6 \
  setxy   ( xcor-of turtle h + x )) D! P0 A9 |0 @% R- |
           (ycor-of turtle h + y ) / {  O1 E: q( T# z4 ?1 g
                          % W& ]- o# T, \6 J' u2 b# k, h
                          / H- _7 y) l/ W$ j. i: z( \
                          ]
8 K7 B' u5 \' d+ W# ?4 ?# Wend
& `8 C) D* s& A  q' N
* n) e" V6 E4 O# [0 X; ~[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
$ C* j8 r) ^! H应该是, ^7 Z9 b7 d2 R2 l. n8 J
ask turtles [- d& M' ~) X  u
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
! e, U& e* s2 u  b5 E. q, e, a8 P                          set y  Dep / 2
$ N7 b+ c3 K! w# g  l1 K6 N           set b  int (who / 5) * 5
5 W6 R  \+ K, N( m* q    setxy ( xcor-of turtle b + x )
1 j& b  b- d6 o2 q+ p) D5 p7 v          ( ycor-of turtle b + y )]]
3 g- n! E: Q8 b" g+ R+ `: j2 kend
5 U* W8 S( t2 Y. X之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-13 23:48 , Processed in 0.015993 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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