设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7995|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。. X; n4 U. q8 \! ?7 F7 f
' d) @7 n! o! W; {
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。9 Q- [% p1 r& _  u& O& W

1 k) U. y2 T) H: S4 _turtles-own [a b c d k f g h$ F8 {& b6 m! {
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
, R3 H, e! s& M: A+ q7 C]8 z+ ?' V* [) p4 J8 R
to new4 K6 o( f) C5 B: x5 X! ~
  ca
8 l* V! {2 A, T4 H* t+ M9 @* H  crt 5 * num_of_building
" h8 x  p0 F! Y7 t2 V9 J; v( f  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]9 n  }2 x$ k( v# l6 ]
  scatter     ;;keep center-turtle random positions
5 Q/ C: a: v8 n  unit_plan   ;;make up the building plan" B+ ]( H# R0 T- f
end
& p6 O  i3 A; e/ Zto scatter
) G% Q1 f/ Y7 B9 T# h- jask turtles with [remainder who 5 = 0]0 S6 [, K# A7 r5 g' S
[! j3 p& o6 x6 c. C0 T( j; }- R" r
set xcor xcor - 6 + random-float 15& ~9 T) s. q" K8 e$ i
set ycor ycor - 6 + random-float 154 N6 ^6 }! f- m5 V' @- l8 N
]
/ _: g  ]4 B3 X# ?3 Xend0 C/ t4 C7 l0 F7 p
to unit_plan - ^' ^, u! r* n3 p7 u, e0 v/ Y+ F
ask turtles [
9 d( f$ Z. n" _, V( Aif (remainder who 5 = 1) [set a who . }- C  j4 y! h2 ?& _: L
                          set x ( 0 - Wid / 2 )
% m1 f3 N! a/ @* q                          set y  Dep / 2 ]& }/ q* e9 ~% x+ \# _$ V+ J( K1 a
           set b  int (a / 5) * 5
; _; s! ~7 l: S  S0 Q5 N1 ]* ^! i    setxy ( xcor-of turtle b + x )
+ I0 f7 a6 k0 a8 {0 y( c          ( ycor-of turtle b + y )
! E* W' k  X! [2 X. iif (remainder who 5 = 2) [set c who& X- ?) x1 j. ]/ J
                          set x ( 0 - Wid / 2 )
3 a$ [# L# i' ^- E  q" e% L6 B                          set y (0 - Dep / 2 )  ]
' I3 u4 v) F8 H/ Y! W                          set d int (c / 5) * 55 _8 }8 N( R2 l1 E9 [6 n4 c
   setxy   ( xcor-of turtle d + x )
* g+ j5 d1 \* k# L$ d: N: z+ n* d           (ycor-of turtle d + y )
6 p9 P$ i- j* C4 s2 S& e         
; D: n+ O9 g2 q( N( z( `9 Q& s            5 }8 ]7 k+ V* @: ^! I
if (remainder who 5 = 3) [set k who5 {; ?7 \3 R( ?  f0 G! P
                          set x( Wid / 2)  $ c7 ~  C5 j9 I) c; e* n6 u) Q# C- E1 b' g
                          set y (0 - Dep / 2 ) ]: Y5 {4 Y: ^0 K3 |
                          set f int (k / 5) * 5
) ]3 N: ^5 {( q+ z1 r/ W  setxy   ( xcor-of turtle f + x )
4 o; @; J  c! o4 O) \# B% U           (ycor-of turtle f + y )
. ^4 R; ?$ K( R           
9 T& _( B9 d" ?" P           9 Y9 {% [" C) G) P7 o' E
if (remainder who 5 = 4) [set g who, N, E* c: u% f# d" B
                          set x Wid / 2 % b% t) v+ g3 B. j
                          set y  Dep / 2 ]
: W0 {1 N2 y+ x. ]                          set h  int (g / 5) * 5
8 o: f0 G: t3 A' r  setxy   ( xcor-of turtle h + x )$ T$ P4 n( H5 }& m" t; d$ y
           (ycor-of turtle h + y ) 9 e7 L  ^0 M) w, E/ N, l+ p
                          
* \% O2 R$ q8 q* P                          
2 a* U: d9 |5 b& G5 G% h$ c                          ]
  L+ O9 x  ~1 V* s7 @1 o3 ^end
( |/ o4 O4 F2 x* @. v# g6 m4 B! {' |
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,; n3 E) R" W" W; D' M. F' A% e7 n, I
应该是2 z" \. C! l' C$ M
ask turtles [
) S6 f; X9 l& @if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) " |2 z5 H8 u, G' p8 |" P
                          set y  Dep / 2 2 d, N# i! W- x9 j- J9 m4 x6 T* R: ]
           set b  int (who / 5) * 5
; ~, c" t2 x4 p    setxy ( xcor-of turtle b + x )
7 G) t  E! m' X          ( ycor-of turtle b + y )]]
- X2 ?  K) K" [  y4 ^end8 b) U3 X2 d) s7 @8 {0 m/ S- D! |
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-26 16:51 , Processed in 0.015756 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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