设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8831|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。/ ]- V- s7 k+ r7 ]
- C4 ^" \! s- X. O3 F
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。2 r7 z2 \+ @- d  M4 b
' b; i8 V* p$ ]  ^/ d( I
turtles-own [a b c d k f g h
8 V* q- G- p% k  C4 A% n  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
& s1 s1 V) P' d: G- h9 e/ i]
- @4 Y) t6 @5 w, m. rto new5 q1 P+ x/ @8 B  m, P; h
  ca) [8 b/ h% R0 K" P. u) L
  crt 5 * num_of_building% l2 T$ [6 C' P3 ?5 G
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]9 y6 y# I( h+ e
  scatter     ;;keep center-turtle random positions
, F3 [! Q+ i7 h4 V4 s; b5 }; f# T6 i  b  unit_plan   ;;make up the building plan
: ~+ X$ \2 d0 uend
$ i) U8 t& Z5 Z- S, kto scatter1 X( b2 A( U0 C9 v, a' i
ask turtles with [remainder who 5 = 0]% S; i: a2 ^, B* `  t! }- @# ^8 |# a
[
5 `, W' s" _0 ~3 j4 n% s( [/ R* nset xcor xcor - 6 + random-float 15, w) i/ B, a, f0 @! u" J% n
set ycor ycor - 6 + random-float 15% Z6 j6 v" H! b1 q( x+ _# ]
]
, k# c+ l8 e8 ~! ~/ ^end
2 _4 `% i! g! f. B  ^to unit_plan 9 O# R, f: }8 {* j
ask turtles [8 s, L8 |; s( i, d, ^! I, b/ H
if (remainder who 5 = 1) [set a who ( }% V& ]8 H8 O- X5 f
                          set x ( 0 - Wid / 2 )
; j# a' y0 p( A                          set y  Dep / 2 ]
. L! `9 ^$ o' E5 Q8 c' _           set b  int (a / 5) * 5( m, Z0 |. N, x5 `
    setxy ( xcor-of turtle b + x )
$ y; y" [' @( U$ w" X( A1 U6 K          ( ycor-of turtle b + y )4 g7 b0 ^* H+ \4 T
if (remainder who 5 = 2) [set c who  g: q/ y  f+ x; y; L7 r0 N
                          set x ( 0 - Wid / 2 )
$ P* G7 E5 ^6 O% w; Q& M- z% n                          set y (0 - Dep / 2 )  ]
: I/ A. e, p9 z( R( E- ~. I  Y                          set d int (c / 5) * 5; I/ c3 c* ~* Y& ?* l
   setxy   ( xcor-of turtle d + x ): [* b- y! K+ v+ y$ J- ?2 ]! K
           (ycor-of turtle d + y )
3 }) b4 z: e! u3 u6 ~          9 k/ _. ^, R. C/ T6 u$ ~  w
            9 i" f. F  \/ r5 r& ~: a
if (remainder who 5 = 3) [set k who5 z. l" c4 y  T: \7 o
                          set x( Wid / 2)  
* J( y& o2 \% x; a                          set y (0 - Dep / 2 ) ]
% |0 x( y; z* j8 R6 m                          set f int (k / 5) * 5
2 ?" ~! X* x, c2 n) e7 t, [  setxy   ( xcor-of turtle f + x )+ O  k1 ?; B% f+ Q7 J
           (ycor-of turtle f + y ) 3 U, E" m! G% P8 e7 l7 c
           ( B: [9 L! K  p; L5 `9 i: q; d3 t
           
3 {( J) I* _" Zif (remainder who 5 = 4) [set g who: C. z4 O6 b) _  o/ k1 e
                          set x Wid / 2
" g. {% l& O1 c! O  e+ B1 l                          set y  Dep / 2 ]
3 G; U0 z1 I: t0 R, D) y                          set h  int (g / 5) * 5
, n  `" z$ f% `  h& S4 R7 d  setxy   ( xcor-of turtle h + x )
( V+ T7 C! `" p8 X           (ycor-of turtle h + y ) 5 G% _9 U  l5 B+ g
                          % N7 e$ s# [7 C# H" r: _
                          
+ I% y6 F8 x2 j+ n! N' q: e( s! c                          ]
& `! _1 E; y8 mend
$ ~" t6 g1 s% x7 l6 {
5 r3 U$ S0 T$ X! o[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
8 G7 `' p  ]0 @3 N3 _# L0 I应该是' o% {; m/ g* E3 h2 v' \3 P
ask turtles [+ `+ ]8 f- Q5 N: H" T% J/ }3 t
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 6 Q7 y/ l5 k5 S5 c4 A
                          set y  Dep / 2 ' v$ v, `8 l$ j9 L# y0 C
           set b  int (who / 5) * 5- P$ l+ d( y( Z, V
    setxy ( xcor-of turtle b + x ): N3 n5 v8 B* p" t! X0 m( Q9 @
          ( ycor-of turtle b + y )]]
3 |# Q: s9 p5 ?/ n2 z6 Aend
8 b  ?# m- X, [9 `: j之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-9 08:18 , Processed in 0.016697 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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