设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7778|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。, G( W4 A$ f' ?" |, u  a9 N& G

' k8 X0 P) r. u但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。- c* L7 H8 R3 J9 B* x

9 Y1 y+ m' G( q# l8 R9 U) Xturtles-own [a b c d k f g h7 Q- Z0 B" j/ h6 f% e
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ) W6 H3 X* I- g/ w5 C/ w
]
; g2 ~, t  K8 S# Yto new
; {- R) a; `% r4 ]  ca
9 F& S& A, _3 Q8 V8 ]) p+ g  crt 5 * num_of_building
. p4 W/ o) U  J' ]& _: Y  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
& j7 @! g& ~$ p! g6 K/ O  scatter     ;;keep center-turtle random positions . }' X' Z9 x! e# l; L4 F
  unit_plan   ;;make up the building plan) z3 y' F' I* T. |; q
end
, v- A3 p2 a1 a- X1 @! Mto scatter5 N# R4 d% f( S0 M( p+ ^8 i
ask turtles with [remainder who 5 = 0]) j' C! T! P5 @+ f/ T
[
6 z: C0 S, S" d( i0 Kset xcor xcor - 6 + random-float 15
1 `; o: c0 N' u9 v4 a1 Rset ycor ycor - 6 + random-float 15- H0 `) a' ~, [$ ^' o3 K
]
/ X1 e+ ?/ w, w. y! e) \end
# N. p* M; I$ o. p& R  n# lto unit_plan 0 ]% G/ v) v: d9 M2 `
ask turtles [* u5 u0 F" u* i* _; H- m7 |4 y' a
if (remainder who 5 = 1) [set a who 6 b" s/ h3 N) \4 T) O7 G# |; P
                          set x ( 0 - Wid / 2 )   N6 O+ c4 U0 D9 d$ _
                          set y  Dep / 2 ]9 Z0 }) b: q, d- d3 ?; j" p& U
           set b  int (a / 5) * 5
# F8 r' k: D2 G1 K( P    setxy ( xcor-of turtle b + x )5 ]3 V5 p. M1 z( E
          ( ycor-of turtle b + y )
( Q# ?$ ?! v  c$ Gif (remainder who 5 = 2) [set c who
8 x. u* Z4 i3 ^9 m                          set x ( 0 - Wid / 2 )
- E2 Y5 r! k  a: A2 U                          set y (0 - Dep / 2 )  ]" v) u/ d+ L4 S3 X: n4 V
                          set d int (c / 5) * 5# Y/ m% e3 V1 m7 ]' x5 n
   setxy   ( xcor-of turtle d + x )+ Y9 e/ s, V, ?: f
           (ycor-of turtle d + y ) ; i& o/ K! L& C3 ^0 ?
         
# y2 Z  B- Q5 H! b, V3 K. L5 ^              C% O2 M+ t5 J. e. R+ h' z0 B
if (remainder who 5 = 3) [set k who. M9 |& f2 ]! R- Z0 k/ a8 r% ^8 q
                          set x( Wid / 2)  
6 @3 w7 O# b) w7 }! B7 `+ }                          set y (0 - Dep / 2 ) ]& v2 W* g9 [( b* B6 C
                          set f int (k / 5) * 5+ A" {8 l, U% t3 l& C! P, F+ n+ B0 d
  setxy   ( xcor-of turtle f + x )' x1 E" z* t7 m( l
           (ycor-of turtle f + y )
: h9 j. w4 |5 u' H( e           ) S: c. ?1 ~! ], w: q
           " G2 L, F# l8 u! z+ q% v
if (remainder who 5 = 4) [set g who& l$ s& H, |* }/ Y2 y
                          set x Wid / 2
4 d. G; s' d9 q7 i( l. J                          set y  Dep / 2 ]
/ ^  I8 `% b8 r; Q! R9 T: @                          set h  int (g / 5) * 54 Y  ^" N' O/ P& ~9 |( J* s" [4 C# w
  setxy   ( xcor-of turtle h + x )
: Z/ _: _* P/ S) N) F           (ycor-of turtle h + y )
+ o4 \7 K  c. H2 A1 x                          ) j1 b% N$ F: U2 J  `
                          
3 e0 L+ m- Z8 [                          ]4 o( L% L9 y) ^" B2 P+ m3 q
end8 G5 p# }2 ?: i+ O
5 d" w# P! b. t8 ^1 t
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
/ o3 r/ X' @' K: V1 X$ `/ v$ G应该是
5 R0 j5 U, X* ~9 F! `# n, task turtles [8 _# P% Y/ A4 _: E1 ?' ]
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ) b- i" x! a! n# j) |7 F% b2 A
                          set y  Dep / 2
8 y' j$ k/ ]& P5 X6 O* r% O! w5 T$ G           set b  int (who / 5) * 5
: _* v- M, f+ V: [+ k    setxy ( xcor-of turtle b + x )+ P. @2 t6 w# B5 h
          ( ycor-of turtle b + y )]]
( q  E8 g/ u( A% \  A8 ?; @end3 C9 O* e+ k/ O0 a* N5 I; @2 }
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-30 10:56 , Processed in 0.015680 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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