设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7557|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
3 R, o' w8 X' \$ i% r( e! \
" \  k. k& B2 v% [+ h% n但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。* X: V4 v6 w0 a5 \/ n. g6 M
/ s3 p6 |" _8 ?; l8 M5 R' h
turtles-own [a b c d k f g h
2 p* V8 {1 |" y0 D. D- m3 v  D9 u  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
1 s& s# l. t1 q]0 ?& {  v- l- M1 f0 @$ O7 x2 x# O% A
to new6 E; b# g1 d1 h5 f
  ca, x7 N, N$ a, j
  crt 5 * num_of_building
5 L; I8 R' a& h  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]4 v9 H+ f: Q! |, G- G6 P0 k. Q
  scatter     ;;keep center-turtle random positions 1 C5 p6 W" u& c1 `1 t8 g
  unit_plan   ;;make up the building plan' j4 m4 n) z$ i1 f$ Q
end
6 c$ b7 }1 {9 G& hto scatter% o& H' O; O# O* e
ask turtles with [remainder who 5 = 0]% n$ Q# v3 r2 W; j/ p
[
  I6 ?! f; A- C7 X1 {" s! @3 fset xcor xcor - 6 + random-float 15
1 J# f& a! E) v" ~& n/ y/ d1 y. ^set ycor ycor - 6 + random-float 150 j+ _$ S6 Z& k
]; ]* ]; }; R1 [0 V* v5 y
end
! S( I( r4 k. ~5 f# w, Y. ito unit_plan
% N  Y! i  w+ I9 m; m8 C& v  Aask turtles [
$ W4 \9 r4 h' L# c" P- j9 N6 |if (remainder who 5 = 1) [set a who
# e1 Z# d: O5 k9 e7 ]: v/ g( e                          set x ( 0 - Wid / 2 )
+ r1 b" Z6 M. M                          set y  Dep / 2 ]2 i4 ]+ M2 B& [3 M! ^+ W8 Y5 N
           set b  int (a / 5) * 51 ]9 ^. O1 x" V9 x- J- K1 g
    setxy ( xcor-of turtle b + x )# p7 Y" p" O# B& K1 C
          ( ycor-of turtle b + y )
6 i  b9 X7 T  @/ C, Kif (remainder who 5 = 2) [set c who
- \% A) R. z8 B; d; J+ k8 W                          set x ( 0 - Wid / 2 )
2 P- I6 }' e, G3 h                          set y (0 - Dep / 2 )  ]  Q8 x. j: |5 A2 c8 g# \! z
                          set d int (c / 5) * 5
! J3 H* g" M' w* ?1 B) ]   setxy   ( xcor-of turtle d + x )
& a. n/ K3 g* F) Y8 T8 M4 q           (ycor-of turtle d + y )
6 y- P0 m- S' N  o         
) L3 o! `3 k! a9 L) k+ P            % T$ a# G  L+ c# S4 k+ q; j3 g# a
if (remainder who 5 = 3) [set k who4 @' [9 _( R0 G
                          set x( Wid / 2)  
) `5 y; m  R, X5 ]. Q                          set y (0 - Dep / 2 ) ]
% v, a- ~5 Q5 ]  _3 z                          set f int (k / 5) * 5) z' V9 K) i7 `, W: ~$ Z2 m
  setxy   ( xcor-of turtle f + x )6 k" D" S. J- G8 s6 d8 U
           (ycor-of turtle f + y ) . f) Y( h% i* A* [: g4 u6 `
           - M8 A6 p$ G/ K4 G* t+ _1 s: p" _
           
9 {' Z2 v2 g' P8 `+ _. Jif (remainder who 5 = 4) [set g who
/ S6 n# E: Z, D; ~9 w( |6 f' e                          set x Wid / 2
& @! `; X$ {/ l& a                          set y  Dep / 2 ]
) H4 F3 S! ^* j3 p                          set h  int (g / 5) * 5
) t; L& T0 s; C9 C2 a% k0 n( S  setxy   ( xcor-of turtle h + x )
  g3 ]4 f# r  C0 Z7 k$ ~+ q1 l+ h/ Z           (ycor-of turtle h + y )
7 Y. e5 R4 H" J0 f/ t                          
* o$ P) x' c) e, T% e' P                          
; O) h; K  A$ h0 n                          ]
6 w* y) u6 x) a3 u! d* Qend3 \, y  S, r: j- v" v
; W! J: l2 |0 \) x/ x
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,  L0 A9 F" l* H: r$ s
应该是4 u/ f) p! j0 e9 y8 ]
ask turtles [0 Q3 f  u, W1 q  Z! L4 C+ N/ W: H2 N
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
8 L1 h, ^" m( W; Y5 M/ |/ ?                          set y  Dep / 2
9 T, z) {8 L& i8 n# t2 W4 l           set b  int (who / 5) * 5/ ]% m3 X3 r1 G6 \
    setxy ( xcor-of turtle b + x )
) p( ~0 q6 I" r/ L& b5 _9 E0 A( @          ( ycor-of turtle b + y )]]$ d& y" v) U4 H) n0 h$ _
end
* U" O! ~9 V. W. V之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-26 08:08 , Processed in 0.017126 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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