设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7876|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。+ N  s9 A& X' X' T; M

/ ?; d4 d* @- }6 Q) ]但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。, v( W' _' r6 v+ Q, e4 S

4 s, }5 F$ z+ Zturtles-own [a b c d k f g h) g/ U" v$ C9 Q( x
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
$ i# o4 J1 Z( H) P, _]1 t/ ~% Y- {) \: U: g
to new. a" K6 ?: R. t1 `, ]
  ca
  d% p- u0 @; |3 V' C: ^  crt 5 * num_of_building- |# ]) Z- j# L, i! M0 F* o
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
0 g& O0 R7 a( J  U3 ?5 O  scatter     ;;keep center-turtle random positions
9 S8 v3 [7 j+ d8 e1 w2 p2 P% x  unit_plan   ;;make up the building plan
  S' h3 `. M; Qend, r6 t+ l" b0 _- G. L
to scatter
- H9 B' G2 B; q  C+ J" oask turtles with [remainder who 5 = 0]
$ }% q- [" ]* e) Y0 B. ?[
9 k# K6 O0 V' e+ hset xcor xcor - 6 + random-float 151 ?+ a0 J4 u! E6 z  D4 t! i% m) u
set ycor ycor - 6 + random-float 15
2 p2 Q6 a6 g, N( d2 B" V]0 @9 {3 y4 a" A: k) z" O
end
" X9 K( ?2 e1 Q# l& @to unit_plan . j  R) E+ w  ]8 W% W
ask turtles [
# [- h! E: n% iif (remainder who 5 = 1) [set a who
: a0 j; I/ A& I+ _2 K                          set x ( 0 - Wid / 2 )
/ U: {, C, u' n                          set y  Dep / 2 ]& B* d4 _& @5 H/ q1 s: o; v
           set b  int (a / 5) * 5. E+ n. e' W3 A) W
    setxy ( xcor-of turtle b + x )
0 r  Q: w# g, C+ M, G$ B6 J. d          ( ycor-of turtle b + y )
* n" {% B1 o. U4 q* m) s+ d0 T' Yif (remainder who 5 = 2) [set c who3 i) a6 I6 _+ C: E- b- s/ o' C
                          set x ( 0 - Wid / 2 ) 8 g$ N' V" [# F, o* J% F
                          set y (0 - Dep / 2 )  ]
; Y- X: H3 i3 Q0 J* a, {- e                          set d int (c / 5) * 58 t& U4 ~! U" \5 Q
   setxy   ( xcor-of turtle d + x )
0 W3 l) E! w" T( j7 R           (ycor-of turtle d + y ) - r) f9 [& K3 D5 ?5 i/ g3 L
         
" [2 ~3 b7 R% e$ Q/ T2 Y! O: m! M            ; a6 ]1 a) ^# }
if (remainder who 5 = 3) [set k who* I9 m& x, x* J- h
                          set x( Wid / 2)  : [$ K1 x* ?9 p0 c: c( A" u
                          set y (0 - Dep / 2 ) ]
8 M5 n( Q2 P  w: V( N7 r' n+ o                          set f int (k / 5) * 53 ?8 c- Y) l! K+ @$ B% g6 u& B# C
  setxy   ( xcor-of turtle f + x )6 [0 K9 U% u/ h; g1 E
           (ycor-of turtle f + y )
) |  r, W0 _) a- h1 M9 M9 ?           0 J  U1 ?9 j# X( r+ u, X
           
0 J. u$ X: [: d! l1 z5 |if (remainder who 5 = 4) [set g who2 z$ i9 p& e0 d3 Z9 I8 U
                          set x Wid / 2 : c8 j7 c7 H9 g5 j8 _
                          set y  Dep / 2 ]
1 N# |5 _* W: k9 e* |                          set h  int (g / 5) * 5. I; W, S# C- N+ z; Y
  setxy   ( xcor-of turtle h + x )/ O! s0 M& y6 l- w7 D3 h+ Q& |
           (ycor-of turtle h + y )
8 r& y. L) H% Q$ ]: S5 \+ \4 U                          " d8 |: A: r. j. t  a4 d- e6 ^! _
                          / ~+ r' Y/ t2 l* l7 F
                          ]- ?% H6 k; e+ f! c4 l
end
; m7 }- N: C8 @, A. d3 U
; H; v$ F& e% n+ y* R8 M[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,# @0 X# l9 y5 Q8 M8 A6 D
应该是
7 f4 b7 Z, f* a9 j, |2 |, Q; V) Bask turtles [
$ C. a3 l' d. U6 o% ]4 r. ?if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
# M7 B5 G/ C) _  S2 l4 t                          set y  Dep / 2 5 s+ ~+ }& F7 ^' ~* \$ Q, `( F. m
           set b  int (who / 5) * 5
1 a( ]; s% X+ Y  n" [    setxy ( xcor-of turtle b + x )
8 H5 [7 v/ y! N, {3 I, t          ( ycor-of turtle b + y )]]
% r( F, Y0 ]5 S' p2 `! bend) T, \9 J. z. p+ h- E% v
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-13 22:25 , Processed in 0.018547 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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