设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7179|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
; D0 w1 R& r- W7 p' S" L. ?5 Q- P, j1 T  r) w7 A. T8 C
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。% n3 F+ b, D: m+ X

8 b- P1 ]7 X% W2 |+ x4 sturtles-own [a b c d k f g h
- [, R" [$ O; h/ \' N7 M  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 5 B/ z" a' o- A4 N3 Q+ b
]
! s! p! g3 R0 {1 {to new
) _) U( J9 ]' \4 O  ca
$ p0 e/ Z0 @  d# q! a  crt 5 * num_of_building3 a! ~6 L  U5 l, w1 h/ w
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
% n6 m4 V2 P2 B# ^' q& A; e  scatter     ;;keep center-turtle random positions " v9 y  a1 w0 O5 `& ^
  unit_plan   ;;make up the building plan
6 j4 _/ L8 Y+ X* A- b' q; Gend
2 s. X% |6 r- [5 A5 A  I4 Tto scatter. _9 f; X# a  I& K3 R8 U4 |  d
ask turtles with [remainder who 5 = 0]" P; l: n# u9 q" }
[
7 m( x& C# \; |0 t' s* D, {set xcor xcor - 6 + random-float 15* V3 l4 `" y+ {& I
set ycor ycor - 6 + random-float 15
5 P# a( A% f+ a8 T. {1 l" ]3 `6 Q$ f]5 K& q& N3 b/ D. J9 i% b
end& j' A7 o" `2 S2 e: v" k- ]* }
to unit_plan . Q7 ^+ w, D. c) ^) Q7 |# C& w4 R
ask turtles [( ^' U! }/ G# I; Z% H; i, x5 V6 @
if (remainder who 5 = 1) [set a who
6 c0 |* ~5 N8 J$ U7 s; b  G/ w8 d                          set x ( 0 - Wid / 2 )
5 A4 G6 V7 c) Q3 U, W2 }/ r                          set y  Dep / 2 ]1 j. I( m, r0 F' Q. L" k9 i
           set b  int (a / 5) * 56 P  k6 s2 y; k7 a1 Z0 H& ~
    setxy ( xcor-of turtle b + x )2 k  u9 n* j4 n% G5 w# D+ @7 i
          ( ycor-of turtle b + y )4 O9 }+ ?- o' E8 S2 i9 d9 C
if (remainder who 5 = 2) [set c who
. \4 e3 d; J' K4 O/ o# z) t2 \- }                          set x ( 0 - Wid / 2 )
* ^) \8 V1 B: M: z0 i                          set y (0 - Dep / 2 )  ]
- f# j! ?# q4 o8 O- E: p                          set d int (c / 5) * 5
# E/ Z5 Z+ c6 J1 @. A: d   setxy   ( xcor-of turtle d + x )/ D/ G& V/ @7 Y; M( d
           (ycor-of turtle d + y )   C9 `* D/ p2 [0 Z5 H7 I
          $ V' j9 |. P  k# D# u
            / s6 z& H3 T, t6 \; w/ W2 l
if (remainder who 5 = 3) [set k who* o: z9 q1 z9 _' K1 F, c* f
                          set x( Wid / 2)  ( f# E1 e7 Y/ G; N
                          set y (0 - Dep / 2 ) ]
5 u# X  V0 |, W1 Z% [2 N                          set f int (k / 5) * 5) s! y: m4 p4 c$ i) U6 p& F' L# q
  setxy   ( xcor-of turtle f + x )7 v" r! e0 \6 |# [8 v6 s8 }/ c4 p
           (ycor-of turtle f + y )
( C$ K$ O7 }) D! p" G           
% l  G3 o1 ?7 M* K: e- `6 N/ l           - A8 d7 [/ u3 d$ D  A
if (remainder who 5 = 4) [set g who  a: T1 g$ I( k8 g  ^4 j4 t
                          set x Wid / 2 5 J* r$ k2 Z1 x5 X
                          set y  Dep / 2 ]5 g9 Q7 ]7 }4 P3 m
                          set h  int (g / 5) * 5! J. e9 K% l+ h5 X
  setxy   ( xcor-of turtle h + x )0 a  v' D1 L7 K# i0 J! f/ N
           (ycor-of turtle h + y )
4 M1 Q1 Q# F6 s/ t                          
3 K, J2 b+ r* s                          2 R% |& Z+ W3 c/ d' |! k
                          ]
6 p1 n( e) `1 a8 X) Xend2 [- h$ E& A* S1 h* [

8 ~- U+ Z2 N; ]. C% v/ F  Y6 @[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,- n9 z  e! l: H* `* p/ F$ f
应该是
! G) W% [7 n, E2 ~0 Rask turtles [
  y  E4 [" J5 N8 @% G/ q0 I9 ?if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 0 M+ m# I* C# n3 O: l5 Y. I/ {' M3 }
                          set y  Dep / 2
0 A1 i1 p1 I* X$ \  z6 `           set b  int (who / 5) * 5
9 \. a- @: Q4 u- a2 U; q* A5 b5 w    setxy ( xcor-of turtle b + x )
2 p) c5 j/ Y4 k0 c, @, ~          ( ycor-of turtle b + y )]]
2 z  J/ O4 {. |: {4 k3 B& Eend8 ~0 {3 p1 F# ?: o0 `
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-14 03:15 , Processed in 0.019034 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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