设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6780|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。( O2 M% {8 q6 s9 J

; \) V7 i2 R# i# [但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。& K' H9 h2 R5 `6 w3 q3 }5 V6 D& u

4 ]# _4 c" Z7 n0 P2 m7 @turtles-own [a b c d k f g h, o6 S" O1 U, B  I" }% M. P, R) T
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
$ ?  f0 q( i5 U$ ^" g$ \]. X( X% ^( t) E" X: y* l- F" x
to new
9 y. U1 Z, s4 _7 r2 v  ca
6 `, {) ~: F2 o- ~6 B2 K1 m  crt 5 * num_of_building
  J$ j# b$ h, e9 k5 s# G/ ]# P  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]( X' a' Z( X# e4 S$ D. e" ?" z: h. O
  scatter     ;;keep center-turtle random positions
2 u7 E3 H3 G+ e' E4 J! i# l  unit_plan   ;;make up the building plan
# m6 X9 |. d9 |4 h: I+ v, cend
2 u8 m8 W. C$ s) s$ ^, E, |to scatter* m) K% V& ^5 j  d! {# f
ask turtles with [remainder who 5 = 0]
5 [4 I( m& R8 B  T) ][
3 G% x6 C" @" g5 Eset xcor xcor - 6 + random-float 15: F1 J) _! J$ C) }$ Z9 C5 w
set ycor ycor - 6 + random-float 15
7 N1 F; @; T6 C% S! k6 v]: ?( T) \$ Q- }& z# A
end, l7 |) \) H4 f& N7 A
to unit_plan * x" d# U- y3 e! k
ask turtles [
7 I, G' s  z- r3 Xif (remainder who 5 = 1) [set a who
# s( F9 L% I" R+ _- u                          set x ( 0 - Wid / 2 ) : H/ d3 O5 R' F- f1 R$ c
                          set y  Dep / 2 ], g' I+ U& u% c7 X) r
           set b  int (a / 5) * 5
1 Z8 K4 b2 _1 b4 ~) g4 \    setxy ( xcor-of turtle b + x )
# o# x% j! Q; Y4 m          ( ycor-of turtle b + y )
. E( P' f& }1 W# `  [8 ]if (remainder who 5 = 2) [set c who
2 _$ L& H2 Y' `) F9 G2 R                          set x ( 0 - Wid / 2 )
  `8 l8 [7 D3 U- A3 ]                          set y (0 - Dep / 2 )  ]
: O! v. T: J- j+ O! M0 Q! C9 c$ r                          set d int (c / 5) * 5
( ?  X+ B+ j5 Q$ O# V" c) d$ Z  a   setxy   ( xcor-of turtle d + x )
+ ]' ~. v9 r2 @           (ycor-of turtle d + y )
9 \2 [3 m' F+ u: ^         
4 z' B4 ~" w% F$ n7 R7 T! U            
# n# I6 }& X# J! s" hif (remainder who 5 = 3) [set k who
8 k& R; ^5 H1 q( s2 D  r                          set x( Wid / 2)  
5 u. f5 i, t& b                          set y (0 - Dep / 2 ) ]# o1 ]- r5 b; @, x7 v
                          set f int (k / 5) * 5
' U6 Q8 B. N5 G: ~" g  O2 c* ?  setxy   ( xcor-of turtle f + x )
6 e2 {* S  F2 q. i% ~           (ycor-of turtle f + y )
  D6 m6 D" V7 P$ y, i; d           
6 B) a5 |0 V: \0 ~           9 R1 g1 f6 }5 ^
if (remainder who 5 = 4) [set g who
5 x0 ]- F9 X& F# a- K                          set x Wid / 2
+ ~% V  y  r$ r( g( F7 t- j                          set y  Dep / 2 ]
8 L; m' Y; F1 Z6 e( w# w& F                          set h  int (g / 5) * 5
; v/ d+ [" D8 g4 b  setxy   ( xcor-of turtle h + x )" t1 P  t: ?# m6 f0 _, N
           (ycor-of turtle h + y )
. K! e- A9 i3 W                          2 s# g1 n3 T$ U, M# f
                          7 L# h, ~: o, B% |! ]
                          ]
& D9 L6 ?4 L& H9 T( y& send( x. N% B3 a  l8 G7 x
9 a1 W! ]7 W: ~4 B# \$ g
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,/ V, o( e5 }; @2 C
应该是7 [* o; v( N; U* p  D6 V1 u% B
ask turtles [
9 x2 L9 `0 d3 N. @" Aif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) . a& o9 Q$ k4 w- G8 @
                          set y  Dep / 2
1 h: i# s: a6 v- M, n" L; [           set b  int (who / 5) * 5
) Y# c1 j- ]6 R8 R/ ]5 n    setxy ( xcor-of turtle b + x )( L: _  ^* b0 J- w1 y  t  v
          ( ycor-of turtle b + y )]]- {; G' @$ w, `
end! c# p* o, y4 d3 H
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-11-22 23:38 , Processed in 0.014291 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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