设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8074|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。0 X% o4 [5 @0 G8 s0 @4 _8 T

# v# Q! _1 j' L但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。" _1 h* P4 {7 l- a. Z

& S; J% P1 S0 Z; A4 N7 iturtles-own [a b c d k f g h
# W2 e9 I& X8 X  x y     ;; these are the leaf-turtle's offsets relative to center-turtle " u! q3 V, N& {. m# p* f  y+ c2 D2 E
]2 @; I4 E5 W5 e2 Q
to new
" i" M' z  ^+ W' w# K( W5 K  ca/ P  d! M! D* X: ]9 Z8 Z3 @
  crt 5 * num_of_building
/ |" t" R1 U/ M  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
# Y5 F: {8 D, U1 G! r  scatter     ;;keep center-turtle random positions
2 o" ?8 S: l, p3 t  unit_plan   ;;make up the building plan
4 R6 ^' x3 E6 a, s9 nend1 t; Z$ o! C3 Y! A( U- r" [3 _) H  f
to scatter* O  r4 a# ?6 _: G3 ~
ask turtles with [remainder who 5 = 0]4 P" l0 o9 {; ^3 O; b( Y
[
7 Q! |) b& R; ^9 {* w9 \set xcor xcor - 6 + random-float 15( ~  ?! Z1 p  E1 h- s
set ycor ycor - 6 + random-float 154 g+ P9 U% v' Z' R  y/ a& b
]
/ Y6 k% r) w* M  Gend
4 X1 `8 r- U5 R" R$ c8 \0 bto unit_plan - {3 v( s' p) v# a% K
ask turtles [* j3 j3 d9 a" f
if (remainder who 5 = 1) [set a who
/ l: f1 O" s7 t/ @% E: s                          set x ( 0 - Wid / 2 ) % P' O8 w# m* q5 a. O+ ?
                          set y  Dep / 2 ]
( Z* y. J/ @6 e/ Q5 b1 f0 n, \4 q           set b  int (a / 5) * 51 }% |" C" T; A1 c
    setxy ( xcor-of turtle b + x )
8 M2 o) K/ c  g          ( ycor-of turtle b + y )
, g! \8 M+ T( q% j% |if (remainder who 5 = 2) [set c who- o) \$ e8 m% e% j
                          set x ( 0 - Wid / 2 ) + W! I& k1 t7 l5 M( O& A
                          set y (0 - Dep / 2 )  ]0 T* C$ c' c' e  q' C( Z" ~2 h
                          set d int (c / 5) * 5
2 d8 |. ]8 s+ ^+ Y. n   setxy   ( xcor-of turtle d + x )
& G' @& g1 D0 L" F           (ycor-of turtle d + y ) 0 p2 v# x/ H4 I  O+ p9 M
         
' \" g& T* g- E9 r            
3 x- t7 B( h+ x5 m2 \+ Lif (remainder who 5 = 3) [set k who
: @- z: K( r' r                          set x( Wid / 2)  
9 l* ]# Q- k! |4 f6 E4 Z                          set y (0 - Dep / 2 ) ]5 T9 w( ^" v9 g1 R4 \
                          set f int (k / 5) * 5. E* l4 o0 G# r2 S2 o' w# t
  setxy   ( xcor-of turtle f + x )& p+ ]  W! j6 s4 B. A  ]% E  G
           (ycor-of turtle f + y )
& `* d1 s: }/ s7 G; _6 ^: _             Z) Y. W" |" H+ h
           
+ F' _+ \: L8 @4 fif (remainder who 5 = 4) [set g who
; d2 T8 r/ J1 m/ p# i4 B                          set x Wid / 2 # e2 D5 K* K& M$ T# Z4 ~
                          set y  Dep / 2 ]5 z9 _; a* w! H  E# P" U, G
                          set h  int (g / 5) * 5
6 b6 y, h! a1 \# d, o4 |  setxy   ( xcor-of turtle h + x )
+ Q  [: g* R0 [$ d           (ycor-of turtle h + y )
9 T1 y' J/ K/ R" H% A                          
& Q2 u2 Y, ~& f0 h                          6 h+ ^5 Z# X* W2 d1 J2 |
                          ]6 K4 [  i" n3 `- ]9 P0 h. J1 @. x
end6 q( c, o, A* V( l3 D/ q) P

; d: D; \2 ^8 y; O[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,% V* a( L( z' W5 V/ U- J  C) q6 W
应该是8 y- J4 h3 b6 f; M' c
ask turtles [
, ^+ @8 x- R; e/ J: Lif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 6 c+ o) s$ L4 i5 i2 @0 p
                          set y  Dep / 2
  @% h0 T* Y- i: t! [           set b  int (who / 5) * 5$ }( Y9 z' E9 v5 J$ w
    setxy ( xcor-of turtle b + x )
; a2 [' W) v2 t' o9 n) n+ R6 Z          ( ycor-of turtle b + y )]]
/ D( t6 z, ~! J$ Y2 fend
$ J1 B; l9 H1 c+ L) J/ u之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-4 07:26 , Processed in 0.017902 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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