设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9096|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
3 y  S( Z* e: P0 e( t( \2 k% T/ x8 D# L. f5 d" m2 w
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。% G' ]1 {. x0 L, I2 c* c
, Y. S# x$ r8 @. _. w5 v
turtles-own [a b c d k f g h! u/ l: n, P. i6 H4 R; {
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ' C7 w# M' M8 g- B/ ~; W5 y: e' D
]
# z6 W4 m$ f( a4 [0 A& kto new
/ U3 l* m" u$ s  U  ?1 o  ca
. Z! A0 A  {8 u* w  Y  `  crt 5 * num_of_building8 I* r4 H1 `* l# {
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]  R6 o0 Z6 r* r8 s& t- h! W; d& X
  scatter     ;;keep center-turtle random positions % v& p) Q. P1 M* S0 U6 e
  unit_plan   ;;make up the building plan
1 d: |- Q2 A) [( aend
0 d# z- C! d6 w+ _to scatter8 r" |! {8 N3 O5 w1 {$ F+ u
ask turtles with [remainder who 5 = 0]
! R8 U+ D$ H! t3 y8 i[4 t0 M2 b1 G1 f+ F4 J9 M
set xcor xcor - 6 + random-float 15
1 B7 v. Z3 y1 j% y8 d% Oset ycor ycor - 6 + random-float 15
/ P. F- B0 B6 f1 v- I]
  I- @) j1 L* l! O1 eend8 Y) {' a2 d+ P& O# Y
to unit_plan
% g3 b; s% e" B  X) o$ xask turtles [
3 V+ D0 u) `( O/ O: A! h2 h" kif (remainder who 5 = 1) [set a who
; m& F. e) O: I                          set x ( 0 - Wid / 2 )
7 ?0 k$ b3 I* \$ f2 Q                          set y  Dep / 2 ]) p; J, F' D2 x" r
           set b  int (a / 5) * 5
2 Q5 Y6 z' w4 k, E, V9 i, L7 S# s    setxy ( xcor-of turtle b + x )( H, j+ Q3 H3 x7 l4 N
          ( ycor-of turtle b + y )4 O; ~/ m; b: H1 K( R
if (remainder who 5 = 2) [set c who6 r8 L- E/ D- n1 p0 ~- o1 n
                          set x ( 0 - Wid / 2 )
5 g& Z; W& @: h+ k5 ?9 z                          set y (0 - Dep / 2 )  ]
4 ~/ ]# O- R- _# O  u( A3 D                          set d int (c / 5) * 5
$ f, c4 m, r' d" }1 u( q* p   setxy   ( xcor-of turtle d + x )
# Q! r' o" o4 U( I" S! x4 d           (ycor-of turtle d + y ) 8 M; _& N8 A$ w  |$ J1 V2 m4 y
          ) V* f; I# ]0 a! [- V' w
            - ?( P+ P. X4 z4 \3 T1 w
if (remainder who 5 = 3) [set k who
2 J2 {% V1 `- H$ H* C, ?                          set x( Wid / 2)  & j) Q! j' s. t. L% K- v' S
                          set y (0 - Dep / 2 ) ]
8 R3 ~$ K$ e# W9 x1 T                          set f int (k / 5) * 5
3 R7 [4 W1 o! V" b  setxy   ( xcor-of turtle f + x )
- k. e, j5 G$ t( w* h           (ycor-of turtle f + y )
6 w! N  h4 D3 L, X" `- x8 R8 D% I9 l: p           3 |, D1 V  E7 X3 k5 a0 K( r6 {' w
           
) O3 c5 L- H6 O$ ]if (remainder who 5 = 4) [set g who' ?3 C+ z: ~# t
                          set x Wid / 2   k; f! T( y6 G* O, C
                          set y  Dep / 2 ], p% }8 \: x- N; l6 [
                          set h  int (g / 5) * 5) J2 ?5 M7 D3 Z! c' j. o, L0 s1 @
  setxy   ( xcor-of turtle h + x )
$ |" Z0 a3 d5 [+ I/ z2 P& J           (ycor-of turtle h + y )
/ Q5 k% x1 l0 b                          
: _* i, F4 j  m+ U                          1 O. G& j* J  o7 B
                          ]9 d# r; f) m, r8 X
end
. j  z6 h* `' A. r8 D- u) h& l; ?* {# V. c4 K8 S8 o# R
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
8 Q% H2 U" S, s7 [应该是
& {' u8 k- ^% d' e( A7 j& kask turtles [, l( h; F$ ]& e# v. Y
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
" [5 g+ b/ H8 C5 y$ z/ F7 b) I! R                          set y  Dep / 2
. p+ p3 R9 P5 a8 Q0 V: T; ~           set b  int (who / 5) * 55 M8 {' y$ U/ ]0 Z8 G* d4 M# N0 E
    setxy ( xcor-of turtle b + x )+ W" m$ R  B) k% m
          ( ycor-of turtle b + y )]]
" E! x4 i. G* pend
" I, ?3 e- c$ R6 J) Q1 ]. J# t之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-17 15:00 , Processed in 0.018033 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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