设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8658|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。% B" k* @4 a  n2 o; S3 U

& ]3 s# O1 V% C但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。& h$ z; G3 y7 M* K+ D
% K" h4 Q0 b1 n& l" `. P
turtles-own [a b c d k f g h# j; s2 p' f1 [2 b7 e
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 2 a$ d1 ~- v4 s& x' z& a) ~
]; }, T! V" g4 |! Z" i* i+ t
to new0 X7 t% f1 I  u: v
  ca1 }- o5 C: R1 n' Z- p. A- C
  crt 5 * num_of_building
0 j, g; V# O) N  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]4 ]: S! A& b! b% ~
  scatter     ;;keep center-turtle random positions
( I* ]) n; u7 \0 o( m: g  unit_plan   ;;make up the building plan: L8 q4 G% y, ~% v6 k* K. Q
end
/ A+ d! A# a& y' |to scatter
# Y( R# Y" ~" l$ Bask turtles with [remainder who 5 = 0]
9 [, n  J- E$ ~; x  N[8 o/ M* r/ B- c$ A% L
set xcor xcor - 6 + random-float 15  Z7 |: A& `- n: M( [7 b
set ycor ycor - 6 + random-float 15
8 {1 q  H2 Z/ `4 x]
3 e: ?( Q9 d  M. \; Send
' ^8 n% @# w8 B7 o( g0 Sto unit_plan 6 G  B/ D% f6 a# k: N! Z
ask turtles [2 |  W1 B* O/ y& |  X' S! l4 w
if (remainder who 5 = 1) [set a who + u+ U# s1 _6 V6 V7 N# ]
                          set x ( 0 - Wid / 2 )
2 \( M! l2 F8 y8 K2 c5 E                          set y  Dep / 2 ]5 W$ ~% G* h2 Q& u0 V
           set b  int (a / 5) * 5
" L* C( I7 @' I( r8 F+ `    setxy ( xcor-of turtle b + x )/ X; e$ i: q* P* i% z
          ( ycor-of turtle b + y )% c. W# P  Z& z- L
if (remainder who 5 = 2) [set c who
: R  L2 _- e6 R0 M+ X                          set x ( 0 - Wid / 2 )
4 F0 B: O3 N" `, F                          set y (0 - Dep / 2 )  ]
1 i! \% o  u: B4 B# ~                          set d int (c / 5) * 5
( w3 y& y; M( ^4 v   setxy   ( xcor-of turtle d + x )
/ z; M" u7 O2 C! Q' S" A$ a           (ycor-of turtle d + y ) / E) x8 E$ ~6 W. z
         
1 N9 C6 D8 n' a& F6 }$ H            % @1 C' S% ~- y5 q. F* S
if (remainder who 5 = 3) [set k who
# [+ t3 `. D; }1 e( `, e                          set x( Wid / 2)  
/ {8 L& V" l. f% y: F8 ]- p% t                          set y (0 - Dep / 2 ) ]& e8 r$ T9 \( R! a$ [, \
                          set f int (k / 5) * 5
! M# i8 ~6 ~- y6 P  setxy   ( xcor-of turtle f + x )
9 [  h, s3 Q3 m- I  p( n           (ycor-of turtle f + y ) & f' l+ o* p7 M/ _1 R
           ( V3 m! i* ~% m6 J( ?4 M' P/ T
           
3 @/ P' F- `2 v7 Fif (remainder who 5 = 4) [set g who
! [3 t- v- Y( v- q' D6 I                          set x Wid / 2
" ?" ~7 }* C) C5 j, c6 b                          set y  Dep / 2 ], g; {' ^, P' G, V5 v$ n9 D
                          set h  int (g / 5) * 5* R* Q# b  _) j" ]$ s
  setxy   ( xcor-of turtle h + x )
6 y) J# u2 P( }, b0 W" S           (ycor-of turtle h + y ) 5 U& Q$ v, Q+ O4 O
                          
8 O$ p3 L7 D" w; x                          9 W+ V5 d' x# Q6 r( [
                          ]
2 g6 q% n$ C' \& j% G3 Aend
8 ?1 u, H1 s; T- t6 S& K1 L- k, o' c. r& v! m: e
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
9 h% u" m( M% ^9 @" ]. Y应该是
' A/ Y3 O6 o9 lask turtles [- e1 H0 w  j1 K. |+ A2 ]
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 4 ?2 e, V" d( H
                          set y  Dep / 2
2 ?, ^" m' v$ L2 [           set b  int (who / 5) * 5
& k" i. g8 X4 q2 ?$ B! m    setxy ( xcor-of turtle b + x )7 |8 {$ m9 {9 r
          ( ycor-of turtle b + y )]]9 A/ b" h9 m/ ^* Z( X5 \
end" r9 P# f- A2 |9 T4 W& s+ F
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-21 12:01 , Processed in 0.015859 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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