设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7497|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
/ \2 s$ G1 [2 j8 O* [, J) {
4 e7 r2 \) j" L) h3 d5 f但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
8 |+ Z4 M. i2 L# n4 k. W& ]$ R4 @2 T( b  E* |5 F
turtles-own [a b c d k f g h
0 V. h: Y& k) D" i0 m  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
0 T# O4 N) |) {& A: W]
) m% V# }5 T( uto new0 b* e: ~2 n# r! P3 x% p! W
  ca. t/ c# M7 Z1 m
  crt 5 * num_of_building
6 B7 ?3 [2 P$ O  S, x4 o6 U& V/ P  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
6 }4 n7 t% C9 J; G8 Y9 B2 u  scatter     ;;keep center-turtle random positions 9 ^# h6 p" P* @5 B; l
  unit_plan   ;;make up the building plan
* j* T) f" F# H2 V: }end) G- B; |3 E5 `! o
to scatter5 y2 C& m4 q5 g* E+ l; y
ask turtles with [remainder who 5 = 0]/ O8 U, L2 O. I0 S) X) b
[1 G/ u; }0 N; x5 @
set xcor xcor - 6 + random-float 15" g' h8 W8 V; m- J$ c( I$ X: a! |
set ycor ycor - 6 + random-float 150 O- J& S; S3 I* s& [; x' E: R' u
]1 W) G# u' u5 Q& c9 }6 _
end
/ H- n3 m0 p4 g# j5 T* Jto unit_plan
$ |% `5 Q" \" U. @" Z7 v7 J6 M% A$ cask turtles [
- f3 |3 j9 X- |6 eif (remainder who 5 = 1) [set a who $ t' }6 e& b  f1 e. b1 W
                          set x ( 0 - Wid / 2 )
( `  @6 P% r, U0 m                          set y  Dep / 2 ]
: N, k. a4 |$ s, d0 ?7 {) X           set b  int (a / 5) * 5! p! a) Y4 C, ]' o
    setxy ( xcor-of turtle b + x )
; \- |4 f6 ~6 Q          ( ycor-of turtle b + y )! O8 r! @. s1 }$ z; a
if (remainder who 5 = 2) [set c who) B7 i- i7 C0 w, ~
                          set x ( 0 - Wid / 2 )
; e  K) u& A  ]8 u8 ^+ L                          set y (0 - Dep / 2 )  ]' c8 k) p' T- R$ K; \" [; B, w
                          set d int (c / 5) * 5
3 L- K& c; b; K$ R   setxy   ( xcor-of turtle d + x )  w. y# h: J$ Z( k' E( _
           (ycor-of turtle d + y )
5 D( e5 J2 c( y0 Y9 Y# b          : x8 o0 F6 m* W9 \! ]9 I1 P0 M7 M
            # z6 A% C) @) }* }; ?
if (remainder who 5 = 3) [set k who
3 j# m: \: G" L                          set x( Wid / 2)  
5 `& [1 M( e$ T                          set y (0 - Dep / 2 ) ]7 C% D6 p! n2 T+ q
                          set f int (k / 5) * 5# x4 B8 ]3 S- R9 k% g; d; y$ z" R
  setxy   ( xcor-of turtle f + x )
. t7 l. h- m0 t3 U3 t7 ?           (ycor-of turtle f + y )
' d- p' V& ^8 d5 ^$ e             I) W  P% A+ H8 Y5 L
           8 x6 ?, T4 s* V) u
if (remainder who 5 = 4) [set g who, G- ]6 A! d; [1 A% i
                          set x Wid / 2 , p  g: N9 Y8 ~, }( |/ h
                          set y  Dep / 2 ]' x0 R% _  A( N* A+ q' L# m
                          set h  int (g / 5) * 5$ d' B6 p* k8 q1 T* W
  setxy   ( xcor-of turtle h + x )$ D8 u& }7 h  P
           (ycor-of turtle h + y )
2 Y  a6 \1 {! ]  F, \2 X                          ) ~% K, k7 Y% x
                          $ W) H* ]& }3 f% N( u' m
                          ]
, Q% K/ T0 Z# ?$ K0 o7 i; ~end
( b$ n: X8 I* p% q
0 G- v$ Y* P$ q. W[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
- T* |2 v* s" q应该是, Y% Y6 l8 h- B
ask turtles [
4 G, x5 L) m0 v) W9 Y6 X& B. Sif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 6 B" _3 v2 W* `8 M" m
                          set y  Dep / 2
4 Y# N# k# r$ J0 L/ Z/ O8 h: B           set b  int (who / 5) * 5
8 v. e7 a9 y+ O8 l5 T& r4 ?    setxy ( xcor-of turtle b + x )
/ R2 H, t4 c; O          ( ycor-of turtle b + y )]]
/ A! @9 E! H) l2 P) h3 |end
4 o9 B, ]6 o7 M3 E, _. d2 D3 m( @之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-18 17:48 , Processed in 0.015828 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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