设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8785|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。" |  Z% q+ A  a- e6 D

* j  M. w" Y: v4 ?6 f' J9 D! `, @4 L但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。( m; c! i7 o$ [0 K
1 O  K. A3 B. P( D
turtles-own [a b c d k f g h" o+ A+ z- v( w
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ) M$ e+ S' s! R: n0 j% z7 i
]
3 \: z6 f4 B4 H. P* Cto new* d# ?* X1 U' k. J5 o2 }
  ca0 Z% H- d. Y% @
  crt 5 * num_of_building
- s$ a# c. x9 T. v  v  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
2 w, G' }7 h5 Q) I7 L  scatter     ;;keep center-turtle random positions : {1 h# H0 M6 ~
  unit_plan   ;;make up the building plan$ K* h% y, R/ _+ l5 _: o
end. V& e: I3 s/ Q0 W( P* p" B
to scatter
: l/ V* U( k' F  I8 V9 c0 Gask turtles with [remainder who 5 = 0]
) }) P, k0 o+ K# x[& J3 v3 x. R& N* B1 ~. v
set xcor xcor - 6 + random-float 15; g3 Q: j5 V1 s% v3 b, z% q
set ycor ycor - 6 + random-float 15
6 n& U3 o& w8 C  l" h) k# ~]
4 o# @9 r+ A3 x" D" ]end5 s' Y4 {/ D) B+ R/ l
to unit_plan 6 ~2 ^* P7 w* g' W9 y
ask turtles [/ W" O& P& y) b5 n  ~! ], |
if (remainder who 5 = 1) [set a who 9 f, l% i) X# W
                          set x ( 0 - Wid / 2 )
( Z, n% D  l% }$ \' [  Y                          set y  Dep / 2 ]2 t$ `/ }7 P0 O! d
           set b  int (a / 5) * 5
. J3 q% U% Y/ |! s    setxy ( xcor-of turtle b + x )  }* `: s0 J! h
          ( ycor-of turtle b + y )
5 p, P2 `0 ~$ H0 f# e  }if (remainder who 5 = 2) [set c who# v0 c; n+ J7 }5 b$ x* n! W
                          set x ( 0 - Wid / 2 )
, r" F# r) [! {" a                          set y (0 - Dep / 2 )  ]
+ l1 F5 \3 U0 \( R6 @% @3 v                          set d int (c / 5) * 57 b& `" k4 x6 C! o  m; [+ B+ @
   setxy   ( xcor-of turtle d + x ): I& k2 |2 h: c; u" A' D# [
           (ycor-of turtle d + y )
5 V# W1 G: o' c& F; g# Y- Q) H         
8 P" ]2 Y7 t2 q7 P            
7 ~( E$ U2 `8 l& N  Y, A) dif (remainder who 5 = 3) [set k who+ d* M9 x8 c7 C# N5 I' C
                          set x( Wid / 2)  
0 f/ |& j4 z1 U* |: I                          set y (0 - Dep / 2 ) ]+ U. H6 C- v% j8 l0 D
                          set f int (k / 5) * 51 W9 O7 i# ]7 D
  setxy   ( xcor-of turtle f + x )
3 {2 d' ^" K9 ?$ e# i           (ycor-of turtle f + y ) 2 z7 H! n6 n0 d/ h6 @) @- z( m
           
0 u. B7 I0 Y% ^# ~3 w) _# M           8 i% O# O) B5 k* S: J) D3 m0 K
if (remainder who 5 = 4) [set g who
$ Z; C* ^' W: i0 X1 b) \                          set x Wid / 2 . K! |- F* X8 C4 r, u
                          set y  Dep / 2 ]$ v* E$ }7 K$ O. }
                          set h  int (g / 5) * 5" J  ^, e0 J) P+ L& s; S' L
  setxy   ( xcor-of turtle h + x )/ R  I5 t6 Z5 Y+ N3 c' ^$ J
           (ycor-of turtle h + y ) ( ~# W# D( f# q
                          
: H, f/ ^2 h0 \/ k                          
& ~3 o5 d2 \  e                          ]
! o9 a) f2 v  Aend( [; t: P1 c8 f% [! h. M

1 Z6 H* @% p! L/ C  F6 o[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,) d3 |% R- C3 U# S; [+ {- q
应该是- G* w$ f3 ^' J( _. J
ask turtles [
; I( E2 `  C1 w1 R2 F3 h0 uif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) % h  E+ L) A0 r
                          set y  Dep / 2
" A, Y4 P. m, J: A1 U; ^           set b  int (who / 5) * 5
, O; M- c( S8 T* b    setxy ( xcor-of turtle b + x )5 p9 ~) S* C' E& P1 U" n/ l- E
          ( ycor-of turtle b + y )]]: @) U* ^' M% |# z* X( f* E
end  A1 D4 h2 Q: V! C
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-4 05:30 , Processed in 0.015864 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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