设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6898|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。4 O$ Q, |( a$ X# [) h
; W5 @: y8 X0 g% d6 A+ s, N. M
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。, a1 A6 b- u( y/ n; d, f! c
  U* M1 a6 ]. j5 A& B
turtles-own [a b c d k f g h
) m: Q- g1 X1 Z6 ~+ c  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
) n+ y! ^+ p% K/ f$ A% D1 Z]* [1 r: i0 x. F: ~
to new/ b' J4 H' M1 Y% W# v$ c2 o( E
  ca
( V) z4 v# z- i0 n4 g  crt 5 * num_of_building  i# {& ~8 x; W" X# G' r
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
; v2 `* }" O3 L, k: H' {  scatter     ;;keep center-turtle random positions
7 R7 ^) ~; O: N! J1 [% N  unit_plan   ;;make up the building plan
2 n  y# @/ y8 d# \& S7 X, aend$ y6 t9 C) j! n% v3 y" w# V
to scatter
: k, o0 I! D, ~$ uask turtles with [remainder who 5 = 0], Y( L) a/ |: s* a
[' ?7 C, S) i9 H- S
set xcor xcor - 6 + random-float 15
0 s& p$ D" }2 g) R6 F6 ~set ycor ycor - 6 + random-float 15' h  j. }8 {5 P4 b" P
]
( l: {" F6 \0 @1 I) Send3 T4 s, E4 x* j# v- O% g- I; [
to unit_plan : I  ?* i' R9 D; u: m
ask turtles [
0 m# n4 G7 |0 `5 t& @. F, X, U$ hif (remainder who 5 = 1) [set a who
+ I; E7 s/ r/ \7 j) @) n( M                          set x ( 0 - Wid / 2 ) 4 E- }! r' g' G( t+ G# Q
                          set y  Dep / 2 ]! |( N/ }& G$ O" O* t' P1 T- A
           set b  int (a / 5) * 5
# q& ]2 c+ o7 p    setxy ( xcor-of turtle b + x )( f  W% S3 m. H7 w
          ( ycor-of turtle b + y )4 }! @, K( _( e4 `
if (remainder who 5 = 2) [set c who
% w$ b7 V& U' M& z                          set x ( 0 - Wid / 2 )
: q. b4 m' a: V8 P                          set y (0 - Dep / 2 )  ]
7 H* e! A. N( I$ e, }5 ^9 m                          set d int (c / 5) * 5: ]: v, n6 X4 G* ^2 B
   setxy   ( xcor-of turtle d + x )
# h3 O: ~. p7 J! T9 K1 h$ K* t* |           (ycor-of turtle d + y ) % `0 B( m6 |: |+ Z) E
          ( f, R4 {4 R# L0 l" G
            
3 f0 e; u3 N  d8 {( Iif (remainder who 5 = 3) [set k who( t4 X- e: H: q. r
                          set x( Wid / 2)  
+ B& M) Y( G1 M( B+ s                          set y (0 - Dep / 2 ) ]$ t$ V5 o* Q" c0 W
                          set f int (k / 5) * 5
) o7 p% V) g( ]' ?1 Y' p  setxy   ( xcor-of turtle f + x )
, S+ ~' G0 @! d0 s           (ycor-of turtle f + y ) & x. a' e. c( b' Y' V! j' @1 C# Z  U
           9 ?+ |0 S& {+ `# I
           7 X5 c! R" U3 m3 z
if (remainder who 5 = 4) [set g who7 L6 S( q5 t. D! `! x. }% V
                          set x Wid / 2 / o* p! l( d; X; _
                          set y  Dep / 2 ]
- D9 B" G. ?; W- y- f                          set h  int (g / 5) * 5
0 _, K+ Y/ C* y7 n, U5 O+ z  setxy   ( xcor-of turtle h + x )
7 k8 }, K# g; x2 {9 `$ J* O           (ycor-of turtle h + y )
' M" G& n( g& \. G                          8 T# g: T( y+ E7 m
                          + Y. O9 D/ O- x+ E( F  N& x0 ]
                          ]
/ z, T- k. \. e8 Q" w( fend4 n( U  X. O9 W! b, n5 I
& m- c- ], i% F  m  N6 V, `7 |; H
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,& Z$ R0 U: J. f" Q
应该是) I& D- s& h8 H, r) a
ask turtles [
* w7 ~; r1 K1 Hif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
6 A5 Y5 C: m7 J                          set y  Dep / 2 & E/ ?, C5 P4 j& ?
           set b  int (who / 5) * 5
7 \) d: K, X/ P; |( C- {+ U    setxy ( xcor-of turtle b + x )
2 d; v" s( \* E6 Q/ C) Z          ( ycor-of turtle b + y )]]: w2 n, m3 A' p$ I, K6 I
end
; B* L1 ^' C4 l: S: H之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-7 07:52 , Processed in 0.019880 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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