设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8337|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。5 y- C' R* ]2 w! [
( e' S$ o$ x; ~7 p% w4 p7 d5 o
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。! U9 D( W9 b& R+ I' m; C
4 s* @$ k9 Y  a( J4 M# h
turtles-own [a b c d k f g h
0 v3 y+ Y  j" C  T8 i* _$ i  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 4 ]! S8 ?" G' W* m
]
! V+ b3 d) j  K  L0 y) ]+ {; j& r1 |: Cto new% ?0 S, E' S5 B; m- ?. A
  ca- u; l- @6 h' A
  crt 5 * num_of_building
& _8 Z7 E3 L' E& }  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
& M6 l$ X+ R% V+ w% x5 t3 p  scatter     ;;keep center-turtle random positions
5 z0 X3 V% o3 j% f- k2 a2 Q  unit_plan   ;;make up the building plan0 k# _8 b6 V; b. F3 u- ]
end, y( v0 a# H1 D
to scatter7 u! R9 K* \; g0 h
ask turtles with [remainder who 5 = 0]
; `+ g; j2 B& M3 b! g- B[8 S# h! p( N4 |; e! s8 q
set xcor xcor - 6 + random-float 15
( Y" _& J9 \) d' i- Zset ycor ycor - 6 + random-float 15  J& J' [. q1 h3 e
]/ [- Z! z/ k: p
end
7 a  ~8 i# O, K/ P/ Lto unit_plan
) i. F( E2 u8 \* `6 ?+ vask turtles [; \* A4 d! r: Y7 L' v
if (remainder who 5 = 1) [set a who
1 Q2 _& q3 c0 n; H, E2 D2 H% T( d                          set x ( 0 - Wid / 2 )
+ C/ _# _$ Z/ T                          set y  Dep / 2 ]
3 h8 v+ P/ k3 m7 B           set b  int (a / 5) * 5  J' \4 _8 c% R/ L
    setxy ( xcor-of turtle b + x )
9 U" v; E0 V: L- R' X8 S) x9 Z          ( ycor-of turtle b + y )  i2 E4 k4 F  o# d
if (remainder who 5 = 2) [set c who
8 v, `0 a& w7 R, m                          set x ( 0 - Wid / 2 )
+ c6 p: V! O/ t& I( E5 h7 A8 x                          set y (0 - Dep / 2 )  ]2 h. R' D# E! K% ~$ f5 E1 W
                          set d int (c / 5) * 5
: u1 p# Y! k  }: Z* @0 k   setxy   ( xcor-of turtle d + x )
9 H3 c0 z9 W+ i4 E8 W0 c0 G           (ycor-of turtle d + y )
$ ^- ?& z. ?0 Q, p" K7 ~         
- u" v& c" g' s7 a( ~7 w* g            
$ y& y$ R/ g. C/ G0 _! a7 Rif (remainder who 5 = 3) [set k who
# g8 n+ W2 R4 [7 B* l, v# u                          set x( Wid / 2)  ; v" `) H" \6 b5 [0 L' f( o, V# v
                          set y (0 - Dep / 2 ) ]
9 O& p0 u# @3 N& X% X                          set f int (k / 5) * 5
: Y4 Q7 I# |4 C  j5 b* ~) ]  setxy   ( xcor-of turtle f + x )4 |* o2 f5 y& I6 o7 P& z+ H
           (ycor-of turtle f + y ) $ S; m4 W* _9 }- l; v/ o# c% J, O
           & C. `/ ]" j% y: q% f
           , [- O) h/ g* p7 p
if (remainder who 5 = 4) [set g who" B3 b4 Y( J8 Y; P( D: M* g6 e  o
                          set x Wid / 2
9 O& T  V+ n+ P5 [% g                          set y  Dep / 2 ]5 d5 l- g8 P- I8 k& v6 h
                          set h  int (g / 5) * 5
3 [, J& Z+ `* g- s' W" C  setxy   ( xcor-of turtle h + x )' I# [) w- x8 ]
           (ycor-of turtle h + y ) ) z; ^2 B$ H) e1 K' G3 `; }, T
                          - u* a& N" w4 L; t% q
                          
+ w6 @" Y) ^3 `+ L( l/ |. Z                          ]
9 a7 }0 ^$ ~' B* jend
( o2 b3 Q" D& Z
* ?9 B" y' p; Z) ]" I[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
7 c$ h1 @! v0 E! W$ g应该是
" t1 b; `1 N7 k- `+ ?) ?7 oask turtles [
" _* j0 o, u) Y! B. G3 D+ M5 M# ]if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 3 Q% I% s, @. B/ y1 Z4 D4 k3 T" d& F
                          set y  Dep / 2
1 G4 {2 v5 g# A  y5 T7 l' O           set b  int (who / 5) * 5
/ i5 ^7 V. Z  |% ]% ?$ T( |4 m4 L    setxy ( xcor-of turtle b + x )
% x: d8 l. G% Y; @          ( ycor-of turtle b + y )]]
, @6 U8 V1 [8 S2 ~- C  ?4 hend- M7 ?, H: G: \1 B
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-10 00:30 , Processed in 0.017658 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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