设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9154|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。1 O+ f% @- h0 o0 r6 _
6 |) ~4 O; N2 r5 @0 K5 u
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。  J" e! z: R$ C6 s+ t& y( g' p

! e; E2 ^+ M0 M- {' N6 Fturtles-own [a b c d k f g h
  ~- E- b6 \+ G0 h7 a3 [+ O/ {  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 2 O, ^- b2 ^4 F  l' f# u2 K% F
]
) @8 B; ^+ k- y' D( tto new
/ s! o. S, K- t) @8 U, p  ca1 B4 }4 Z1 k; h5 ~: E; n" y
  crt 5 * num_of_building3 N7 s  W, \. t; [9 @
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]* I/ z8 a3 o7 L% [" c
  scatter     ;;keep center-turtle random positions ! V3 E# C) b5 u1 s- r
  unit_plan   ;;make up the building plan+ p6 L$ R* ?$ u& |3 @
end
( Q. e% |3 c8 x7 g! I& o2 d2 o* oto scatter
5 j4 r- u# z- c2 u- nask turtles with [remainder who 5 = 0]
" O9 a) k0 G1 E2 R) S+ b[
% C$ \0 l# [# A7 j1 zset xcor xcor - 6 + random-float 15
% k9 P' x1 T6 P% }set ycor ycor - 6 + random-float 15
# |. d; m" y2 n8 U' V3 Q4 }]
) M2 p" N4 e" t& e- iend3 }! _$ O/ K. J. U. R/ Z
to unit_plan
" ]8 F' D6 ~2 ?0 Vask turtles [9 X! q4 \% ?/ ?8 G3 y  b3 F3 [
if (remainder who 5 = 1) [set a who % j" f  ]7 c' X* L6 `
                          set x ( 0 - Wid / 2 ) 5 x) R' z5 E: w# U2 \: S
                          set y  Dep / 2 ]
# @8 v9 h& [1 \9 m# [1 ]8 v3 O/ i           set b  int (a / 5) * 5
7 R: b: l; Q9 z$ P& s    setxy ( xcor-of turtle b + x )
' \  a& p% ]7 [1 ?          ( ycor-of turtle b + y ), a3 d1 U- X! i8 T% |/ Y1 _
if (remainder who 5 = 2) [set c who: W- V8 A' Y7 }6 |
                          set x ( 0 - Wid / 2 )
. Q- ^9 I( e# M, y: v: c1 i' B                          set y (0 - Dep / 2 )  ]/ j) R: r) o7 P2 c! P, Y$ b
                          set d int (c / 5) * 5* T, [' m* S& S8 B% \! g
   setxy   ( xcor-of turtle d + x )
! X0 N2 e5 R4 g$ x* a           (ycor-of turtle d + y ) 5 L$ J6 O% c4 R; H0 R' z+ i3 d9 [
          7 x- z0 M, o  ]
            ! f  _  g. F5 x8 v! Z" x
if (remainder who 5 = 3) [set k who& _( F" O& V( w8 A) T6 ~
                          set x( Wid / 2)  ! T2 u  p! p; R6 e3 c; N  y
                          set y (0 - Dep / 2 ) ]' C$ a" q4 A# x: @4 I1 N# r
                          set f int (k / 5) * 56 m2 `/ x- e; M, s  X
  setxy   ( xcor-of turtle f + x )
5 X: b, ?$ W- _9 c# }           (ycor-of turtle f + y ) ; W( s3 j. D6 i5 N2 ?/ V
           : }# f! c4 q: S6 H# m0 X
           
; O" [" l% q$ ~0 S2 A2 |8 mif (remainder who 5 = 4) [set g who
  d, S- o3 u6 t$ W$ X# u6 N  V                          set x Wid / 2
7 p$ i' u9 s# ]: V- P                          set y  Dep / 2 ]* B- X* p& G: _
                          set h  int (g / 5) * 57 `- I3 N7 f: I4 e8 U# c  V
  setxy   ( xcor-of turtle h + x ). |8 D3 ^1 I0 G" v. k" V: [
           (ycor-of turtle h + y )
4 L( {1 c* U' q+ `                          % h( b( N9 c3 P
                          
5 H+ l4 ?1 F) Z# ?                          ]! U% C# K$ N2 j
end
$ i. N$ F' b1 c0 o: k2 W5 _# {) D
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,8 Z2 |& u, O: x! q
应该是
: k4 s& U4 B/ c! Gask turtles [7 K# s% O- s( R' U
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
' _( a: D4 I, W, j  g2 w; g                          set y  Dep / 2
/ L6 x7 O# M5 I9 ^* e6 @           set b  int (who / 5) * 5
' j( a& D9 k8 w! j9 ^' C! w* X9 Q    setxy ( xcor-of turtle b + x )
! a# i5 b7 i. f% Z" _6 J          ( ycor-of turtle b + y )]]
. L$ W( {# A+ Q! n% c- j% H- F( {2 k( v$ Vend
) |( M7 r# E2 ]1 h$ a- i, ~+ H" _之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-23 09:08 , Processed in 0.014638 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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