设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7703|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
8 x# z4 v. J, X' ~
6 ~: W; z3 M3 }6 l4 D& t" o9 U但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。6 o0 R& N* i: i7 U

/ E7 W& @5 w2 V& Nturtles-own [a b c d k f g h
4 ]9 V9 r, D0 V( V  x y     ;; these are the leaf-turtle's offsets relative to center-turtle $ z- b. S  F5 V
]' Z& h2 i3 X2 R
to new
# f8 ?" G3 C( O9 f0 K. ]  ca  ~! O3 O5 Q& r
  crt 5 * num_of_building
0 E0 [1 d6 u) v7 O- i) r  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
$ K/ N6 o: C! t! i- b  scatter     ;;keep center-turtle random positions : e, V1 o- B2 c- @% K- }
  unit_plan   ;;make up the building plan
) T8 M6 ?( e* i' x+ w* ~end+ C6 j6 L$ y0 B7 o1 N# w5 D5 i
to scatter0 w! k; }! m2 o) O4 }
ask turtles with [remainder who 5 = 0]6 y! L' P7 E% U+ g" S
[' M/ a" I0 r" U
set xcor xcor - 6 + random-float 152 |. D$ A+ z  p2 _3 }" G# }
set ycor ycor - 6 + random-float 15* T/ R' u% D) `! R
]6 \- S! J! q, |  Y. q% o' c+ ~
end9 g  w8 A: O& b5 |6 t1 W
to unit_plan 6 r% ?" X* x# K% {8 R: g
ask turtles [
! K/ z# r6 J6 E1 O9 O7 e" H1 @if (remainder who 5 = 1) [set a who
6 Z6 d! D$ g) W9 G0 {4 B4 {  ?% N                          set x ( 0 - Wid / 2 ) $ G" c" m9 c" R
                          set y  Dep / 2 ]
( D+ ]$ G1 q7 S! G2 Q; l. }           set b  int (a / 5) * 5
9 S, c  W/ C5 D5 L    setxy ( xcor-of turtle b + x )/ B* j/ Z: r% K
          ( ycor-of turtle b + y )7 P/ N8 c9 |5 O3 U) e! u; s( k
if (remainder who 5 = 2) [set c who% [# W$ b. Z6 b  R
                          set x ( 0 - Wid / 2 ) # h% z2 Y" b( [* \! F
                          set y (0 - Dep / 2 )  ]
6 r& x# S- f9 D" e5 z                          set d int (c / 5) * 5
2 X1 d. k7 x' Q4 R   setxy   ( xcor-of turtle d + x )2 x: o- M* u0 O( a
           (ycor-of turtle d + y )
, ^" ?% q# G& |7 L6 A          0 t! ^# D4 g7 \( Z6 \5 D
            
1 c* r- u: P1 U0 c, iif (remainder who 5 = 3) [set k who
/ Z/ Y3 @% k7 D7 B3 s) A                          set x( Wid / 2)  ' \, L3 \' t1 F$ ~! K
                          set y (0 - Dep / 2 ) ]- ?* ^/ `) E: R" X) n; A
                          set f int (k / 5) * 5
' h0 B) s, n. o2 x# P9 R0 E8 }  setxy   ( xcor-of turtle f + x ), S& @# L  M0 P, n/ b+ U
           (ycor-of turtle f + y )
9 ^5 y% a* f2 F; H; C) i           
% v; S7 {; ?! c; ]% E- p           
! t; I# S- U; v; f: y1 oif (remainder who 5 = 4) [set g who  `( p) l6 `" ?1 a0 S; X
                          set x Wid / 2 8 e% l% b% `6 l9 Y
                          set y  Dep / 2 ]" t  T2 F; R) Z, n) ~
                          set h  int (g / 5) * 5
! |: c3 S5 p% I) I; t: U$ q  setxy   ( xcor-of turtle h + x ), b4 I( K2 @7 M: \7 G7 F
           (ycor-of turtle h + y ) # U) E( k) ]8 E. h; |/ N
                          3 S! F0 B% t7 u" l; u0 J
                          2 B& |/ K+ f$ A+ R9 X
                          ]/ Y, `& |) K2 Q! Z
end
& z' I+ O9 M2 k6 U; B! Z! H
4 R& R4 l7 b; w- T$ w/ Z[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,, Y, f+ S& m' ]6 ~3 X" x; d. i
应该是4 n; E4 L+ j( ?7 n+ a5 K& z
ask turtles [
# J! q1 C! O) l( _if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 5 w$ a- L/ n' a/ R5 u
                          set y  Dep / 2
* z$ T" F8 u9 b2 |1 k0 z) m           set b  int (who / 5) * 5
' B% t7 M+ }, _+ D    setxy ( xcor-of turtle b + x ): q* Y2 G# d% l/ d+ z
          ( ycor-of turtle b + y )]], C' F' y9 v; \1 W5 Q" ~9 ?. c
end
0 m. p' N+ O. K2 B; n" F" l9 P之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-17 17:58 , Processed in 0.014103 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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