设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9116|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
5 N$ a3 F; @- J" T# B& L
5 j) o) f0 h/ y9 O/ O但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
4 o' H* D( v- o3 v0 I7 s
1 }* i4 v4 ^: lturtles-own [a b c d k f g h
4 I3 S! u1 s0 p  B$ o- s) C0 M  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ! A/ ?9 V- ]) U1 r% g$ ^
]
2 n7 x* p0 {1 g3 k& _. ito new9 W2 h" t7 l  J* Q7 v7 Y% F7 A
  ca, s1 ~  ^8 |# W  ?) h3 {' U
  crt 5 * num_of_building- U- Y  H5 I& c* ?2 `- k, U8 Y" Z
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
- S8 {: K6 x2 ^1 h; M  scatter     ;;keep center-turtle random positions 7 z9 y1 n% D2 X: ]& W' j* h
  unit_plan   ;;make up the building plan
* ?0 w0 ^6 R7 P( Iend2 m5 q/ V0 E$ V- J! r( b! E
to scatter
; C; A2 G3 t/ M0 U9 N* F% g( _8 ~ask turtles with [remainder who 5 = 0]
' ^: E$ g8 Q& a' ~[5 U$ s" f. j3 v/ s& e, u
set xcor xcor - 6 + random-float 15
* G1 l0 S" S+ k9 z; }set ycor ycor - 6 + random-float 15  U" w: z* y& p0 A% H: J+ N
]
1 |/ A& x4 A* tend1 W; A# j2 d0 C6 w
to unit_plan ! a, \  W: u& ^% t$ T8 H2 B
ask turtles [
! v0 v; o! {; a3 Q0 {; G* M5 rif (remainder who 5 = 1) [set a who
5 L, y4 V2 ?" p+ e8 q                          set x ( 0 - Wid / 2 ) ) W- X& Q3 ^) @1 q- A9 F
                          set y  Dep / 2 ]2 L# X' {0 ^6 \' k6 s' m
           set b  int (a / 5) * 5
1 `, B, {- g! s  w8 @: b( H    setxy ( xcor-of turtle b + x )/ m0 r0 s- i, [1 [7 Z" k" ~
          ( ycor-of turtle b + y )
: t2 q/ V2 r9 wif (remainder who 5 = 2) [set c who
2 S4 \& S& i) \# b/ p0 D, r0 n                          set x ( 0 - Wid / 2 ) ' @% q+ |/ @: H  F: m% @$ @. |' p& ]
                          set y (0 - Dep / 2 )  ]
' f( {$ h' l4 m1 P                          set d int (c / 5) * 5
' {) {  R6 _# M5 \+ @+ j5 a: k2 C   setxy   ( xcor-of turtle d + x )* H* g  M7 n8 f- U- s3 t
           (ycor-of turtle d + y )
: \- `( q5 w: _3 Z         
- [7 ~* f" e9 s: f            
; Y  N+ c' k( l2 @4 l) Cif (remainder who 5 = 3) [set k who
7 c: M! \7 D' j                          set x( Wid / 2)  
. O: H2 D) h4 M, }                          set y (0 - Dep / 2 ) ]
8 x& O' C; s6 q- N1 G3 v                          set f int (k / 5) * 57 V- P! c3 M- d: t/ ]6 m: S' ?
  setxy   ( xcor-of turtle f + x )+ O/ A% ^  c( k
           (ycor-of turtle f + y ) 8 x6 ]4 I7 h% s) j/ K( t
           " l. t( [1 n5 O. W- P
           9 i; p* L9 w. U& x0 a2 i% x
if (remainder who 5 = 4) [set g who
. ?4 y7 E! _9 J) h( l                          set x Wid / 2 ; |; F8 ^" w6 A: t! s
                          set y  Dep / 2 ]# Z8 P/ }1 ^$ x$ D0 e1 _
                          set h  int (g / 5) * 5# @( D; I7 [/ h
  setxy   ( xcor-of turtle h + x )
' L: D/ l: }& O2 y, H1 C: |           (ycor-of turtle h + y ) 0 U, t) N- ?5 @" U( }, j
                          7 K: m. W& H% z8 x+ H4 j) l, b9 j
                          
2 |; K, ]8 q0 r                          ]' V# b5 O6 |7 e( H( [
end
( A# I' n. W2 s
1 d0 R& J- N! d! K7 Z[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,! R/ C, U4 U- ?" l( R7 I/ d/ T% j& |% O
应该是
$ [5 O1 O! W/ a  l2 zask turtles [
& {9 [& z6 N8 Z$ @. K; g9 uif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
9 K8 G$ h& I7 n* e% A* @                          set y  Dep / 2 , p' s$ b( ?& u* F4 P
           set b  int (who / 5) * 5% n, M: V" i( W& h+ Q7 V3 g9 T5 ]8 D! r7 E
    setxy ( xcor-of turtle b + x )
5 H% z8 B' L' e3 B# E0 \; a! O          ( ycor-of turtle b + y )]], v. L! L+ h2 J$ o( y% [
end0 ]" p6 j: l4 o6 X% O
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-19 23:03 , Processed in 0.015667 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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