设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8896|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。9 X" E/ x2 q" E. b
$ A9 U; K' _  @
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
+ g( k! Z. d! }. I. u/ I: r
& W8 t# U( B: Kturtles-own [a b c d k f g h
+ b2 J) _! v! @% Y! h8 J# K. k  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 8 k& M3 k: \. U" Y$ }9 o
]
  G, d5 x& j  U4 o/ T8 n; @to new; u/ H# s+ h* D+ p
  ca
1 j& h0 b. `* E( J  j2 U5 r; i* a5 B  crt 5 * num_of_building
4 E) G7 h% c  O7 T/ }# n' z  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
# Y0 O1 G# z0 k; t2 _0 {- y0 l2 M  scatter     ;;keep center-turtle random positions
3 _# b+ W( Q4 Y2 h* ]5 G  unit_plan   ;;make up the building plan
# c6 D+ W# Z$ ~# Bend
; `7 L7 Y5 u( `to scatter
7 h0 H+ W0 }3 I: t, Task turtles with [remainder who 5 = 0]9 u+ Z# i8 l, K% M9 }5 f- g  E
[+ {6 {5 C$ f8 ^6 k) Q* R6 b0 [
set xcor xcor - 6 + random-float 150 n; R- X7 C6 _2 U
set ycor ycor - 6 + random-float 15
% @2 q$ A3 r# ~+ i% o  p) G' n]
2 z/ a4 H1 j- d2 Z1 a' Wend
$ b( D) J( m0 S! K8 Dto unit_plan 3 @) _2 ]% _7 {$ v1 C; d5 c: U4 e
ask turtles [
& B9 k8 R8 e' W  x8 a- p% n, ]if (remainder who 5 = 1) [set a who 3 u* `. p1 G+ i  j# y; [
                          set x ( 0 - Wid / 2 )
; _& v/ [  |: F$ x1 ^                          set y  Dep / 2 ]4 A* h* J! ?' Y! r3 J9 ]
           set b  int (a / 5) * 55 |/ o) j7 q9 P$ a( N' O( c, T& z6 q
    setxy ( xcor-of turtle b + x )
+ p4 V/ y9 u9 r          ( ycor-of turtle b + y ), K' T9 C! X4 J$ `% w% X4 t
if (remainder who 5 = 2) [set c who$ B8 I* `, n& ]% N4 X
                          set x ( 0 - Wid / 2 )
: M0 X; V3 _9 _! z2 r2 _2 V$ |                          set y (0 - Dep / 2 )  ]
$ N; |5 p. }; Q8 T5 F                          set d int (c / 5) * 55 o4 M3 E% [& I: b1 {; \: f
   setxy   ( xcor-of turtle d + x )
; ~6 V8 q" H, A6 J' L           (ycor-of turtle d + y )
6 G. Q; k+ C  ]* w- g! J- l' l0 I/ r& j         
6 j1 k* u  `) S2 v, R            7 J1 N5 i( v+ x; `) q
if (remainder who 5 = 3) [set k who; U7 q# T8 _3 @3 K/ l+ j
                          set x( Wid / 2)  ( T- f" D" y# H6 d3 h4 [
                          set y (0 - Dep / 2 ) ]
, d4 y, S# o  m                          set f int (k / 5) * 5: k4 W7 M; D1 e6 Q- O
  setxy   ( xcor-of turtle f + x )
$ C) ]" t5 U0 P' s           (ycor-of turtle f + y )
6 n; t: u8 N$ l" w# P0 [           
, l# o2 a6 `: O& d  p           
1 T1 E8 r; J1 Z2 Aif (remainder who 5 = 4) [set g who4 b; ]0 X1 M4 u6 k  c% p2 s
                          set x Wid / 2 3 U- M7 P3 o) y# k& Z+ Q- n) i3 s9 t
                          set y  Dep / 2 ]
# j7 q( P. a. R0 f2 L$ w+ P                          set h  int (g / 5) * 53 E& _0 ^& Q1 o! z' a: j
  setxy   ( xcor-of turtle h + x )
3 D# _7 a5 v( X& d           (ycor-of turtle h + y ) $ ?( B" u5 Y0 N" j& h
                          
+ k4 T- Z9 k$ ]! o$ a, {, B                          
3 c5 x0 G. B# Y6 @. F2 U                          ]5 z3 X  \: g: M- [! |7 _7 S
end
4 n5 p1 {! O  D; Q* M8 ]" U# a
+ _" \3 i9 a- S1 U* Q. @[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,/ |$ s5 U# a* r% j6 u. t. Z& O
应该是3 e: Z5 R3 {: [) t( w5 @9 l4 O: S
ask turtles [
' m5 F+ n0 [$ |if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
5 f0 e8 v; T0 U5 Z$ B                          set y  Dep / 2 ) m6 M0 n+ W  V9 S. O6 l, L5 k" O
           set b  int (who / 5) * 51 ]$ D% m& k: d
    setxy ( xcor-of turtle b + x )- M+ _6 n* B3 b: B
          ( ycor-of turtle b + y )]]
# M$ @# H; v6 O: T' j' X* P: hend* i5 j9 E9 I! V% M% X) L
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-19 17:50 , Processed in 0.015551 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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