设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7433|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
6 _- _5 c* X0 o0 C1 b: d3 P. h2 c
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。& x- r3 _" j9 m$ d- l8 g

( o. m; t/ ]% l3 f# zturtles-own [a b c d k f g h" B4 a, {4 v; k
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
6 `* }8 O! J& U! \; P0 c) o: N4 J]
6 j& h8 G; n  R8 H' ato new
! ~" I& V& |2 x9 Q4 [: e  ca
* P9 N" v2 A3 B" L: H4 n$ q* Y  crt 5 * num_of_building
0 ^& E7 `) j1 P6 F  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
: t/ _0 i5 n& M  scatter     ;;keep center-turtle random positions
: k; l5 F- ^) f- ~, t5 B5 b3 [  unit_plan   ;;make up the building plan& P8 b. T2 e% Y+ I. _& g4 n9 q! p* K
end
% o* T( f4 P. [/ wto scatter
9 S; q# U( v, `ask turtles with [remainder who 5 = 0]
4 Q& {; k4 _8 h. f5 q[
+ ^) I' P' t2 ?1 T6 Rset xcor xcor - 6 + random-float 15
9 c/ x6 A  D8 [1 jset ycor ycor - 6 + random-float 15
6 I: c* C0 S0 r0 T- K' `5 y/ v, B]- o$ c1 B5 ^; |6 j% Y* r' u
end6 U9 Z0 e  W% y' g& {, I
to unit_plan
4 f6 P: V; Z& R' \- Task turtles [' i  S% \+ m# B# d2 E( P
if (remainder who 5 = 1) [set a who $ ]) k, o% w* M& _- r' T8 e
                          set x ( 0 - Wid / 2 ) 8 u0 |! l5 f+ S/ S: x
                          set y  Dep / 2 ]
. u' ~. c& z% P$ d3 u8 C1 ~8 C           set b  int (a / 5) * 5
5 h& D" c4 }6 R2 D! O3 q    setxy ( xcor-of turtle b + x )  O& l. F' |2 [9 b6 U: m
          ( ycor-of turtle b + y )
: }5 G0 [5 K. J! q: w, r  M0 A8 Pif (remainder who 5 = 2) [set c who
( ^. i0 @% n1 v' ^; l                          set x ( 0 - Wid / 2 ) 3 J) j% T$ b' [4 \+ Q
                          set y (0 - Dep / 2 )  ]% O: e4 r& y9 ^( n/ ^( e
                          set d int (c / 5) * 5
, e. I+ w! i* Q   setxy   ( xcor-of turtle d + x )
: k5 w' D: e; w+ r/ ]           (ycor-of turtle d + y )
# {3 v* X8 @' g3 [, j+ @         
( \+ [, p5 R# o- ~- M' H, r( e+ R            
( i  p" l2 k$ |; |2 a) Wif (remainder who 5 = 3) [set k who
" j1 f2 z1 B/ {" n$ g- V                          set x( Wid / 2)  
9 y' b  l3 W  C                          set y (0 - Dep / 2 ) ]
. ?" v, V# r  I4 I                          set f int (k / 5) * 58 R, t3 ?7 k: X0 @" {% b1 p- x
  setxy   ( xcor-of turtle f + x )
+ G# a. ]1 g, y8 z           (ycor-of turtle f + y )
, m: P2 a6 o. O# t' C2 M           
* B! P% w* M! e           
& {( l4 w# E9 j7 r1 @5 k# @8 sif (remainder who 5 = 4) [set g who
2 V; a* u0 Q3 v9 E3 Z                          set x Wid / 2 . ~* ^' B5 O0 ?4 c% i4 U, G
                          set y  Dep / 2 ]
$ k/ h5 V, |2 J/ B: G6 r                          set h  int (g / 5) * 5, P, m4 o$ w: l4 V2 \
  setxy   ( xcor-of turtle h + x )
! v3 ^) R0 ^9 Z; B           (ycor-of turtle h + y ) : A, o% C5 g1 T
                          
: a* y) i0 B+ t6 M3 d' K3 r, C                          9 Y6 j* N) Q" c7 P) D
                          ]8 V( N  G" t$ e' }
end
( {' s9 E0 F) _: X' f9 E/ R1 {/ f6 L$ E: n1 V1 b* c# v1 j: M! f
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
. a: E6 u1 o$ Z' z$ l0 o应该是0 @; X( o7 d; x4 n9 Q
ask turtles [
- x# n  r' c- X! C# Q% z# Sif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) . ~$ }' D" b3 {) u1 b, C3 F
                          set y  Dep / 2 + _; z3 d# a9 s/ s% `9 e
           set b  int (who / 5) * 5
  Z; L1 B/ E( t4 n    setxy ( xcor-of turtle b + x )
% t8 k( v. I% k0 n8 f          ( ycor-of turtle b + y )]]
! Q1 t1 q& t* m/ gend2 _* @. g! ]! y2 a1 ^  c/ c$ B
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-10 21:16 , Processed in 0.016024 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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