设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7986|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
  O7 W9 w( [/ M" Y7 X# [
' Z$ q8 T, V0 L$ Z6 M: M但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。& h# y1 y  J4 i. U# L: w4 ^

" G3 @. Q8 i0 g9 ~# |5 Y2 {turtles-own [a b c d k f g h
( l+ }8 ~1 [& F! x6 u7 v  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
% F1 r" _) F2 H8 Q5 Q]
/ C# W. J5 Q* w& R1 o3 S/ T3 ]5 Fto new: N8 o2 `) \1 u. [
  ca
. u7 F' S6 y: Y; [$ x5 @; y0 N  crt 5 * num_of_building( U, o- T/ |3 k3 U! }% ]! Z
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]4 w) N  H5 I+ q  c% K
  scatter     ;;keep center-turtle random positions
- w; O: v+ h6 \8 l3 d5 m  @  W: E  unit_plan   ;;make up the building plan
  \0 A  V3 C( d# n) Aend" ^! p" A5 b1 y
to scatter
2 l5 A, q, \  W. C" `ask turtles with [remainder who 5 = 0]
. K/ c9 w$ F8 i[
' C" R* D& p/ J0 Sset xcor xcor - 6 + random-float 159 D. L- y' S! c, T8 l
set ycor ycor - 6 + random-float 15
' g& c- H" W8 W5 _]
, m9 F8 y* J* c2 o/ jend
; z7 W, S0 M/ I" Wto unit_plan 1 e0 M9 {" ]2 p$ c! w( A
ask turtles [
* @/ b1 _$ \  M% D' M3 cif (remainder who 5 = 1) [set a who : ~' z# s* m& u+ Z; Z
                          set x ( 0 - Wid / 2 )
6 a, L: @2 l+ R8 w% d& W1 C: D. j                          set y  Dep / 2 ]
  P/ D1 c9 q: ^( v$ \3 D( f2 T& Q           set b  int (a / 5) * 5
+ W) i9 X  u6 i: I' A7 C: ~1 M0 N    setxy ( xcor-of turtle b + x )! k2 b: {, |- S- A: J, o' B& N
          ( ycor-of turtle b + y )
3 S0 ^5 o3 R+ a* Y( r0 K1 u( Nif (remainder who 5 = 2) [set c who
; s4 d# Z& t# g$ u                          set x ( 0 - Wid / 2 )
3 b5 u* F/ U% \. t' ?4 M5 }                          set y (0 - Dep / 2 )  ]. t1 v- m  }0 \
                          set d int (c / 5) * 5
0 s. N0 ?5 ^' S' n4 d! u   setxy   ( xcor-of turtle d + x )
5 ?( Y& z" ]! }& _; a           (ycor-of turtle d + y )
! T3 h: R9 Y/ I/ G         
7 p- B+ U8 b6 F& ?9 D# r5 H            * I0 B7 m- n/ N, }2 C7 j
if (remainder who 5 = 3) [set k who% D4 J- K( O- a3 j- W
                          set x( Wid / 2)  7 O3 ~8 Q7 ]) X/ W: Q
                          set y (0 - Dep / 2 ) ]
7 D6 M! U2 h$ U3 U" P0 Q                          set f int (k / 5) * 5
7 w; h3 G% V/ o* }: x4 w1 h! H8 S  setxy   ( xcor-of turtle f + x )
" `4 @* u. U" _1 M* q           (ycor-of turtle f + y )
( L3 H* F5 `" \           " t! q8 W# }3 [( B" n
           
: p1 M7 I8 a/ M* uif (remainder who 5 = 4) [set g who
0 C- \8 O+ ^( g2 g$ S" x6 V                          set x Wid / 2
8 {4 g$ H! w: M' J' B                          set y  Dep / 2 ]
3 w0 u6 E- B# Q( ^( W# h- h- p                          set h  int (g / 5) * 5/ u2 U5 R7 L* ~% N7 ?- v
  setxy   ( xcor-of turtle h + x ); W9 G: o2 F: |
           (ycor-of turtle h + y )
6 ^: U7 _2 @0 O; ]. j) G                          , N. }' B  h" L" l4 H0 A! y' D) }3 H- X* g
                          
2 M( N6 s' G% P8 S9 t6 n7 C! m                          ]
! j- V5 C* {& p, D7 ?4 G# m0 Zend) [& M9 I# A8 Q- g, K
. ?9 v* S0 a8 P
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,' ]5 s# I" t, N
应该是$ p" R3 x8 }$ B
ask turtles [
4 X5 v2 S6 |% H2 X5 V. F/ Iif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
; P2 Q4 M1 g( o& ?/ n7 t                          set y  Dep / 2 & o& \" T# S! z" R, U6 y1 {
           set b  int (who / 5) * 5+ O. G3 k1 K3 z3 q) m
    setxy ( xcor-of turtle b + x )6 Y  g! J0 O; }) E+ m' a
          ( ycor-of turtle b + y )]]. j' W0 V8 w' z- N/ n' {
end, R- b( {- p1 Q! g" w& n1 `( ~
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-25 02:34 , Processed in 0.019021 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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