设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8572|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
4 M7 w: C8 U- \3 ~& a9 J+ h
3 t: M3 T& B  q8 \- y9 W' N但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
4 l$ `8 Z6 B& R4 ^" W( N$ r4 e( }  U6 K5 u' x5 G, }3 R
turtles-own [a b c d k f g h
. }. ~8 e9 r  ^7 L& ~. `+ C  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
( u! F  B$ k" @& V. Z& }]
8 H5 k- R" q1 P: ?- y* y7 Wto new
7 x& E, Y/ M/ D" V  d& E4 v- J  ca
* h! D$ P1 U7 [9 l  crt 5 * num_of_building. K& |3 Y1 T+ v0 b  M  W
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]( Z+ m$ G0 l+ n# T) _7 s
  scatter     ;;keep center-turtle random positions & \) }) f2 e3 R2 k' t4 x
  unit_plan   ;;make up the building plan
  p8 t! b1 M2 E  }7 Pend- ~; u0 {& A% f2 y8 w7 W+ H
to scatter
5 U+ W4 ?/ m3 T2 V* jask turtles with [remainder who 5 = 0]
8 G8 U* V- g5 i+ Q. y0 V( K[1 ^" X+ p! l# A
set xcor xcor - 6 + random-float 15$ _' G) `4 d% N, V4 }& @& e
set ycor ycor - 6 + random-float 157 ~6 D4 D& z  g6 O8 |& g0 J
]
: R( |1 l9 t' i0 k$ Bend7 i3 ~3 R5 `; R
to unit_plan 2 v* x! V: u5 M# I: y( N. ?
ask turtles [
( u6 u- s, Y7 Z' [- r) N$ yif (remainder who 5 = 1) [set a who 1 U4 E" V+ K9 G0 N9 [; k3 {
                          set x ( 0 - Wid / 2 )
: l' I8 p: F0 l                          set y  Dep / 2 ]. X, N# M8 [. ~  d$ k9 e8 b
           set b  int (a / 5) * 5
- G1 _$ m2 e% d$ E' z3 h; o: J    setxy ( xcor-of turtle b + x )
# j6 J: J2 E& M2 Q: W6 W! i          ( ycor-of turtle b + y )
3 T, i" U8 Q1 e3 \8 I0 Mif (remainder who 5 = 2) [set c who
7 o$ }& Y) W' i! m7 K$ Q                          set x ( 0 - Wid / 2 ) 7 g  z: r- |# A: f+ I8 j
                          set y (0 - Dep / 2 )  ]
# v3 I* e) A; j- O                          set d int (c / 5) * 5
$ w/ M8 D8 W+ w. x   setxy   ( xcor-of turtle d + x )/ N+ G% o3 A6 K% x
           (ycor-of turtle d + y )
; W6 {: i& R: r7 n         
% p* H# d  Z* \* {1 i( z: y  N            2 f( a4 ~( J6 m; ~1 `
if (remainder who 5 = 3) [set k who
, R; m7 t$ W6 F9 L: \0 p) G                          set x( Wid / 2)  
; V& D2 G; m3 w5 n5 |                          set y (0 - Dep / 2 ) ]" e3 ?8 p" z% ]. d) y+ i1 y
                          set f int (k / 5) * 5
9 y% j' u3 B& F- u$ v! V. R  setxy   ( xcor-of turtle f + x )
5 L: f' B" R5 \3 I0 ?& u           (ycor-of turtle f + y ) ! g7 r6 S% e6 Y, j# O
           
, H* F9 |# {1 C% p           
. S# \( ^* \( |8 t* ^  {if (remainder who 5 = 4) [set g who
3 X( x1 S+ \8 Y  B                          set x Wid / 2 . P: D8 e, |/ g* Z
                          set y  Dep / 2 ]& D8 z0 M3 {& n5 n
                          set h  int (g / 5) * 5
. R4 d0 _9 U" b6 F: L& H* y% J" k  setxy   ( xcor-of turtle h + x ). u- m8 ~" E5 U+ B( y3 \
           (ycor-of turtle h + y ) 6 Q$ e7 L) h; \* d9 @! x
                          8 g" Q' [- M2 n( `0 H/ y. ^
                          9 v0 Y7 e# n' ^4 A, l
                          ]
, V3 n. k; q2 s, G# T9 i! send
( t  y- L- z+ ?% w  r; i1 Y4 @8 m. f/ i
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,5 I7 f. s$ ^3 S; d
应该是" {5 l$ c2 X6 I
ask turtles [
# o5 r% R: U4 h1 ^if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
# A% k! H( ^2 Q* Y* B: [                          set y  Dep / 2 5 F6 V2 o) y7 X, w
           set b  int (who / 5) * 5
& C: I2 w. Q; b# C1 J4 R# C4 @    setxy ( xcor-of turtle b + x )
; U8 K+ t, Z4 f& t          ( ycor-of turtle b + y )]]: _8 j! m3 o9 Z
end% ~7 }& I9 d6 S: l# W; y
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-12 08:26 , Processed in 0.012930 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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