设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7686|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
' E1 f# k  C# J4 @8 u6 j# y) Y! F0 R* b& v& H: s$ `9 a
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。3 D% t: k; d0 a0 Q
( z) N! a. A  ^+ N5 G' U% H
turtles-own [a b c d k f g h: D& M7 A8 {) Y$ y' ]
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
7 n. ?3 Q0 s- `% o2 d; Q. v]3 @* z& F2 G6 Y4 }! l; F& [) a# I2 _
to new# W: z* U/ t  i7 y' J
  ca0 {% c% B3 W9 T, F2 C- p2 \
  crt 5 * num_of_building
/ q$ X& J3 e: u0 X  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
) B1 M+ n+ G) R8 ?0 y( q  scatter     ;;keep center-turtle random positions
7 y$ W& W. ]3 F0 u; C! q; B. Y  unit_plan   ;;make up the building plan# F0 }% x6 ~4 n0 Z/ f4 p7 F
end
5 W9 o% g8 Y* L0 c5 G) Wto scatter) n  n& U% ]9 a0 j/ K; @2 I! e
ask turtles with [remainder who 5 = 0]5 ~# @2 [* r/ h3 E! l$ r* |4 A. ]
[
3 A4 `, G. U1 M- V2 B3 c2 Sset xcor xcor - 6 + random-float 15  B3 c* Y) ~! L
set ycor ycor - 6 + random-float 15
9 G8 |( D, l/ `3 @  `]
8 K9 q9 D8 a* F* S7 P5 q1 Send5 Q# }: A8 y! Y9 d' p. W# |
to unit_plan 4 q& W* A% R- ?$ Q9 ?: x
ask turtles [; Q! W" z0 V! e* b
if (remainder who 5 = 1) [set a who
  c( a. ]$ j7 G9 J                          set x ( 0 - Wid / 2 ) & v: H8 u  D; w% |( {
                          set y  Dep / 2 ]  F9 x9 e% M4 {, v$ h7 F- Z3 W
           set b  int (a / 5) * 5
$ V( P. b. [' P1 p! z9 c8 O    setxy ( xcor-of turtle b + x )( \$ Q+ R: v. e9 S
          ( ycor-of turtle b + y )
3 }" E$ t3 H* N' e2 e5 |1 Xif (remainder who 5 = 2) [set c who5 p* g  }+ d3 _8 A2 y* H: m
                          set x ( 0 - Wid / 2 )
- m2 }3 q4 i  g( L# m  D. S1 n                          set y (0 - Dep / 2 )  ]
9 W! H1 P+ J9 O2 P( K1 L                          set d int (c / 5) * 5% g, e) }) C1 @  h7 h
   setxy   ( xcor-of turtle d + x )
; A" N. n! b; S1 U           (ycor-of turtle d + y ) - H8 k( @8 i4 F& D# P1 N3 q4 a& ~# A
         
/ u* h/ h" Z' K5 s            
* E  D/ _4 @- a* Y3 C9 R- Y: v9 N$ [if (remainder who 5 = 3) [set k who% r6 l/ `' @. h6 W1 t% e* y
                          set x( Wid / 2)  
8 q& {& T9 q1 B$ f                          set y (0 - Dep / 2 ) ]
5 R0 Q2 U  J; L# y2 n& _                          set f int (k / 5) * 5
& B! R7 c8 l" C$ v- h2 ]7 t+ n  setxy   ( xcor-of turtle f + x )
6 O8 h( f" o: [0 l' O. O           (ycor-of turtle f + y ) ! M+ Z6 L7 M" m: I: _$ ~
           
% g8 |- v) f7 V* t2 d           
8 T4 Y0 J* i! J* ~8 F7 d1 U# qif (remainder who 5 = 4) [set g who! D( F6 N  Y5 k3 o+ k) q' V! t7 B# K
                          set x Wid / 2
% n. V) i$ h( p* c% y                          set y  Dep / 2 ]
4 W. S- H, U3 ?8 y% q                          set h  int (g / 5) * 52 R' s7 O; v) J$ A% i- z+ y  J  ?. L! V
  setxy   ( xcor-of turtle h + x )
: C# N3 d) S9 a# g7 B* ~           (ycor-of turtle h + y ) ! }( ?2 o+ {% H( t% F0 H
                          
. {3 C# _+ `- H                          
  Z8 W7 Y7 h4 s3 q) d" f. y1 f                          ]
6 w' w$ G& p0 Vend
- D$ Y( S# Q: d' k. T4 \4 p3 k2 ~8 G
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,7 o7 m# d' i% m  }
应该是
/ \8 N: V" M' fask turtles [
: I5 ~8 m0 a4 e) H/ g+ i; u! |if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) # ?' W# L4 n" V
                          set y  Dep / 2 2 i" S" E( C; h& u/ f* s
           set b  int (who / 5) * 59 s" z1 |: k1 F  H
    setxy ( xcor-of turtle b + x )
6 m! J- ]; Y$ K% c          ( ycor-of turtle b + y )]]; y. ]9 \* C, m( G( u) {
end
5 R' Z5 D& H; Z5 n' E4 `$ e! p6 P之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-3-14 05:55 , Processed in 0.019298 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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