设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8276|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。" U+ X, q$ K3 T- ]7 L2 V( k" q8 j
5 C3 `! E* X' y. w
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
3 Y# k5 _6 b0 N0 [$ W- S6 X* Z! K6 P$ G* D7 ?, Q* j" ~
turtles-own [a b c d k f g h
0 t9 G* H' Z' C( L& W) x  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 2 t$ O* u0 k! V; h; X/ F0 S
]
+ P* l/ d. T1 e: P+ Vto new
9 n$ e6 Q5 P1 Y6 b2 d/ U4 S  ca
  w5 Q* T# j7 `* B2 {: R  crt 5 * num_of_building
+ _) q- T0 Q  _. ~8 \9 @! W1 \% k  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
- |: r2 `4 X! x/ m2 M& n  scatter     ;;keep center-turtle random positions
9 }/ _, m+ X: ]: B' d/ F- E  unit_plan   ;;make up the building plan0 S% \5 c1 q: b4 @
end2 I; t2 w1 l' q( Q2 @. h! \
to scatter! t# _3 G4 l, P3 o4 V/ e1 L
ask turtles with [remainder who 5 = 0]
; g! j& W* G# {6 T( h  d/ \[
8 g0 t0 Q( i+ M7 Z, K. D) cset xcor xcor - 6 + random-float 15* u9 ^: `2 G# `- ^
set ycor ycor - 6 + random-float 15
$ O' D' @4 _/ v3 e0 L+ N( c]: j% S) A$ }$ T) F
end, T# f- O( J* ?, P8 H3 p. [
to unit_plan
* Z, |5 C9 C6 ?  i3 Y. d; Iask turtles [  h  x$ T- v1 L+ J: H& S/ t
if (remainder who 5 = 1) [set a who 0 O' c3 ~5 x0 g: B" Y
                          set x ( 0 - Wid / 2 )
$ c# n0 i) k6 j7 |9 i( ?                          set y  Dep / 2 ]! y  q% k3 s" \% T+ M+ R# K* g( ]
           set b  int (a / 5) * 5
% Y' d2 E$ M& o' ?0 e6 P6 A- N    setxy ( xcor-of turtle b + x )
9 m9 c' y  b  P- y& r          ( ycor-of turtle b + y )7 Y  y- F& U+ ]8 U. O: m
if (remainder who 5 = 2) [set c who/ D. M' G. Z# a- m
                          set x ( 0 - Wid / 2 ) : A8 q0 z4 p: e6 y8 w
                          set y (0 - Dep / 2 )  ]5 m4 [4 p& ^" x2 f5 g. R, I
                          set d int (c / 5) * 5
9 V2 W; t& V- }+ x   setxy   ( xcor-of turtle d + x )
: d6 a) M1 H2 Z1 c5 }% A+ D- D7 a$ D           (ycor-of turtle d + y ) 7 L2 b% W1 W0 N9 I% p
          . S& C- m9 e/ e% U) w2 _
            
5 c" H2 w  z, S6 \" B6 ^0 ?# Aif (remainder who 5 = 3) [set k who3 k* F) b/ }* l: g& B
                          set x( Wid / 2)  
' s) @+ O" ^* u                          set y (0 - Dep / 2 ) ]5 S7 J& j" b- z, f! C& w
                          set f int (k / 5) * 5
0 p) \* ^: ?4 B8 b; R8 u! b2 Q  setxy   ( xcor-of turtle f + x )
4 g$ h$ S) k# Q           (ycor-of turtle f + y )
" T- z8 S& N1 Z$ \7 Q           
. v" N2 ]% ]+ b) U( Y1 L* e8 z           
9 F; u& ?9 G( q: hif (remainder who 5 = 4) [set g who
/ g: U) h0 d3 J2 u. ?) Q                          set x Wid / 2
3 U4 \# J3 ^# ]                          set y  Dep / 2 ]
* q2 {  Q1 d+ y7 @  U                          set h  int (g / 5) * 5
7 L$ I, y6 V6 E; o% e7 ~- |6 T  setxy   ( xcor-of turtle h + x )0 z/ f& L9 f, Y6 h- O) W1 @
           (ycor-of turtle h + y )
+ b. H7 Q  x: H                          ; P6 V- x6 n; G5 `5 k0 b' m
                          
1 @& Y$ [* ]! S                          ]
: Z- Z( b) t& A5 z& c8 m% Nend
: ^1 G2 e) }/ t4 b; n* j8 |( D' ]8 w. k8 I4 O1 u
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,4 W% N4 M6 t# `1 |; Z
应该是% B& P/ n4 ?8 O' u4 h1 B
ask turtles [7 X% W+ f7 s9 d6 e. |$ s. }
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) % P8 F: L) h: G/ X3 D
                          set y  Dep / 2
* G) X2 E2 l; n) H8 e           set b  int (who / 5) * 5
+ k$ L9 P$ d' A0 C& U    setxy ( xcor-of turtle b + x )
5 h/ t# [" O2 o5 }          ( ycor-of turtle b + y )]]
* D3 Y$ J8 j4 R9 \# k' L2 Xend( i1 J4 s3 w2 `7 [0 M
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-28 15:12 , Processed in 0.018908 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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