设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6759|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
5 J" D& K$ G# r9 w1 S$ Y2 R: X* N  N% R$ }1 G2 O6 e! H3 |
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。* N; ~# F9 ^* u$ `! K
3 F5 N, R: W2 |; @) D, u
turtles-own [a b c d k f g h( ]3 ]. K& ^; O& j6 u+ S! ?
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
3 q: L9 V3 U: M6 a: F/ d: k. W# Y' u]* @% b  g! Q, r3 {; O( Y; G) @
to new0 l* h. A2 c. @, D/ g
  ca' f' a8 T# A# y+ r7 q) d# l; Z' p( c
  crt 5 * num_of_building
" \% C/ [  Y# o) }: n2 Z3 R, A( @  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
. V/ O3 c! X, K% j  scatter     ;;keep center-turtle random positions 2 t3 E/ p8 F( s" v# I8 C
  unit_plan   ;;make up the building plan( d+ S( i% ?3 @: U
end
8 X7 l7 O6 I! {* X' y: [# Kto scatter6 y" ~9 W5 j8 D  S7 v8 |5 G! r
ask turtles with [remainder who 5 = 0]0 i2 I% }' t7 c: U9 Y% I
[
, Z6 I) O- D- Y3 S3 {( Hset xcor xcor - 6 + random-float 15! j8 _. |0 i' V
set ycor ycor - 6 + random-float 15
0 \% J' z# D8 g4 g]
/ r8 U# G/ w& I8 Send$ |5 y% M5 \  n
to unit_plan
% b  p; i" G6 N0 ^( Z# X' |  y7 }ask turtles [- Z  q8 v4 K  L8 t# y+ e3 q, f
if (remainder who 5 = 1) [set a who # `9 ?5 S  n: O7 W) Q
                          set x ( 0 - Wid / 2 )
% j- K5 G5 A% u7 v" |8 J' |; r                          set y  Dep / 2 ]
5 I9 x5 ~& P6 r3 \  u           set b  int (a / 5) * 5, g% H1 J* g7 R, V, O! b
    setxy ( xcor-of turtle b + x )
4 R% S! P1 v3 x          ( ycor-of turtle b + y )
9 P2 j: l+ t, [( u8 l7 {if (remainder who 5 = 2) [set c who
/ r! {6 ~4 _1 X4 i                          set x ( 0 - Wid / 2 ) 6 X. g4 o+ L5 b, g7 i
                          set y (0 - Dep / 2 )  ]
- O0 m5 ^# I1 a                          set d int (c / 5) * 5
, i2 b" A* D4 }3 R9 i5 c   setxy   ( xcor-of turtle d + x )5 n- G( P. `9 G8 Z3 w( k4 b( U
           (ycor-of turtle d + y )
: X  v; X3 V# Y8 f$ Q0 X6 b! b3 a          0 Z# N! [- c3 e/ k
            * L% h  F$ z3 X/ g9 f" e+ ^
if (remainder who 5 = 3) [set k who
5 `3 w- P  g! [% i* b; G7 }                          set x( Wid / 2)  ( W$ [4 U* j2 F+ F
                          set y (0 - Dep / 2 ) ]
+ K# s: |6 X3 @$ u                          set f int (k / 5) * 5+ T4 [4 g! P% l
  setxy   ( xcor-of turtle f + x )0 }3 z$ H# T+ k1 G6 f8 j
           (ycor-of turtle f + y ) 2 u1 q. B1 l: M# m( f
           
% r! R6 k1 K% j& x3 x           
. A" o" r" a; p+ E; dif (remainder who 5 = 4) [set g who
; u1 ?; T$ w, F) Z                          set x Wid / 2
# @- L9 i. u5 q" G4 Y4 P                          set y  Dep / 2 ]0 G& w  W# h' }
                          set h  int (g / 5) * 5* ]9 }- I9 g7 Y) A* c5 Q" N# g
  setxy   ( xcor-of turtle h + x )0 @$ e( y1 F% o9 o
           (ycor-of turtle h + y ) ) W3 [- Z$ r6 v# D2 l$ n
                          
7 J2 h! @% r9 P  `+ ?$ ^3 |0 }  f                          * F' n3 e* U3 d1 t% l: ~
                          ]
/ |, U8 L& G* X. O) o+ u! Nend
; z7 O# c. S4 |2 S$ j: V6 `0 `/ W5 q: t5 i: y. {
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,5 N. V( X+ L$ Z5 C- j0 Y
应该是- ]- P- m5 o, \
ask turtles [+ H' D/ W4 f# y
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 1 b1 v* ?" L0 g! `' Z9 |2 [1 U* e' e$ o
                          set y  Dep / 2
0 v+ N+ m7 e" x+ B- E           set b  int (who / 5) * 5% ?" h9 K( o8 F9 l7 A% Q
    setxy ( xcor-of turtle b + x )
5 e/ w: O& u( ~' S  m) V          ( ycor-of turtle b + y )]]
0 s# c# f5 x9 Z: v0 [; Xend7 S7 {7 H$ A7 Y
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-21 11:55 , Processed in 0.026051 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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