设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7356|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
! t% W. g; e" G+ {, a' L* c9 X7 _4 i+ b2 O) {
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。# A: u* [! p1 s' o0 q1 {0 w- W
( _" m! v1 |& J/ g+ b4 _
turtles-own [a b c d k f g h
7 J) ]8 m1 a1 o) v+ K  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
# [( H* l# g0 F( w]/ G- e$ _0 f; z( R& f, B6 h
to new$ W4 e) _' h) v, W, d- y
  ca% C# O  w8 J! R) ~! L: b$ a( }
  crt 5 * num_of_building
$ v4 p& c" F! e6 L7 d% s0 w  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
; B4 {/ Y* w- B, t  scatter     ;;keep center-turtle random positions 4 D4 c) B# n5 s2 A0 i0 y
  unit_plan   ;;make up the building plan" [$ M' t0 l' S& ^2 Q* G7 g. G
end" Y/ j) R) b* p: j- Z  m
to scatter4 Y0 f$ t5 i2 E% G0 ^$ a- z- F4 Z
ask turtles with [remainder who 5 = 0]0 T1 z, s0 h" U* V
[
- Q8 U' _# ?% I. p* Aset xcor xcor - 6 + random-float 15; g4 H; ?& @7 G
set ycor ycor - 6 + random-float 15
+ }) F& b' z( {/ _]! |5 d: P9 e6 ^4 H* ?! q( _
end
" L& B+ W' p: `# Zto unit_plan
/ ?6 z; Q5 p8 p3 ~! K" Yask turtles [8 t" ^% B$ Y, O
if (remainder who 5 = 1) [set a who . F2 L9 K2 f; c8 w
                          set x ( 0 - Wid / 2 )
# p3 E4 ?8 \2 ]& J/ h3 ~                          set y  Dep / 2 ]
7 M3 M& T0 {9 B  w; k           set b  int (a / 5) * 5
9 S$ L# n7 h- }! ?, L    setxy ( xcor-of turtle b + x )
/ w- X0 J+ n3 t: P, S7 \% o          ( ycor-of turtle b + y )
3 m( A) v. F: l* h0 sif (remainder who 5 = 2) [set c who
1 \/ q' U/ p/ u' l  I: l, A                          set x ( 0 - Wid / 2 )   O' h! j$ b, C
                          set y (0 - Dep / 2 )  ]
9 w0 f) p! S+ c! T0 g9 ?, ?                          set d int (c / 5) * 5
' m+ I$ ?" S+ B6 Q% g' w: _+ E7 [   setxy   ( xcor-of turtle d + x )
7 b# `' J7 M# J& T* n8 Z  ^) f/ d           (ycor-of turtle d + y ) $ x% o0 D* F: e/ l0 V5 ]) o8 U
          9 R3 u, y. |% a9 z/ Y5 A
            # i/ c3 V, }! f- b0 B
if (remainder who 5 = 3) [set k who. s7 U/ w. z9 L+ k  z9 `
                          set x( Wid / 2)  
4 T; n& c2 i1 e5 j' J                          set y (0 - Dep / 2 ) ]
, f8 i) \" J9 O5 K: v                          set f int (k / 5) * 59 ]& h4 e! U* W9 i& B8 A
  setxy   ( xcor-of turtle f + x )1 ~, v  A' B5 c
           (ycor-of turtle f + y )
5 J/ C, l, M" w1 F, t' ]           + \8 v- A8 [* t. D9 F6 T' N7 {
           
5 `3 R6 B/ a# Sif (remainder who 5 = 4) [set g who2 |% c3 s1 ?+ k. j. n
                          set x Wid / 2 . n; t# S; k  G# _# F
                          set y  Dep / 2 ]5 L8 Z0 V8 V% [  ]) D! ~5 m
                          set h  int (g / 5) * 5& Z1 N- l: x$ I$ v! ]
  setxy   ( xcor-of turtle h + x )  E( U) F9 U: J3 Z; z. i; h
           (ycor-of turtle h + y )
$ r3 ^$ A6 E& ?9 c6 q                          / W$ E9 d8 ?8 ]7 C/ A" p5 Q7 V
                          + ]* G: Z* J$ G7 A# y9 @& ]' Q2 P8 M
                          ]
: R3 D9 \% ^% kend; W8 ~" }; w4 M
/ \/ m; P  H1 D; N" V
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
7 Y0 q2 ?1 F1 f! o1 O) d& d4 U3 M* l应该是) D! C' Y" C; u' ]: Q5 Z- Y# J
ask turtles [
$ u  O/ Z* ?8 ~% V* s$ aif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
2 H  X9 a. x6 d/ ]1 {, f                          set y  Dep / 2
) ^% f# Y( [' O0 S, \" R           set b  int (who / 5) * 5# X' b9 E( J0 L+ m3 w4 |5 q3 p
    setxy ( xcor-of turtle b + x )
. n& D8 @; y2 |/ k4 Z          ( ycor-of turtle b + y )]]4 k6 U$ z7 P2 G4 X( G. h  A
end# G$ j" F! d+ L
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-2 10:32 , Processed in 0.016839 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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