设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8693|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。6 ^4 ?: s5 ]) x2 i( I6 p& @! g/ g

& [4 O. S. ^3 r但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
, }6 v1 b* u: j; i  A( @
+ I% b2 y2 W! D) e) j9 J. C! f* ~turtles-own [a b c d k f g h
! |+ X6 j  ~" J  s7 h  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ( K) l8 z# i: I' j& v; X
]
6 L/ w5 N, I+ [! ]! e, yto new
* e/ }  Z2 T- E  ca1 m. y3 M$ ]0 @2 C" J1 T2 g6 O1 T
  crt 5 * num_of_building
! _6 n+ [  y4 |  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
4 \* s. E! V9 B2 K  scatter     ;;keep center-turtle random positions
' P) d/ N4 g7 }7 Z: u# j  unit_plan   ;;make up the building plan
. K- n% c3 n( e1 D3 J. {9 Dend" t3 B  C. o. b  E  o% t7 l) ?
to scatter
) b5 f, u8 r3 T0 Xask turtles with [remainder who 5 = 0]
! K0 D9 }# g" D! I% i% h2 ?4 `[
2 b6 G1 K% }! kset xcor xcor - 6 + random-float 15
2 c; [1 T. m# M2 @  \set ycor ycor - 6 + random-float 154 F8 @3 u  p5 H  z& {
]
' n& [; p  X/ h. ?, H7 xend- {2 t; ~) b# N& P. I
to unit_plan ' z& e* D8 T6 }; U
ask turtles [
& j& c* n# n5 a6 G$ `- dif (remainder who 5 = 1) [set a who
0 |4 [  ^1 Q' P5 c* S# Y7 ^8 A                          set x ( 0 - Wid / 2 )
$ o, P4 E$ b/ }  ^8 K0 j( l! h                          set y  Dep / 2 ]" ]+ P8 w9 t+ D5 J
           set b  int (a / 5) * 5
: A7 k! R) P" @2 ~    setxy ( xcor-of turtle b + x ). }* {; w' J6 F2 ]
          ( ycor-of turtle b + y )
9 {$ S& k! z' ^. T: z/ Y) m* e! wif (remainder who 5 = 2) [set c who
% [  W2 m! g$ n4 s7 Z+ H9 j                          set x ( 0 - Wid / 2 )
5 s, E, D" e& e6 O% x  @  c                          set y (0 - Dep / 2 )  ]. _6 c! E, j5 w0 |9 V: q
                          set d int (c / 5) * 5# M' c. ^8 k2 l
   setxy   ( xcor-of turtle d + x )5 f/ D# L! w& o/ R  E, R' W
           (ycor-of turtle d + y ) 0 p% P% u7 T; W# z% ]/ S: u: d3 }
          6 _2 g5 ^: B) V" p2 R0 L
            & t3 s; j' m: S
if (remainder who 5 = 3) [set k who
/ R: O- G$ h4 i( X                          set x( Wid / 2)  
* j( v6 Z9 z" Y& n                          set y (0 - Dep / 2 ) ]
% |/ y! T% J/ k& Q                          set f int (k / 5) * 53 ]( y6 @! A: ?* ^& _8 q* O
  setxy   ( xcor-of turtle f + x )1 |% p- ~$ B# C( S! a
           (ycor-of turtle f + y ) & k+ o# B: \& x8 L1 f( Z/ w; }
           
, w, m9 B: u* M2 y           ) `$ x  @! `( Z7 ~/ K) I2 \
if (remainder who 5 = 4) [set g who: y7 F9 {1 ~  P2 K+ r# g+ L
                          set x Wid / 2
) [- b: k- m* Z1 O8 a. }                          set y  Dep / 2 ]) l# ~3 c) K$ ?/ r6 B  C/ R: M3 [
                          set h  int (g / 5) * 5/ X. Q& m- n2 q, s0 K  o
  setxy   ( xcor-of turtle h + x )
; {8 d9 C( n( n           (ycor-of turtle h + y )
$ \' V1 o0 S8 H/ H6 ~1 S                          
8 I3 P+ X$ z* C" l+ R/ k                          
. T+ d* S1 O0 P* d0 C3 |- o                          ]3 v9 ?& a1 n; G* Z0 X
end
- \0 e$ j4 b% [5 Z) ?0 D* R0 _. x; U$ Y& D. `
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,. Q: J" e) Q! j1 ]7 E
应该是5 s- g, h. B+ Z6 G! D4 s; ?5 r) a6 Q! v, N
ask turtles [
: |5 J0 [. D) }9 iif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
& B* j/ b0 O" `% h8 I                          set y  Dep / 2 3 C5 \. @# \8 R2 m4 d/ D
           set b  int (who / 5) * 5& Q# O$ ]* Q" h  F1 m
    setxy ( xcor-of turtle b + x )
7 I" K; K" {6 @          ( ycor-of turtle b + y )]]
. _: ~& h0 F4 a5 lend) W0 J5 L" o+ k2 f+ A
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-26 22:39 , Processed in 0.016501 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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