设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7069|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。* B) m3 m- [! w3 R  X+ C( B9 N
/ w2 ?! s3 J/ }" |0 v- H
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
2 K  P/ [$ q3 Z8 D# a2 O7 C6 r: w; U: O$ A9 Y( K& k
turtles-own [a b c d k f g h
! v1 f8 w& X+ x1 R' F% E% Q  Z' o  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ; d* g1 {" l0 z" J' B% h) [
]5 M! a- O7 I% q9 _, f) F1 F% e" R  e
to new
  Z% A4 X* I4 Q6 c! b  ca: c! A1 ~7 w2 t9 `
  crt 5 * num_of_building
) I! G* g  g! T. i1 l: x) l7 S# q  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
7 P9 m& k% t2 D" F6 I7 L  scatter     ;;keep center-turtle random positions
- v0 z, B7 m/ k, y6 v0 z. \  unit_plan   ;;make up the building plan
# W' T/ u3 B& c# eend
" e+ A& K  R) w: q% r( {4 R# _to scatter/ O$ J. V" j+ [, Y' e
ask turtles with [remainder who 5 = 0]( D5 t1 H+ U8 i' M9 e  l3 u
[$ z8 k1 D$ h% O+ N3 H6 C* _7 E6 f8 q
set xcor xcor - 6 + random-float 15+ O$ U: d; w6 `* m8 F! ]
set ycor ycor - 6 + random-float 15
" l5 _. {7 {& U& N]2 A. x/ U5 d; x
end
; q: |7 f; n( T, kto unit_plan
. x+ t5 G" O; c3 k5 b$ r- cask turtles [
2 Y% R7 V% B& e  D  x* e" jif (remainder who 5 = 1) [set a who
3 Q0 p- p/ m/ t  F                          set x ( 0 - Wid / 2 ) 4 \# e/ f- y& y$ J9 n3 z, X" M
                          set y  Dep / 2 ]
1 \+ x* Q6 O/ b' E2 b# E- U5 }2 L- N           set b  int (a / 5) * 5
5 ?: g9 ~2 S& d/ C2 U# Y    setxy ( xcor-of turtle b + x )" c6 P3 c3 }! d" G
          ( ycor-of turtle b + y )
! ]0 i: x2 x' i' |if (remainder who 5 = 2) [set c who
  b) K% u" ^* ~: d; N                          set x ( 0 - Wid / 2 )
; u6 [8 C7 h/ I. ^8 Z( J; x                          set y (0 - Dep / 2 )  ]
; R* M; b  E' @; i6 a1 V! t                          set d int (c / 5) * 5% K9 e% [; t! b" _4 p
   setxy   ( xcor-of turtle d + x )
5 q! o, _  e& Q           (ycor-of turtle d + y )
6 B1 M$ r0 Q, F1 T& r- i* _          # a" R+ R0 Z( r5 E' S% z2 P
            
* V9 |- _3 G6 Wif (remainder who 5 = 3) [set k who
4 i: I6 V# Y# k& t                          set x( Wid / 2)  
0 ?9 h  P8 F, ^) n2 S, p+ F, b                          set y (0 - Dep / 2 ) ]
/ E3 \, V- X% P5 p( p- k1 I                          set f int (k / 5) * 5
* @5 e0 e7 L* Z: X/ v  setxy   ( xcor-of turtle f + x )7 @8 t, @: o0 k/ G% i
           (ycor-of turtle f + y )
8 b$ C6 c0 w9 y, }9 q3 c- d9 c- {           
$ S# h2 ?  l6 m$ f' v2 c  d. A9 S" b             E$ Y$ g- p% g, p: m
if (remainder who 5 = 4) [set g who5 `& ~8 S# W  t- R0 A, o& E
                          set x Wid / 2
' L2 S9 j' r) D) B$ a                          set y  Dep / 2 ]
5 B2 G9 C( y* R1 _6 q5 Y. R                          set h  int (g / 5) * 59 P$ W* [9 ^( |( S7 m+ k1 \6 {
  setxy   ( xcor-of turtle h + x )8 q8 H% Y6 ]' X3 j% L
           (ycor-of turtle h + y )
" S% O; g$ `1 I  r4 E  b' L                          
* V- C* Z2 w0 i7 R% P* `6 z                          % G: h# Z! T$ w5 ]$ q7 W+ O  j% c
                          ]
' ?  F) J5 G5 e5 oend
! d$ I6 s3 [" u
. r1 N; I  U6 }7 L+ _[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,( i( C" u1 W+ R  @2 k; J
应该是
) p: \8 Z  x* y7 H  `5 Iask turtles [
. O' S5 K: t0 B: s* k& eif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
( O" O3 k1 I4 B6 W8 b( m                          set y  Dep / 2 9 k: B! t, Z( y* W5 W. k0 Q
           set b  int (who / 5) * 5  ^0 h) s: ]; Y+ r- y
    setxy ( xcor-of turtle b + x )
0 L* M9 P  I$ [3 b; U/ E          ( ycor-of turtle b + y )]]
  v& P" z& @* a, Y  o* |end
1 j# ?/ E* H( R( c之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-25 11:23 , Processed in 0.015981 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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