设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7609|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
2 }5 A4 X' n3 W6 _- Z" e& @0 i
+ @2 d* y; ~! U' o4 M/ k但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
, {1 ^# p# V' J& e6 s! l) s
- ^& Y- V, s& lturtles-own [a b c d k f g h
: t$ q2 `4 C- f  u, M  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
3 }8 Q3 _- h- h/ V5 x]
9 h. }, S/ C& {( y# V4 cto new7 z5 R6 o' P" g  g+ ]7 [$ g
  ca" S1 @# O) n5 ]" d! v7 c
  crt 5 * num_of_building! F: Y: `4 [; Z* Z
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]/ S* k( M9 D, n! T3 c* s
  scatter     ;;keep center-turtle random positions
6 ]+ w' _9 ?6 e* S9 ]# K  unit_plan   ;;make up the building plan) Y# n3 L% x+ x
end  t: k$ {3 D0 v3 W8 ^
to scatter
) p6 X. p1 \6 b: task turtles with [remainder who 5 = 0]" h3 ~' r' D/ A/ s0 f8 `. @( C
[$ K# u8 l! o, o- X9 f
set xcor xcor - 6 + random-float 154 m2 Z% D* H% C+ J; g
set ycor ycor - 6 + random-float 15
7 z. N9 [8 Z4 ]) l$ q% L5 S6 S]  D+ H2 V, T, Y7 y+ `% l
end1 i5 a" L4 R' k/ @+ l/ Y# l: p* \
to unit_plan 4 E7 l4 s3 S* K/ I; g7 O
ask turtles [: B+ B5 O. Y! y) J6 o9 S/ X
if (remainder who 5 = 1) [set a who " A' B; Z; C6 u% C& |
                          set x ( 0 - Wid / 2 )
8 N( l2 y1 u+ m" l8 J6 l% G                          set y  Dep / 2 ]
! s& m7 e2 F0 D           set b  int (a / 5) * 5( L7 k% j* O& S# x. Z
    setxy ( xcor-of turtle b + x )% N+ Y; A. ]7 S! f- H. ]8 l
          ( ycor-of turtle b + y )
' T, G+ c' v( K- ~; J7 A2 g4 fif (remainder who 5 = 2) [set c who
2 o2 C1 l* P9 [: `, s+ }1 h1 z                          set x ( 0 - Wid / 2 ) . D2 T" Z' e% y( a% A$ Q4 @. l$ B
                          set y (0 - Dep / 2 )  ]* m: g5 Z9 f; X6 x/ z
                          set d int (c / 5) * 5
8 `0 g* `, t2 q" ~   setxy   ( xcor-of turtle d + x )
  x: O. g4 N" S* |1 J, r           (ycor-of turtle d + y ) / w5 M9 g6 O( }9 a. @- f' t
         
; y8 d$ R/ B/ q, \! j, ]  P            0 L  l2 B" e8 ]% s9 J" `
if (remainder who 5 = 3) [set k who  s2 L% x3 E9 ^/ m
                          set x( Wid / 2)  . u2 {$ A% ?9 v5 `. Y7 X/ R
                          set y (0 - Dep / 2 ) ]
$ L/ i/ a6 T7 F1 v, k                          set f int (k / 5) * 5
. \5 V3 P3 Q3 ]  setxy   ( xcor-of turtle f + x )  C0 S) T1 `/ c  v" }
           (ycor-of turtle f + y ) 3 m. L8 L2 N8 z# Z) p, n: j/ J2 z
           & a) _! u. k# S+ F" `2 F! \! V
           
! O) d9 Y% a+ s# _8 D6 Eif (remainder who 5 = 4) [set g who+ S, M6 {- v% V7 O
                          set x Wid / 2
' C5 Z4 E) K" D9 C# [                          set y  Dep / 2 ]  J: m3 H9 Y9 Q; [
                          set h  int (g / 5) * 5
3 P/ X0 K. m& m  setxy   ( xcor-of turtle h + x )+ T( M  J" \9 I& N* O9 W
           (ycor-of turtle h + y ) 5 u: ]* u$ g. Q
                          
# s" z6 P3 ]; S; }5 Y% n7 g7 Z                          
1 c6 N- v" }! J" s1 A                          ]
* ]$ l$ S9 G- j- c& n8 u# Y3 z6 ]7 yend, F3 ]  D1 I- K) k9 ?0 I
) f8 o) z! a+ l
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,% O! C+ @$ g# d% z
应该是
. R7 Z3 t" Y! g/ Iask turtles [$ a( y2 ~' C3 D2 I; Z
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 5 N; G6 s8 ~; a- o# V1 S" E6 f
                          set y  Dep / 2
) u0 T: k9 a2 [2 l) O! O# h4 p7 j           set b  int (who / 5) * 55 b, u% ^& h; C, u5 I  ?; T  B
    setxy ( xcor-of turtle b + x )& `" t  J, S+ r& k& R
          ( ycor-of turtle b + y )]]: V" ^' H3 {6 x, a( E% p
end& i0 l2 {/ K1 c. V" l
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-4 19:51 , Processed in 0.019740 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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