设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8039|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
! o4 v4 P5 R( f# L- P1 b0 A
& b( Y* @! Z) F# M4 V. p8 c但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
0 e6 B4 y% |! T, R9 ?, A' v- N. _3 F9 ]. W  [3 C
turtles-own [a b c d k f g h
* Z+ _; ?$ ~" u$ E3 a: I( s" P; C  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
6 B" j7 J& ]! P) R/ X8 N]
& d8 r- H& N9 v# Vto new
' y1 k) P! e$ I0 s  ca* H+ z* N% K) W8 ], D; ?4 r5 X
  crt 5 * num_of_building
/ G, J8 M- H# g8 K8 Z  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]* |7 {& Z$ c0 c' L, g* B1 t
  scatter     ;;keep center-turtle random positions   G$ Q" i: x# Y2 S4 L1 J, M
  unit_plan   ;;make up the building plan; t: R9 ^& C5 y( P" n# _( E
end
. Z9 f1 n' |% \+ @' Sto scatter% ^3 C- S, B. ^' w4 m* W
ask turtles with [remainder who 5 = 0]
1 K) A% T& E) v; ~0 X[
" S$ O, G2 E- q& x4 z* h  Pset xcor xcor - 6 + random-float 15" g4 y* x! g9 R8 I. j+ c/ S$ N
set ycor ycor - 6 + random-float 15
* z0 D9 S( \$ i- _/ ~  t]
: N. [: }/ S# i$ L0 D6 t! @end4 U" z! ~/ X9 l8 l' X' V
to unit_plan
. b. L8 H! O9 X; u) h3 X& rask turtles [
5 X6 i) Z. I6 [if (remainder who 5 = 1) [set a who + b/ M8 H, D* t: \
                          set x ( 0 - Wid / 2 )
3 A. v8 \8 j3 X                          set y  Dep / 2 ]
6 t5 t) ?9 n# ~' b4 j! z/ T$ Q% Y           set b  int (a / 5) * 5
- L6 A0 T0 t8 z0 g, j, L    setxy ( xcor-of turtle b + x )
( t3 w% r; }0 e4 Y& F          ( ycor-of turtle b + y )8 N; }7 D6 c7 t5 n/ c' D
if (remainder who 5 = 2) [set c who4 A- o: ]% x$ d- l$ R6 b! N
                          set x ( 0 - Wid / 2 ) 4 e& g5 w. U: p  `* V
                          set y (0 - Dep / 2 )  ]
8 P$ U- {5 b- S3 S1 T                          set d int (c / 5) * 5
0 `% X1 ~: E4 C) |1 I6 l/ @/ S   setxy   ( xcor-of turtle d + x )
! @% `* J% t: |. D: X' T           (ycor-of turtle d + y ) 1 c' T( G& d/ o8 c( l
          : v8 Z8 Z* x2 _
            9 u& x& O9 H! t! z# U6 _
if (remainder who 5 = 3) [set k who
+ T$ F! a# H* ]+ ]( H$ A- L                          set x( Wid / 2)  
  a+ s- v& X* M) }# a5 w4 y& P! N; w& G                          set y (0 - Dep / 2 ) ]8 y0 w' Q. T" t" d
                          set f int (k / 5) * 5
* X; }1 P; @0 ]2 G  setxy   ( xcor-of turtle f + x )
5 A1 |5 A/ ~! I* ^* u2 d           (ycor-of turtle f + y )
/ o6 C/ ?# u3 l% x$ u           
, C' c6 H  d" q" E# x0 _$ B$ H           3 K( }, q+ p6 H, P5 L) t% S
if (remainder who 5 = 4) [set g who
# L2 H5 s6 O# }" D7 }0 I. C2 B                          set x Wid / 2 5 `6 `+ {% Q8 i# O. ?
                          set y  Dep / 2 ]# g1 ?: S8 k8 D! U" @0 U! P
                          set h  int (g / 5) * 5
$ Q; V) P1 X$ u1 p8 ]4 y' D- b' T  setxy   ( xcor-of turtle h + x )
9 ?: G/ K4 B. v/ X" Y           (ycor-of turtle h + y ) + r" u) R* H8 u6 P+ `8 p& K( I! E
                          % a8 u& w4 g) ]" k
                          
! V/ ~4 W; M" S# _* W. q                          ]4 ]$ ?4 \0 O) Z- ^" W% x6 N
end
. Q4 B* N/ w) p# z4 F( ~1 Q5 M/ p- Q3 q: E
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
/ }" C/ f+ K# i! Q% h4 Q0 ?7 j# {应该是
% h8 B# [- n/ z% {: v; V! s7 oask turtles [2 p$ }# X+ M  E$ V
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) : [7 r( L- b# p& Y
                          set y  Dep / 2
# U, ~$ x1 w# K% F: b% W3 Y# [) M9 N0 v           set b  int (who / 5) * 5* x3 U8 q  }& @" r
    setxy ( xcor-of turtle b + x )# J2 h; i/ N# w% @! ?% K' M
          ( ycor-of turtle b + y )]]
3 v6 x* A" d0 D5 pend7 }4 h1 X$ M7 M
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-1 00:53 , Processed in 0.022267 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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