设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6739|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
) e4 l0 b- E1 y8 ]: p, \) ^7 q7 I" n5 a/ Z% l1 M
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。3 U0 D' W* H6 H% B; x

/ e1 b! d; V* P: w5 cturtles-own [a b c d k f g h
# j$ l& a/ U0 D/ t2 {$ _  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
7 `; J' ^" R8 U' x+ o]
' y. e) q7 T6 Q- z) Z" @2 yto new
( Y4 S1 s% }) w. h) {9 ]$ |7 [  ca9 O/ h& `. w) Q9 ?" P* O
  crt 5 * num_of_building8 F+ @6 ]8 ~3 E6 v6 q
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]+ d  F9 g" G& D0 p' u
  scatter     ;;keep center-turtle random positions : t7 @' O/ I/ r3 n' Z2 U# p
  unit_plan   ;;make up the building plan5 T, T4 l+ V) Q/ ~
end2 A6 ~5 F) H- b+ O% |* n/ S; m
to scatter
) @+ [8 z( n  u% xask turtles with [remainder who 5 = 0]
# i( H7 V3 v1 R4 |7 C* C) [/ O* @! F[
. P6 z  v' G  F  Y. Y! R& A" @' S% ]% Wset xcor xcor - 6 + random-float 151 K% [9 f3 T1 M- f
set ycor ycor - 6 + random-float 15
$ W; [& d8 k/ J% r  r6 {]
) ?6 c+ U3 T4 v% f- z- wend
1 F" P% [& j2 j. d& U+ eto unit_plan
. r8 q' O; n  D! o) m8 W1 q# vask turtles [
; z) h0 `" p, J  a$ f8 qif (remainder who 5 = 1) [set a who 9 Z1 \/ d+ }; F9 `7 x) c5 M
                          set x ( 0 - Wid / 2 )
; ]9 Z/ }+ }# [- ^5 T& \/ j& s' v$ a5 c                          set y  Dep / 2 ]
1 T7 |4 i3 @: P7 ~) K2 I2 L           set b  int (a / 5) * 5
- ~7 f+ @4 P# A' s- b" ?# R    setxy ( xcor-of turtle b + x )- W) H! H  K% ?4 G0 }& _; g4 z; e
          ( ycor-of turtle b + y )
9 r% P3 I! a4 M7 ^if (remainder who 5 = 2) [set c who% t. R3 X: b5 T! P; y! P( v1 {
                          set x ( 0 - Wid / 2 )
7 F% ~4 [6 T" x2 @                          set y (0 - Dep / 2 )  ]
9 v( O7 u: ?' y1 l3 h8 y6 X                          set d int (c / 5) * 5
2 p: j5 W6 ]( Z& `% \  E- R7 B. K1 W   setxy   ( xcor-of turtle d + x ), m) R: a+ x2 B; c" t4 |% y* P
           (ycor-of turtle d + y )
5 l  ^& L9 j: d' B) D0 C          : }9 d' X4 x4 }
            
0 m9 Z1 d) _( E" H; i" t# w+ bif (remainder who 5 = 3) [set k who
, I9 F0 [6 J1 l3 U3 c                          set x( Wid / 2)  & T- ]# o* P+ ]
                          set y (0 - Dep / 2 ) ]
5 K8 a6 e2 x( ]) G+ ~                          set f int (k / 5) * 5. Q4 v7 U* k$ I0 I, U
  setxy   ( xcor-of turtle f + x )
8 \4 M0 L9 z1 J. {. v           (ycor-of turtle f + y ) 6 o6 X2 B+ B7 }$ b* c9 `9 Q
           * {! G; r' f9 D6 `5 A
           0 c" h+ g, ?7 R% ^( _0 f
if (remainder who 5 = 4) [set g who
* U  v  L- K4 k' G                          set x Wid / 2 & u, i) V( r4 p' d3 I6 l
                          set y  Dep / 2 ]% d! H9 Q& ~9 j5 x# i! i
                          set h  int (g / 5) * 5' D. T# Q6 z5 f/ p) I5 J+ z
  setxy   ( xcor-of turtle h + x )
8 H4 s+ d8 y7 c" J! ~" f           (ycor-of turtle h + y ) $ S) H0 s/ ^8 Q% U! J8 s  z6 O/ }
                          . b* a" }+ A( j6 {8 x; @4 u- ?
                          
, h$ }! l, H8 z5 E                          ]5 O1 b' Q8 q5 P9 S. h
end9 G1 K3 g  @7 s. ^' l4 Y

' P/ M9 Z+ d% K: S: k& Z0 @4 a[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,$ K5 `$ a5 d  B; Z* `9 Y
应该是
) i! B3 X0 l4 k# X) zask turtles [
0 N5 g3 W, V; Y. @6 B; U" H% ?if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ) b6 O" w- n3 L( u- b& i
                          set y  Dep / 2 ( A8 n; U# f2 |6 e+ u% ]# N
           set b  int (who / 5) * 55 s0 ~: F, ]& M) F/ W
    setxy ( xcor-of turtle b + x )
+ n$ R* k" h/ h4 t# D          ( ycor-of turtle b + y )]]
' z- s' {1 g+ B6 qend
7 C, @9 {, u$ k/ J- P之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-19 11:55 , Processed in 0.019317 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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