设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7984|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
9 b; h1 }) u5 ]4 V$ |- i
, o" t2 w' k1 ~$ w6 W; a0 v2 }但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。) T7 a+ c- J% A+ n. i4 Y/ P
* L6 N4 q3 s, W% `5 a* ?( _% U7 i
turtles-own [a b c d k f g h: f  H9 D; x1 A3 U6 K+ C
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
! ^: s+ r0 o( t" k]) x1 r9 i% F) W" G
to new
* J# Z' Y/ D( o/ B: w  ca
) m* i3 s. r" Z- E. U  crt 5 * num_of_building
& k: D7 s' h/ k  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]7 {3 r* F4 y9 {2 b
  scatter     ;;keep center-turtle random positions 9 E0 ~1 T$ o# c
  unit_plan   ;;make up the building plan
8 `6 z3 p5 b% ^) ~) x7 R. Oend
; R( b& T: p3 M" \) Fto scatter: c; f3 k0 q& U6 d
ask turtles with [remainder who 5 = 0]
$ x/ U$ E! i3 L4 m6 k) \# U[
1 {: P% ?9 \) P$ k8 Oset xcor xcor - 6 + random-float 15
! F( F0 ?3 F+ ]# W8 t9 _; cset ycor ycor - 6 + random-float 15# W4 I( c; b5 I7 d& D  S( K/ q
]6 V) E# R+ e( }( N# e
end4 ~4 ]4 d/ ?6 L1 ]1 [( w9 t
to unit_plan
* _' Y: \' n8 a2 Task turtles [
4 c' `! U# s  |3 Uif (remainder who 5 = 1) [set a who
# t( k8 A& l0 V" e" m1 Y( J& i# S                          set x ( 0 - Wid / 2 ) , a4 R: I% ?' V9 H0 k* X
                          set y  Dep / 2 ]7 Q0 b* [4 T8 ?: r4 r+ ?
           set b  int (a / 5) * 5
7 i6 f' B! e8 g4 B    setxy ( xcor-of turtle b + x )
5 J# k+ k5 _& I; U, u          ( ycor-of turtle b + y )% _8 ~7 [. p5 e& y. B9 |
if (remainder who 5 = 2) [set c who" n( ]/ V) O" e; u- l2 k6 ]
                          set x ( 0 - Wid / 2 )
7 \$ Z6 p2 u, _5 A! T2 J                          set y (0 - Dep / 2 )  ]$ F" z2 e+ V. j+ u( g/ |9 x
                          set d int (c / 5) * 5/ {$ F/ j; r# [( \5 n2 z* |  R
   setxy   ( xcor-of turtle d + x )$ R( y# X7 |) c& h) ?2 t
           (ycor-of turtle d + y ) " [# G/ ^$ p) f3 N+ W0 S* Z$ {( r" e
          # ~9 L# W7 D; a5 ^- i
            
2 U( E& I4 R( r# w3 Lif (remainder who 5 = 3) [set k who
3 X, v5 [- L- p                          set x( Wid / 2)  7 I, \: s9 `' x5 a
                          set y (0 - Dep / 2 ) ]
7 r" \# n3 \$ ?3 G. [                          set f int (k / 5) * 5
. E2 J% I* W* e* ~( N  setxy   ( xcor-of turtle f + x )
8 O" _  L" c4 \! H0 a           (ycor-of turtle f + y )
0 ?* o$ ^1 j9 i- o3 h- |9 I             e$ F  U4 k! d
           2 v# b8 t: s' f. z5 P
if (remainder who 5 = 4) [set g who
1 l4 P- I3 T  [4 ]$ k" p$ [* m+ y                          set x Wid / 2
, \+ o9 ]! a# N4 ~: J* r                          set y  Dep / 2 ]
- l. V+ u- P4 y& Y6 ~' q# T( J2 w                          set h  int (g / 5) * 5
* J* k: |* N( ?  setxy   ( xcor-of turtle h + x )% w/ u  H2 G3 P: F' g& z# u0 x9 s* X
           (ycor-of turtle h + y ) 8 o1 P2 w9 Z& o
                          
8 ]3 t- y' o* f9 l% f                          ) _. D7 z+ ?5 E  B, V
                          ]
5 l3 \. T% Q- x( |7 F/ ^) e1 l& \end5 o% w' B5 x( l, p
; I3 W9 W) h9 a8 I- p4 G
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,: M9 S9 U7 Q( n- m
应该是3 ^+ O% y0 t0 w
ask turtles [
  P0 c+ T+ O& u, h3 P1 b/ d; s% sif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
% p9 [' P  @, Z! t. r: C* L3 E+ J/ n                          set y  Dep / 2 - c8 b0 B4 x' P+ O
           set b  int (who / 5) * 5
: P3 M2 g9 A  T) P: m4 i  H    setxy ( xcor-of turtle b + x )
- J4 U9 G! o4 D+ Z* \7 g( L          ( ycor-of turtle b + y )]]: n6 \8 t' a8 F# A0 M4 g5 [1 L% E
end1 v  @6 m2 u" c( E' G* {' r
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-24 19:20 , Processed in 0.019353 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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