设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7049|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
" f: F/ a) P) e9 K+ g9 ?# h6 {
3 W9 K5 E. [' M; t但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
6 l" F/ ?, T/ a) W/ p/ ?5 C
1 s8 f# @; |2 R0 j8 o2 c& {/ V- ?turtles-own [a b c d k f g h6 S6 E7 `5 W" Y/ A2 v( X2 f
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 7 i" q: |. R% V  H
]" z! o# [) d2 B$ P
to new
5 I0 o7 t8 V. V: q* |8 v  ca0 @: {8 l! h, b- f& L& U
  crt 5 * num_of_building0 c" Y, G3 p, P& |
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]! F  F2 J2 @! ]( e' O" q" D8 h
  scatter     ;;keep center-turtle random positions
4 Y4 w) }( y- I3 e  unit_plan   ;;make up the building plan8 X* P5 Z! n; F8 U
end& a3 y+ h( P+ B
to scatter
+ e4 t- E6 F; j( c3 w5 K* a# Pask turtles with [remainder who 5 = 0]2 f+ K6 ^' A0 e& v( O( l
[
4 @% W- ~# x( g0 c% {/ `: h0 vset xcor xcor - 6 + random-float 154 u2 h/ b1 e. ?+ D6 X" z
set ycor ycor - 6 + random-float 15
* u3 a$ j. t2 R( Q, \# |]
/ @$ L; a8 C* [4 ~3 w5 k9 s  Qend
$ W/ ^: z. `! f* h7 a  F- [to unit_plan
/ u9 T: }0 a) }4 S1 Rask turtles [
1 T2 W/ e+ F- S0 pif (remainder who 5 = 1) [set a who : A- V& C' I2 q$ \0 l
                          set x ( 0 - Wid / 2 )
. E  o# u7 H4 Z/ |' s( U                          set y  Dep / 2 ]# S( B* n; S. [& I* i( w
           set b  int (a / 5) * 5
! x0 M$ [& s0 e# s6 u9 U( C    setxy ( xcor-of turtle b + x )
' A7 S3 _. v) N6 Z4 a0 Z( f          ( ycor-of turtle b + y )
9 p  f. _: [3 o3 s  I# w! i$ L% cif (remainder who 5 = 2) [set c who) b2 u& {3 x8 z4 f2 y& O! M
                          set x ( 0 - Wid / 2 )   ]9 C: B9 t+ q$ a
                          set y (0 - Dep / 2 )  ]
* j4 k7 V% R& h; ]  n# L* y2 [                          set d int (c / 5) * 51 i1 d7 T( l4 L
   setxy   ( xcor-of turtle d + x )9 R8 V% O5 B9 X* l
           (ycor-of turtle d + y )   l3 B+ K$ f1 M, B! _  g
         
0 m4 H% N8 ~/ h+ w* u, [9 ^# l              f2 }1 w8 V: o% m2 K) p3 k  U' C
if (remainder who 5 = 3) [set k who
! e# p8 u$ w" N- F                          set x( Wid / 2)  
) Y  ~! k3 Q' x5 S$ [  m                          set y (0 - Dep / 2 ) ]6 C2 L; Y, Z' \/ v( i3 g
                          set f int (k / 5) * 5
% j/ y  v. \! f8 C4 i  setxy   ( xcor-of turtle f + x )! @. E% |$ U& ?- k% s/ m
           (ycor-of turtle f + y ) , O) y$ D* q- e3 x) |  g9 A* m  R
           6 O5 u( ^4 `: P" J* E6 {3 g
           
, O: S0 {3 w. k3 I3 s4 `if (remainder who 5 = 4) [set g who- s0 h# g) ]: ]
                          set x Wid / 2
  V- Z0 m) D% `1 J                          set y  Dep / 2 ]2 _0 [% g. P6 H/ f/ a8 G& n' J
                          set h  int (g / 5) * 59 D5 N3 q& I+ @+ C/ O
  setxy   ( xcor-of turtle h + x )+ \5 i4 V: M& M7 E+ g! o
           (ycor-of turtle h + y )
* e& V1 k+ G0 f, Z& [7 u' L                          
# R4 g- }- S3 A) v- H                          ( d; Y. A$ n; C
                          ]
) q8 K1 ^) p- |7 f/ vend2 w/ c4 U4 \/ Y  y2 i

8 E* E1 f9 `; O3 U% B% O$ E[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,7 r$ Q  f5 z* o5 f- V
应该是: T: U1 t  J! c& x- F( M
ask turtles [
7 b! `: q$ I+ A( N4 U7 d/ W* }if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
4 T' N- ~2 A8 e" C8 d" u" v                          set y  Dep / 2 . ~2 b7 g# p( A3 l& Y  n) H2 G
           set b  int (who / 5) * 5, l- K1 m% A9 k6 {) ]3 f# p/ X7 o
    setxy ( xcor-of turtle b + x )3 w% y* Z' j+ ~5 `3 v
          ( ycor-of turtle b + y )]]
2 V1 z2 R3 O4 ?9 H  j2 F9 Cend3 H7 j" |# f3 J8 S7 C. A
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-21 08:06 , Processed in 0.012902 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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