设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8390|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
/ G7 \0 U8 j: i2 W5 I% \/ o& e, O( Y/ q! P0 U" @
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。2 L: W# F) }! S$ Q1 L* E% p  W
. w' n7 j) ~/ Q2 ]
turtles-own [a b c d k f g h
1 Y; W7 T  M& d/ K& Y% L  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
$ e, m; A  t( n4 ~/ f8 u% ?]2 o5 M3 M. R$ ^, u: ?; r
to new
+ j' J6 A* E7 Q' @3 S, b  ca# d* Q* \' Y  L. |/ `
  crt 5 * num_of_building
) f2 y! r' S' V& B9 C# w, X" @/ i* Q  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
, ?6 W) |3 Q' I  scatter     ;;keep center-turtle random positions & m, T7 \7 q3 Q; T. Q7 v; ^2 @+ q9 q
  unit_plan   ;;make up the building plan
, j8 e1 I5 U9 U5 `# `/ |0 Iend
% `* l+ j) b. i" o8 c9 tto scatter6 s5 y" S' ^- j5 F' r) s( i. ~
ask turtles with [remainder who 5 = 0]6 D3 g! ^$ l' E' r7 S, z
[, T* J- e! f* _1 [$ A. Z. G
set xcor xcor - 6 + random-float 15/ a& M& q0 R2 O7 q7 Q
set ycor ycor - 6 + random-float 15' I, \7 b8 ~) ~2 W" n: B
]
' C. O7 Q* K% f- L" m9 w: xend
% {" ?* a( q9 q6 N# Mto unit_plan , c2 s* i$ _& m5 Z
ask turtles [( v% k3 }6 K5 c3 W$ N3 x. a: _0 J2 X
if (remainder who 5 = 1) [set a who
4 s; P3 C4 Z5 J: u: i                          set x ( 0 - Wid / 2 ) ( \* C  W2 T3 m* ~: I4 ^
                          set y  Dep / 2 ]7 C/ Q; J7 P8 e6 N2 Y
           set b  int (a / 5) * 5
8 J5 L+ h2 l: r* i8 m2 P7 K4 z: B    setxy ( xcor-of turtle b + x )
& @1 W' ?* n# U. o          ( ycor-of turtle b + y )! l; L4 I/ X. T9 _. m
if (remainder who 5 = 2) [set c who* g: I' H4 z$ d( a; z) I
                          set x ( 0 - Wid / 2 ) $ U# N/ F, g" x* u" }
                          set y (0 - Dep / 2 )  ]
7 O1 a- e/ ~5 T$ R                          set d int (c / 5) * 5
, `. I" R8 V1 y; m* K3 E. b   setxy   ( xcor-of turtle d + x )! P1 n9 p2 R& q0 d
           (ycor-of turtle d + y )
7 C# {& X# }1 j; u3 m. i* w          4 d6 x( |7 f; ]" \3 A3 }
            / N% `) S, ?' ]: B! }+ L' W
if (remainder who 5 = 3) [set k who7 |; a+ l  h- \2 x$ N
                          set x( Wid / 2)  & R1 `* b: C7 T% M* m2 n7 ]
                          set y (0 - Dep / 2 ) ]
% P1 N7 Y: x8 `9 m- A. l                          set f int (k / 5) * 58 A% O$ M  d& k7 h9 F6 D4 t
  setxy   ( xcor-of turtle f + x )0 f& e1 B( @! L
           (ycor-of turtle f + y )
: J: V4 ^6 v! m% ~$ M* S9 T           $ u% T3 e6 y$ D, g; w, w8 H/ ^
           & {+ x& L1 d: `* S$ t8 s8 h- i
if (remainder who 5 = 4) [set g who2 |6 I1 U  g! \2 Q. e: x2 M
                          set x Wid / 2 5 Y1 e+ x( R! G3 n- L0 x) n8 A
                          set y  Dep / 2 ]& b9 \7 n% F9 L  {4 j
                          set h  int (g / 5) * 54 r: Q4 ]* M. `- R  Z
  setxy   ( xcor-of turtle h + x )9 V- _4 O9 y" t. r7 ~% ]' |" u
           (ycor-of turtle h + y ) 9 q( G9 x" y9 e, |3 h! n
                          
. x; S  W, g; d7 i5 F                          & B* W: R) E' V9 H
                          ]
' m3 }3 B  ]. t' U1 h* w# Z8 |end
# i% J* N9 f3 @' k  V7 I' `  |% t/ d# h) P4 A. @" g( l
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
  K% q: L, _; t7 D) p应该是
( j6 q3 X* \4 b$ J- l9 eask turtles [
( p, g2 b" [* }$ d. q4 x  v- Rif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
' k9 X) @: Y9 u8 P                          set y  Dep / 2
0 d% f/ I9 N$ L9 A; i# `. {           set b  int (who / 5) * 58 q4 E5 U3 s$ J. E9 g: M3 L  F' J
    setxy ( xcor-of turtle b + x )3 i7 l, y7 g6 F+ X/ u
          ( ycor-of turtle b + y )]]5 O) a# e1 o- \; W2 K' A
end) g$ `! A0 M( x" i* ]
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-18 11:14 , Processed in 0.014881 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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