设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8076|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
3 C4 b6 c/ l$ r9 F$ ]  F- J0 U& b
6 k/ P' |( x. @) b但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。2 v+ d( d6 O! a4 r$ }$ J& A3 X3 @
- h7 ~/ ~; ]+ \& }
turtles-own [a b c d k f g h8 l6 h3 o7 Q6 O) w( @
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 1 _% t* g* m: r5 |
]
. ?& N2 i4 E5 @to new- a) ?+ P9 o: H7 z- [
  ca
: h& o+ o8 P' a, P: }+ E  crt 5 * num_of_building1 i3 T! S9 J: E. }) @4 R
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]* S- V* v9 n% y5 R9 R% X
  scatter     ;;keep center-turtle random positions
% K% G0 J1 Y8 L% n1 X$ V  unit_plan   ;;make up the building plan
4 l" r; X" D5 R3 k& s1 o! P6 r+ Send
. ~0 A/ B( t0 t3 S6 {4 @5 Bto scatter3 e7 N- r" i( k" v
ask turtles with [remainder who 5 = 0]
/ j  y% I8 T& u" F0 d' x2 a[
. I/ C/ t0 h6 m: y* F1 ~set xcor xcor - 6 + random-float 15/ |0 h  B5 s7 G
set ycor ycor - 6 + random-float 15
8 J, h/ ?4 a$ B  ]& `]
7 B8 Q1 Z6 G# xend$ Z. P. i- H5 K
to unit_plan
9 w" c: Q! L2 M" V* ~3 pask turtles [
! ]1 \% s+ s! [- T# W3 Uif (remainder who 5 = 1) [set a who
; \' o) D" b7 X* D                          set x ( 0 - Wid / 2 )
. r7 V2 o5 [2 E3 d% V+ \                          set y  Dep / 2 ], J, U" O! |$ y* J
           set b  int (a / 5) * 5
5 j5 T1 g( h8 Q1 [    setxy ( xcor-of turtle b + x )2 |& C8 U  ~( c, N+ G3 Z% |' x
          ( ycor-of turtle b + y )0 f: ~& z/ F3 t1 F0 i, h/ w: Q1 H
if (remainder who 5 = 2) [set c who
! j# y( X1 A9 Q3 d8 X3 k# I3 P                          set x ( 0 - Wid / 2 )
) G! v7 g( s$ K6 S; i- e& B; [                          set y (0 - Dep / 2 )  ]
+ p7 }. X, O+ O" T; x  R" T                          set d int (c / 5) * 5
. `% f: \6 W! y) r4 w9 L+ B   setxy   ( xcor-of turtle d + x )
# `1 P$ a1 W5 ]" s& k- z5 B- \           (ycor-of turtle d + y )
: }' S% R7 Z; d8 }4 a/ g9 o) p8 u            N# h" A2 e& _' D
            
5 d- Y9 x5 p! k/ W3 n/ [if (remainder who 5 = 3) [set k who( O" E/ F' H. c, x$ L) v
                          set x( Wid / 2)  
. l! q  b1 l* Z- A- R, F                          set y (0 - Dep / 2 ) ]$ d0 {5 W, A1 v7 [4 P  c
                          set f int (k / 5) * 5. [8 k; @, B& g$ p) s
  setxy   ( xcor-of turtle f + x )$ @9 c! U1 N% d  f/ c
           (ycor-of turtle f + y ) 2 _: T3 K# r& m( {* t" u3 V: N
           
8 {) X5 ~! N9 s' Y7 V: I           
/ U$ f( d* X5 U7 X* J- b; oif (remainder who 5 = 4) [set g who
1 x+ N' [6 z6 ~) Z" P                          set x Wid / 2 0 m* Q5 Y0 p9 M; ^- c- R, C! ^( m
                          set y  Dep / 2 ]4 I! ~8 L1 \2 M. q) ~7 Q# \. D
                          set h  int (g / 5) * 5
9 N8 D2 y: X; K# @6 `+ S  setxy   ( xcor-of turtle h + x )
& L  F" |/ B: V) P, ?& |           (ycor-of turtle h + y ) 8 k& K+ o, q5 v$ I
                          
# i5 x! l! ^9 n3 Z                          ' h2 G$ H+ H& d/ M9 Y# S6 q
                          ]
  O: C% g, h5 c% m+ oend5 q+ K+ ?7 m% c: a! c* q
* f# i( m  l' k, Y
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,3 U% o' z" s7 t7 u! M
应该是
1 N1 g+ T- c2 {( U% Iask turtles [
6 U; n* b. E3 d: ~; k( h  r  lif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 8 m2 ^" Y% x! B% J7 X
                          set y  Dep / 2 + y2 i- J5 @6 e: h- s
           set b  int (who / 5) * 5. V. f: C3 V) w5 h% h
    setxy ( xcor-of turtle b + x )
' V# `  Z. M2 H1 g! Y1 L. E          ( ycor-of turtle b + y )]]
: ?. l# i. g: j; P7 r: x7 f+ xend$ Q8 a% w  i  Z' \
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-4 13:25 , Processed in 0.015620 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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