设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7245|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
  D* z1 B; W) m* g" f- f3 O6 G3 S8 n1 o- E6 l# S
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。% z# U9 _: i- B7 b# M% K0 ~2 e
( p, r7 k1 I9 v( s; T
turtles-own [a b c d k f g h
8 c7 r) u: @' R  a: o- `9 c  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ! m- o1 t. k8 U4 d3 o$ I1 |1 j
]
2 S; d5 f9 D9 [3 D4 @( G0 ]7 Nto new6 L: ]: e9 Y" @3 ?# ?! y
  ca
/ Y7 C6 S8 w8 Z# \  crt 5 * num_of_building
+ k$ |1 _& v5 P  T$ O8 w8 _  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]6 s2 P, L# f2 {& \5 {
  scatter     ;;keep center-turtle random positions
2 ?" L3 j' l" g# ^/ X; g( t  unit_plan   ;;make up the building plan
8 q( t2 N$ Y/ [2 ?* aend
( i6 \( v  x( Q1 gto scatter$ y& L! c6 y" Z6 J& a* E
ask turtles with [remainder who 5 = 0]
& W3 C0 J+ H* k- R7 F[$ z% C1 N- O& _$ u
set xcor xcor - 6 + random-float 15
) q: w- h5 a6 l/ \- G6 ?( `set ycor ycor - 6 + random-float 15! o5 y- r$ h& o& z' w. M
]' A* x6 D3 x, q. e
end3 C2 }6 Y8 v  N: b' B3 Q3 d4 N% B
to unit_plan
0 M+ i% [6 Z8 N( b6 V4 ^% C% l! mask turtles [
/ i5 A  J! ]- }+ }, m. Wif (remainder who 5 = 1) [set a who
& b& v7 _7 a; P                          set x ( 0 - Wid / 2 )
9 M% z9 J" z  ]; N                          set y  Dep / 2 ]+ y- W2 C# c/ v% }
           set b  int (a / 5) * 5* B8 `* a! r  |( h3 r* H7 s
    setxy ( xcor-of turtle b + x )+ R8 I3 i! ^) k7 n
          ( ycor-of turtle b + y )# V- f- o+ h( g% l9 r, N* s
if (remainder who 5 = 2) [set c who- H. o* g2 b. ^; B% p9 z
                          set x ( 0 - Wid / 2 ) 3 E  _# ?" s* Q5 c
                          set y (0 - Dep / 2 )  ]
( Z* A" M: e; x8 ?4 I! C4 R                          set d int (c / 5) * 5
" H7 s! P4 t& s% n$ X   setxy   ( xcor-of turtle d + x )) L3 l1 F' O7 f) Q. q
           (ycor-of turtle d + y ) % \5 h; h. \& \
          5 f5 ~7 c- j3 ^" |/ ^( K2 ?! M
            5 Q2 t7 q! g& I/ _
if (remainder who 5 = 3) [set k who
& F4 i5 {' a6 D- L                          set x( Wid / 2)  ( ]) j5 p% `: \, Q+ I7 y! j3 X1 U
                          set y (0 - Dep / 2 ) ]
* Z7 p. z% d- \  g& Y$ Q" B; D  h8 H                          set f int (k / 5) * 5
5 L* ?. I5 ]. ~( s; T' t" A  setxy   ( xcor-of turtle f + x )2 C) s' M* q2 a4 L# F" W5 q* `
           (ycor-of turtle f + y )
3 S7 c. \. {; b# i8 `+ |           - k% d4 G& s/ J2 h5 R
           ( }# c- M. |% c( @( w7 o; h! L
if (remainder who 5 = 4) [set g who
9 F* T# a# j. O                          set x Wid / 2
9 o6 f( m6 o( @/ J6 N                          set y  Dep / 2 ]& Z* c! E" B6 L) ?
                          set h  int (g / 5) * 5# c6 j, e3 e4 t2 z
  setxy   ( xcor-of turtle h + x )& u' E; }' m2 a8 x) d
           (ycor-of turtle h + y )
9 K4 M* s2 s& M                          2 D/ V0 t6 L; ?; H7 O0 ~
                          
+ X7 R; X' p% e' g                          ]8 D0 p) X$ o* F9 c& v
end5 `& j3 ^, c  J8 ~3 F0 R: N$ H

$ G# |6 t6 O( ~' q3 O( |[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
: }. `4 E! ?* c5 ^- m/ r, ?, B9 H1 Z应该是
. `/ u5 J0 r6 F1 @' a8 l8 ]ask turtles [
; P$ `6 B; {- V4 h9 ^, ?if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 8 {6 D: ], {. H1 V3 x
                          set y  Dep / 2
8 y- \7 {+ z3 o) }. Q2 v           set b  int (who / 5) * 5
: Y  z/ x* k0 A0 l    setxy ( xcor-of turtle b + x )
( r7 G) I" s4 u6 `! P4 d          ( ycor-of turtle b + y )]]. X! e+ z  f' x3 ~" |6 Z
end
& h3 P, y) E' z# Q* T3 F之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-20 23:55 , Processed in 0.021708 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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