设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7874|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
/ Y4 d3 G' R* d( {; S
% k! m+ r7 w. n3 l但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。( J) K& e% i  ]: I$ Z0 r
6 Z/ I$ N$ S7 a2 _9 L9 v9 g
turtles-own [a b c d k f g h
, A" X2 z. o. ^( V: s$ F' P  x y     ;; these are the leaf-turtle's offsets relative to center-turtle * `- }* o& m, J6 p$ I" M
]6 u9 y! z2 k0 [7 E
to new
5 h# C0 b# ?% z+ Y8 m4 I6 f) ?3 Y  ca
6 O- k6 Q! J' ?: Q  crt 5 * num_of_building7 q" G6 c$ r8 ^
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]2 |' y9 ?/ s; z6 d% J9 X
  scatter     ;;keep center-turtle random positions
1 |% V2 H! u4 h+ j  unit_plan   ;;make up the building plan
# C. `" o& g" q* \/ T4 ]' w; W" Qend
8 B4 [4 p1 k8 d2 z0 o8 hto scatter# Z( T" X* Y# g. P, |
ask turtles with [remainder who 5 = 0]
, N3 m2 ?6 E- q. W+ h[# J+ R! U: `# V6 }! m1 F
set xcor xcor - 6 + random-float 15* n# j* p3 J" X: j, m* C  P
set ycor ycor - 6 + random-float 15
: ~& f  J: q# u) j]
. x. A& R- p. i) v1 uend
! f4 U* N: b. I+ F* Fto unit_plan
0 W5 t" F0 F0 @( ?ask turtles [4 o1 r" c1 q, ^# z3 K! o) L1 |+ g2 U9 m
if (remainder who 5 = 1) [set a who
  F2 H4 d$ |3 N, d: Z) V! N9 T7 y! {                          set x ( 0 - Wid / 2 )
& X. L. q( y6 _4 o                          set y  Dep / 2 ]
+ h$ j5 B6 b0 {; u$ x' a( k, V( ]           set b  int (a / 5) * 5
5 ~  g4 Z  y- y    setxy ( xcor-of turtle b + x )0 i  [. G; n5 G/ K7 A: I2 P
          ( ycor-of turtle b + y )6 [3 P& P7 [2 Y! h' o( K
if (remainder who 5 = 2) [set c who  U$ c. t; S% f
                          set x ( 0 - Wid / 2 )
$ o* J- g. s# W5 }# ?                          set y (0 - Dep / 2 )  ]9 C3 @& d9 L. ^0 n
                          set d int (c / 5) * 5
: S, {4 |- l* O2 r0 N- @   setxy   ( xcor-of turtle d + x )& L& w1 u, k# w7 m
           (ycor-of turtle d + y ) 0 D% o4 y3 w5 S. K. @5 m3 G1 p: v
         
" E) x' O( x' c- U% L+ `            & q6 Q  k  j. g) [' x
if (remainder who 5 = 3) [set k who
4 K  A/ J+ Y. d& b5 s; N                          set x( Wid / 2)  
9 k3 k. a- b7 ?3 m- s                          set y (0 - Dep / 2 ) ]
$ n/ @7 N6 s  Y5 H* Z8 H" y0 V                          set f int (k / 5) * 5
3 `$ w# Y& }$ |3 c" S! E  setxy   ( xcor-of turtle f + x )
/ @/ P" `# k! D8 t, b' P4 H0 k           (ycor-of turtle f + y ) ; _# }9 W: A# h3 H# i1 q
           2 l7 J8 j) o; d
           
) ?/ V+ J' V) h0 A) p7 p8 h; tif (remainder who 5 = 4) [set g who/ l$ L. o- m; P! P$ Y5 s
                          set x Wid / 2
" P2 l) X/ y! C                          set y  Dep / 2 ]
( ~1 R7 `! g6 u& U! o5 Q                          set h  int (g / 5) * 5* e' J  u- u$ Y6 o
  setxy   ( xcor-of turtle h + x )7 f  S7 C4 s% \8 _4 ?5 H0 \
           (ycor-of turtle h + y )
; G7 c& M# Z) i7 L                          
  X5 `; G" d5 k. Z4 Z0 s                          6 Z9 i  t( W( K* R( N$ ^
                          ]
" |8 Y2 X# H0 e# |: T% f6 ?& eend
5 F6 h4 D! p% P) Y1 `
1 D9 k7 l7 M' t& }; a3 s[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
3 \8 ~  K' E% b& B& M8 A1 \应该是
% m0 T( }2 A' r1 Nask turtles [
4 v  q6 q- z/ x4 @if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 3 _8 q- M& L% @2 e) M
                          set y  Dep / 2 2 C. a' x9 L' s* ]
           set b  int (who / 5) * 5
2 i; B; Z, z, X# y    setxy ( xcor-of turtle b + x )3 C; X  w2 I1 k/ E% ^2 Z/ h
          ( ycor-of turtle b + y )]]
9 z! w& z& ^. Rend
9 i) J! n5 z9 `( S' {& A2 q之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-13 16:22 , Processed in 0.018255 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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