设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8010|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
- e0 D* s8 _8 G4 n( c5 B0 s, c; W" t8 r( P, ]# P( }& b. C
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。% Y+ s+ V, C! t
; ]9 H( q9 `4 H, C
turtles-own [a b c d k f g h
8 T. ?& A$ d  _5 q; K$ Y: s; f; y  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 3 t/ o) Z; f$ u+ d; r& P7 i( ~
]/ B. s/ x) C' U+ \3 E# a6 ?- ?7 T% P/ d, r
to new8 V% ~; o" x$ k3 i
  ca
. t. P2 r. c0 s' b' F8 r  crt 5 * num_of_building3 }* v- N8 r' N' J6 x
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]7 |. H- P4 \9 x3 F" {) \
  scatter     ;;keep center-turtle random positions
) a  V/ P4 j" \  unit_plan   ;;make up the building plan+ L  s7 w8 Q* X$ [# C
end
7 Y  M( z( @! p7 Yto scatter
! {% i; p; _' N* H6 n, [ask turtles with [remainder who 5 = 0]. M# I; @/ h3 \
[
3 w* O7 z% z5 J* k, P8 v; e0 wset xcor xcor - 6 + random-float 15( _- |9 \$ ^  F. J3 G" d5 @
set ycor ycor - 6 + random-float 15
2 J- }4 z0 ^9 n% U. O2 V]
9 K+ x9 z* v7 |2 Z6 send
/ L' q0 k6 U2 B5 l7 F" ~# ]to unit_plan
8 y. \- L0 t* K+ q4 `$ m. Y9 Mask turtles [
2 ?4 R1 c2 W6 |! C3 d! H) [/ pif (remainder who 5 = 1) [set a who 4 U, L3 t- j  M9 V: f* P& i
                          set x ( 0 - Wid / 2 )
& ^, b; Q( I/ q: A/ P! n                          set y  Dep / 2 ]- Y# w" F  U' R" R' `3 K! E
           set b  int (a / 5) * 5
" a1 j8 p5 Q) i$ w* F5 ]! x    setxy ( xcor-of turtle b + x )
& ~2 R4 h, A& [" D, G          ( ycor-of turtle b + y ), v' x, x" X% V; }
if (remainder who 5 = 2) [set c who0 J+ F! n1 c; F1 E, y
                          set x ( 0 - Wid / 2 ) 9 j: e- `. c7 U0 d, a& m
                          set y (0 - Dep / 2 )  ]' r3 f4 U& b, R0 r* l" h
                          set d int (c / 5) * 5
# l; c+ y) G+ o( p# r   setxy   ( xcor-of turtle d + x )
( Z! K- H% E: J, {+ q           (ycor-of turtle d + y )
8 F3 |8 Q! |+ E; }2 e: }/ T          ' J0 z4 F5 F0 R* E
            
1 L- h; E9 l/ f  H! r0 n9 dif (remainder who 5 = 3) [set k who
" |8 |, V, V2 d' j* U                          set x( Wid / 2)  
( \5 N3 e1 p( r0 L* w- Y                          set y (0 - Dep / 2 ) ]
8 s" b* A( b3 Q- [6 V* m                          set f int (k / 5) * 5, G' X8 M$ W8 M
  setxy   ( xcor-of turtle f + x )
, A+ r+ }: j" e) c  c7 g           (ycor-of turtle f + y ) / _  o* E( v' c, C# B4 ^% Z9 [
           ) V. f& n3 y3 w. \
           
8 Z3 G+ k8 q5 Z% b0 {if (remainder who 5 = 4) [set g who4 z7 M4 l, H4 K/ O
                          set x Wid / 2
( ?0 B2 b2 g' x; D0 @& z* i' e7 p                          set y  Dep / 2 ]* J  p  U: X  a4 L0 ^) }
                          set h  int (g / 5) * 5& Q6 n1 Q- v  ?( ]1 [
  setxy   ( xcor-of turtle h + x )
, \) l2 _8 C+ G( e0 i           (ycor-of turtle h + y )
3 ^+ l% {) [* C- F# d% v' S- }                          
/ ^& V. V  H; h2 N: G0 {                            j% ?% P7 P2 x) r" c; Q; C( B
                          ], ?' d9 Q; \  K# u- A$ f0 r
end8 m' G2 q7 o/ |6 N" e
6 s( h( U4 |/ t6 L0 S
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,4 ]6 i0 X# L( Y' w" S% w! L
应该是
/ M4 e, I8 O8 s- x; {: {' E/ m1 lask turtles [
- A, O( q9 s0 T# K+ Y" B4 E2 Y- zif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )   P3 d; ~/ _2 M* Y0 j
                          set y  Dep / 2
7 S$ j) a) |$ m7 V. _  r& i5 W           set b  int (who / 5) * 5' ^# H+ N' W3 A: w. ^) e
    setxy ( xcor-of turtle b + x )
2 t4 S3 O5 X; g9 ^4 v. K6 A          ( ycor-of turtle b + y )]]
8 M! C% }! K4 A8 z1 T" {end, a+ t" e: y: r8 v
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-28 13:05 , Processed in 0.017047 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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