设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8167|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。4 j( p! I( T6 R5 ~; [, i( a4 f8 |

$ w3 e1 T" ^8 W但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
- d8 b# ^) o) }" G4 t$ f, K( z1 E9 R
turtles-own [a b c d k f g h
( [: J' ]9 C7 r. O0 F* x! f  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
3 O" v# B6 o4 @# W9 M! x+ Z: i]" _, e9 X. z6 S' ?+ K
to new7 F% k, _1 Q" I3 H
  ca
* }( h( p9 v. T& O4 |9 }  crt 5 * num_of_building; h  |& E) G2 q2 h
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
/ }) H. s0 e. |8 y' g5 g  scatter     ;;keep center-turtle random positions
5 v" v9 D+ f/ u! `! y  unit_plan   ;;make up the building plan  @5 t! `+ U. v& Y3 x, x
end
) r+ ]4 J& z) L) a. Tto scatter
1 H9 [7 U1 ]+ `ask turtles with [remainder who 5 = 0]3 E, v) j! }2 L
[. W8 }* V: v  Q$ n5 r( i' ^
set xcor xcor - 6 + random-float 159 z0 @1 n' q, {3 I. J8 D9 q
set ycor ycor - 6 + random-float 153 E7 A& b! b& b5 `8 }& }
]/ F- P+ o& Q, Z% D7 s) t/ i
end+ s4 _, D# \- W# A/ X- K* [
to unit_plan ' x* C# k( s7 Q" }; f
ask turtles [" m) [* u/ U* d
if (remainder who 5 = 1) [set a who
9 O" C5 ~- _1 `- ~( G                          set x ( 0 - Wid / 2 ) ' [* i) G' [3 }& z% b; r5 w* B6 W% k
                          set y  Dep / 2 ]" o( W& K% V. c! s8 x( q
           set b  int (a / 5) * 5
$ g9 o% F7 ?$ W! Q6 |) I    setxy ( xcor-of turtle b + x )5 |! l# r) Z1 G1 O/ g
          ( ycor-of turtle b + y )
2 c; g# F: P5 Q4 Z+ _5 f1 E% _3 o( q; Qif (remainder who 5 = 2) [set c who
2 f" J1 g' s7 u                          set x ( 0 - Wid / 2 ) 8 F4 X' O# N' Y
                          set y (0 - Dep / 2 )  ]6 @7 ~. B3 X9 c: q3 T9 j8 \
                          set d int (c / 5) * 5
. `5 Q1 k2 r/ T" H# P   setxy   ( xcor-of turtle d + x )
# h& O: n$ J* t! m$ X: j* @, O4 c& p           (ycor-of turtle d + y )
! B* N8 G; m/ p         
, }  u0 w  S' a% }            
6 X0 Z6 \, f+ }, W" f9 I3 t+ d8 P" Aif (remainder who 5 = 3) [set k who3 j  \: e: e! Z- g" D: t
                          set x( Wid / 2)  8 u. x1 e) M) [( q3 j
                          set y (0 - Dep / 2 ) ]
9 u* `4 b  ]6 |* A) R                          set f int (k / 5) * 5% C, X" ~+ J! |% i) \
  setxy   ( xcor-of turtle f + x )# v; ]  G% r; h6 c6 ^7 ^7 A' H
           (ycor-of turtle f + y ) ' b% w6 ~6 e+ T5 ]* o/ O
             \: |7 s. i3 a# m" s% a
           
  n# u& Q, R! m8 R3 i* L7 @if (remainder who 5 = 4) [set g who
, s% Y% x6 J- n. A) o                          set x Wid / 2 6 }( j+ A) p# O
                          set y  Dep / 2 ]. b; z0 M9 [% C& Z3 w9 ^
                          set h  int (g / 5) * 5
1 S  ^( W' e9 y8 b/ \# F4 h  setxy   ( xcor-of turtle h + x )
7 [3 z3 Q  g4 V  G1 _  U& i; o           (ycor-of turtle h + y )
- p' i' h5 q1 M* [5 H" v5 b                          
3 y) M) X9 l5 h4 o                          6 K! f9 [7 `9 z& Y' C& x( d
                          ]
- S4 e$ }" |2 T, u6 wend
% k: h! y, z/ ~$ x) F2 `, K1 E' _$ l  }! W# s: Z7 I$ y
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,0 P7 \5 C+ h" M$ {3 Q
应该是& L! Q9 Z$ s) T8 [/ Q, l
ask turtles [" \" ]; P2 g: _4 C' [9 i
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) $ w; d' ~% T0 U$ B' |  ^
                          set y  Dep / 2 6 Y' c% r6 _8 J+ }7 g3 I' O
           set b  int (who / 5) * 5! [1 G9 Z0 M; ^7 P! {$ d6 s  m
    setxy ( xcor-of turtle b + x )) u5 c2 G2 {& P4 k8 p) ^7 b( _. D  K5 \
          ( ycor-of turtle b + y )]]
0 {) V+ x+ J" k' p0 bend
, A( [6 d5 C$ C, X! f之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-14 05:05 , Processed in 0.029914 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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