设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7370|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
+ y7 g. d* p" k9 D4 e& J+ h8 M4 N; W
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。& q/ j7 o/ a% t7 Q  M6 D
2 }; K+ U5 U9 G! c" P
turtles-own [a b c d k f g h3 L4 z+ Z, E: l- Q
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ' ?9 L' t9 M8 V8 A3 Y# |2 Y9 i
]
* ]1 u5 d5 S" @# G  C- kto new
3 j% N7 _9 o7 s0 Q4 w  ca
4 S% ^' N; P* ?, S  crt 5 * num_of_building6 O& l/ ]7 D8 U' _4 t/ F7 P
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]: Z; n0 g, O( e6 X- I7 n
  scatter     ;;keep center-turtle random positions
# W% y' |1 t, b* L# x/ e/ ?4 [; t  unit_plan   ;;make up the building plan* S$ M, N- C7 E% C( D
end
# r; M" U# Z( E7 |% C/ a6 f4 B4 E+ m0 Bto scatter
9 \6 b! F( x; `; h+ i( wask turtles with [remainder who 5 = 0]
3 s1 X9 M! z+ A- p9 X1 d[) \9 c+ Y6 r  l# N2 w) }
set xcor xcor - 6 + random-float 15* ^8 W2 n7 [0 A1 ]
set ycor ycor - 6 + random-float 15
6 z( [( U8 B+ A, h' [( y9 p3 p]( ^& D  t! ]7 q2 \0 F
end
5 q. I0 D+ m$ ]) P3 n" c& Uto unit_plan
: ?7 q. _$ w  f& u! Lask turtles [* ?9 @! [  m! ?6 O' R- n0 {
if (remainder who 5 = 1) [set a who ' F' s  G! i: y. `7 H& g8 [( s
                          set x ( 0 - Wid / 2 )
# Y- y5 _% [% @- K# j                          set y  Dep / 2 ]9 f# P; s' l& l0 r7 h3 o
           set b  int (a / 5) * 5
7 m* _4 J2 o* t( Q    setxy ( xcor-of turtle b + x )6 f. W: Z) B3 q. {% ^
          ( ycor-of turtle b + y )6 b/ C8 Z4 U7 T, N$ n
if (remainder who 5 = 2) [set c who- Y  P, W# B* k- j2 X: Y! W( }" i
                          set x ( 0 - Wid / 2 )
( F2 @# h$ l) u+ ]                          set y (0 - Dep / 2 )  ]
+ m2 O0 R/ @' X6 c* U8 L/ m                          set d int (c / 5) * 55 A5 [& D& w2 W2 z% C
   setxy   ( xcor-of turtle d + x ); j1 ?2 s( t" v! z) g
           (ycor-of turtle d + y ) 1 I" l  T. Q1 B& {& z! q& O
         
* z6 p, ^/ K2 b4 K3 N            
, f0 v# W4 z" M* Z8 Uif (remainder who 5 = 3) [set k who
, e( a3 I0 }2 i2 E                          set x( Wid / 2)  ! z0 k/ |8 t7 [' N% N
                          set y (0 - Dep / 2 ) ]
8 F' h* x- }2 V9 q5 m7 d                          set f int (k / 5) * 5
! G8 p( z$ c3 I  x  G, U) F  setxy   ( xcor-of turtle f + x )
7 J: s* P2 g1 G* S2 C6 g, n           (ycor-of turtle f + y )
( _" k7 M: G1 A. e           8 q$ Q( g2 t0 q' I! Q0 `
           
! Q7 J" q4 h8 u# `7 s# Fif (remainder who 5 = 4) [set g who( x0 t  Q4 j' l! }
                          set x Wid / 2 8 z1 V3 D  v- {% T6 F
                          set y  Dep / 2 ]+ Y; N. k2 s% x" X' L# U5 V
                          set h  int (g / 5) * 56 h1 I5 ^4 T4 F6 a
  setxy   ( xcor-of turtle h + x ), F: M6 \, ~3 n) g
           (ycor-of turtle h + y ) & Q7 P6 p: J- S( M
                          ! S2 y; m8 x) w- M$ x1 t
                          
9 V/ N. a5 y9 E                          ]0 E: h/ x( K( h% ]  B
end
1 c0 V- s/ g! U4 }  m
5 v$ L2 }! A# l6 z[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,* |0 ?. Z% U  ?5 F: f$ \1 s; ~: i
应该是
* P# o5 O" h3 fask turtles [9 x5 l4 z, B$ f$ @
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 7 J/ c& Q) d* V- Q2 F# M
                          set y  Dep / 2 4 Z; m5 [$ {, h4 H
           set b  int (who / 5) * 5: Y6 }2 ]' s# |5 y3 m
    setxy ( xcor-of turtle b + x )
. r' s, @* R5 ^* X6 O          ( ycor-of turtle b + y )]]2 o# h4 O( Q( R6 i6 e! \; y# |
end$ s4 G" ~7 U3 D5 h" {
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-4 16:14 , Processed in 0.018603 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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