设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8478|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
3 x4 N* @5 b7 P! Q+ N2 A5 {% x; J& ]) X4 B* v
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
- Q  ]! R; d; j8 O# m/ h  n0 l( K3 W) O- S/ o& p
turtles-own [a b c d k f g h& j9 o! t- Q7 o( ]: j  m
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
' i' X( Q) Z! h3 `7 `( E]
- w" y6 S- `9 y/ R+ a6 jto new# l* o& p2 n$ t; K! F
  ca
& Y% J4 G! B2 |4 d" W- |: o7 m  crt 5 * num_of_building
6 Q- f; i7 K1 y* \8 F2 q  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
; M) M1 P1 e& z" b  scatter     ;;keep center-turtle random positions
- \& r* E5 W) j  unit_plan   ;;make up the building plan; v& a+ `& d) g$ [0 Y" z, G
end
2 G$ K9 D* z, t5 yto scatter  e3 P- I, T1 S. O0 N! ^
ask turtles with [remainder who 5 = 0]) h* T) H  Y; H
[" ?& V2 O0 d; K* l8 L4 H( ^
set xcor xcor - 6 + random-float 15
% U2 q; ~* Y6 D+ p4 S8 J' g5 y/ Sset ycor ycor - 6 + random-float 15
" D# i3 i/ s; q]0 S& d' y- d1 m
end+ z# s: y: D+ q
to unit_plan
" w1 X' ^, O7 {. M% {ask turtles [# G' `& M; m* d4 B& S, w1 n
if (remainder who 5 = 1) [set a who . |  ^+ O! ~. ]" h6 [
                          set x ( 0 - Wid / 2 )
5 E' M2 B. d: \) o4 M# S                          set y  Dep / 2 ]
2 a% A- h) D$ v3 w) A/ U: U           set b  int (a / 5) * 58 v0 N4 f  v# t" Z& H- C
    setxy ( xcor-of turtle b + x )- p# x1 P& f8 t; P
          ( ycor-of turtle b + y )+ Q3 N/ F/ Y4 u( _  {
if (remainder who 5 = 2) [set c who
8 }* {! l% I. D& Z8 t' z% n                          set x ( 0 - Wid / 2 )
; |( [+ w( o* l8 Y# q2 L1 m                          set y (0 - Dep / 2 )  ]
5 o- n6 Q8 p6 z6 T/ I2 x: _                          set d int (c / 5) * 56 ~4 k, {8 `3 U
   setxy   ( xcor-of turtle d + x )) h1 x0 h% X1 Z7 E( ]1 r
           (ycor-of turtle d + y )
* |1 ]3 m5 g. o0 {* }9 ]: N) D; o         
8 l$ }9 i* O6 M- Q; X            
- F3 B2 g5 m$ Y* tif (remainder who 5 = 3) [set k who
' |1 y8 H- C; {, E$ @                          set x( Wid / 2)  + I. _9 J( c6 P8 l: U2 [
                          set y (0 - Dep / 2 ) ], ]) i0 z1 I$ W- Q8 R0 W
                          set f int (k / 5) * 5, ~( C6 y! }0 {
  setxy   ( xcor-of turtle f + x )
# |: n5 s+ M& L! W: w# ^! F           (ycor-of turtle f + y ) & J4 ]' R9 Z+ J5 U
           
$ f4 ?/ N) ?: `9 M- |  U- b           
# _; n1 l6 J( w. ]1 nif (remainder who 5 = 4) [set g who
8 N" P7 A) v) ~                          set x Wid / 2
2 L: a# G: }) Z- n                          set y  Dep / 2 ]
' E( V1 W, Z: s# V# J                          set h  int (g / 5) * 5
4 T, N) C& |9 [" R. E, x7 a  setxy   ( xcor-of turtle h + x )5 w. d* L# j  ^% Y! B' c4 z
           (ycor-of turtle h + y ) * u5 E" Z% |% `  P: A
                          1 G0 i: ]  i) _
                          
, s* m5 a$ }# z8 D3 L! l" A                          ]# d- x" k- l* Y+ x  s% n' M
end
: E' D2 T) d, l& s/ u, M; @3 m! g" l3 f9 M7 x0 `- i
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,1 O, E# ?+ }# e" E9 @# F2 n' V
应该是* K% v4 f% k8 ?5 k* [6 c
ask turtles [
4 d* r: D, c7 m* Q) Lif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
7 e& \9 \8 }; b$ }& b8 N- X                          set y  Dep / 2
: X! d( V, j# G: `8 v           set b  int (who / 5) * 5
  B+ k7 n" ~# A5 Q' t' L# Q/ @& d    setxy ( xcor-of turtle b + x )
  @4 ?* _: E& I          ( ycor-of turtle b + y )]]
. I7 H2 |6 C) P4 {) ?/ z0 n" Pend! F) b7 l* E7 |& U
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-7-2 13:21 , Processed in 0.016768 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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