设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5966|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
7 ]  J/ X# W5 y; E, k  N; H! Q7 z% A; q6 U
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。3 F( v5 t+ r2 ~  D
& z2 f/ u0 ]$ V- y* Q$ v0 o9 L3 q& ~
turtles-own [a b c d k f g h- F3 G; W8 T& y: H* m: U: r8 j9 Q
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle & s, o8 l" c" M+ Y
]
6 z  f+ c1 y3 |0 Z0 Nto new) n5 W4 Y/ a2 W% p, s1 \8 g" ~
  ca  M. B7 t( W+ q
  crt 5 * num_of_building; G; D; q3 D( w$ e3 h
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]8 ]/ l2 o. D" X& |$ v! f7 C
  scatter     ;;keep center-turtle random positions , c0 w+ ]4 y# v$ ~! H" m( Q: j
  unit_plan   ;;make up the building plan. k4 @$ J# g- H4 r  }: K' {, W/ Y
end
0 B1 s1 l/ c% f  [2 qto scatter# ]2 s3 q; N" L5 G% A, _, I' @
ask turtles with [remainder who 5 = 0]8 I: `% F, q7 K
[' r  o1 h, T" t7 R; ^
set xcor xcor - 6 + random-float 15
2 g  _; D- P6 N- Hset ycor ycor - 6 + random-float 15
. r+ ?# m5 J& o: I( I]
9 w+ U6 p# C; o: ^end* Z" ^7 ~' L3 f7 o
to unit_plan
8 I: H+ Z9 W$ [' F' f$ qask turtles [
1 a9 P0 q3 M! s2 t- \. cif (remainder who 5 = 1) [set a who
; c  Y6 M- C9 h; \# R                          set x ( 0 - Wid / 2 ) - H$ I. e) n5 r8 a5 R, Q
                          set y  Dep / 2 ]1 B5 T2 i( a4 t
           set b  int (a / 5) * 5
8 ?- x( i2 z% U3 J    setxy ( xcor-of turtle b + x )
8 N$ [2 c7 G3 X" c# H* x" k          ( ycor-of turtle b + y )8 _, w9 A$ I5 T% V  g
if (remainder who 5 = 2) [set c who
4 P; l; Z* a* P                          set x ( 0 - Wid / 2 )
: |& }. e6 [- ]+ ?0 z+ W# B                          set y (0 - Dep / 2 )  ]* c0 Z/ \* S: k5 B7 \! i' w! }
                          set d int (c / 5) * 5
" Q: K) S# g; w   setxy   ( xcor-of turtle d + x )
2 G+ f, Z. b# C& ~5 ^           (ycor-of turtle d + y )
8 r, `' f8 q; P+ e1 f          0 V7 k1 q7 |' o4 o
            
, D5 l- ^! I6 s5 c; U- R# wif (remainder who 5 = 3) [set k who; w1 [6 s7 M; Y5 v2 \# l: H
                          set x( Wid / 2)  
4 q/ Q3 Q  Y6 L! ^/ Z% J$ M                          set y (0 - Dep / 2 ) ]
2 H- L/ M( e) e8 a                          set f int (k / 5) * 5
/ `0 @& S: {) u. Q  setxy   ( xcor-of turtle f + x )6 s" f0 f6 o7 c0 ]& d; s
           (ycor-of turtle f + y ) 6 i9 e6 i! h% P# B* {" B
           
$ w3 }  \2 U- l8 d% U           3 L! A' L; H3 a  J- z% M5 g/ `
if (remainder who 5 = 4) [set g who' i! W3 z- m9 x  i& |2 Z  u
                          set x Wid / 2
  x1 l: c1 k$ i! h$ }0 [9 b- q9 g" T                          set y  Dep / 2 ]7 t5 s) q( S' }7 R- s- e
                          set h  int (g / 5) * 5: k  W+ ]6 p! H3 Z5 V- T) l- p
  setxy   ( xcor-of turtle h + x )6 c& H7 S  D9 _! U! A* C2 R
           (ycor-of turtle h + y ) 3 M% w5 f2 A# n, j# b
                          9 ]4 @% H0 d) o/ d) L! ?4 j
                          9 U) P  C, m3 f3 h
                          ]
" F  H# p6 W, I! V  ^  Rend
8 B# |! ?+ v0 N: J1 J: ]" k0 b5 C$ {& n8 z
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
9 L, o9 q. R4 ^5 @' p/ w  r9 N& q应该是  G9 O9 G8 `4 m
ask turtles [. t2 ~+ [, |/ o! c' p. i2 S  R
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
' y- ]* {3 ?4 e3 ^$ r, }# r8 J                          set y  Dep / 2
/ p0 h$ A2 M* {8 W' e           set b  int (who / 5) * 5: ?1 r7 G+ D9 T9 t9 v
    setxy ( xcor-of turtle b + x )
! d; n1 x1 l3 p+ ~  R. S! `          ( ycor-of turtle b + y )]]% @" C# Y& p' h2 _
end: \8 l  y7 x, `: m; @5 I
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-13 21:20 , Processed in 0.012453 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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