设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8939|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。" Z+ Z$ W' I* j" ]/ v0 C6 s

# Y9 c% c3 T' u4 p但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。$ n7 s& m0 n" }$ D
5 w3 V* Y. ]2 \5 `& c# Q
turtles-own [a b c d k f g h0 P2 L) V4 r: _- B" R
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 5 s2 {/ R# o0 I$ `: A: p; Q
]  n4 K- c$ _) d
to new
9 H4 [" O8 t, E! v* P5 E, Q# ?  ca& j% p5 F% H3 z# y2 T5 F1 `
  crt 5 * num_of_building
, I  L2 X. D4 Y" d$ `% m  O  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]4 U- i( M0 B# ^; @7 d' q6 T( ^
  scatter     ;;keep center-turtle random positions , ~% ~% }. x8 [7 h' g
  unit_plan   ;;make up the building plan" g9 I: m7 G0 N* Y) G
end
+ U7 s. g: @. k; Q' Lto scatter
7 Y, G  d3 ]: v5 i  Z  sask turtles with [remainder who 5 = 0]! T& E6 o( K  u4 S
[
5 S! s2 y# m9 r: W: D8 s2 @0 B0 |set xcor xcor - 6 + random-float 15/ N9 Z/ C& \7 R: @
set ycor ycor - 6 + random-float 157 ^" ^5 Q; Z( R1 J6 ?  l# Y
]  o+ o8 m- b. p) e
end1 O7 Y$ Y+ U$ b  z3 T, W
to unit_plan " B# [1 X& r% ^3 e
ask turtles [. J  ^( M6 Y/ c, R0 O
if (remainder who 5 = 1) [set a who
) J" W  e3 ?" o! Q                          set x ( 0 - Wid / 2 ) 6 Z. `) Z3 O% _7 N+ V
                          set y  Dep / 2 ]
9 [' b8 L6 D8 ]  s/ U6 m6 ]           set b  int (a / 5) * 5
2 ~' k# @6 M. C; Z    setxy ( xcor-of turtle b + x )
+ G* c' d+ D( m/ i3 ]          ( ycor-of turtle b + y )
) r6 G! W9 C2 v. Z, u# [* rif (remainder who 5 = 2) [set c who
) C9 b1 B9 Y  A                          set x ( 0 - Wid / 2 )
6 M: h# f3 ], G( I! y" X8 ]1 w                          set y (0 - Dep / 2 )  ]
" ?5 h5 a& N" B( g+ n                          set d int (c / 5) * 5
& ~3 P$ E8 Y* O: M1 W6 z- X   setxy   ( xcor-of turtle d + x )) x+ m! Z0 R( t6 c9 B9 F
           (ycor-of turtle d + y )
$ z6 [! `9 V$ V3 V" G- J          - i: n* A; h4 r4 G6 y
            
9 x, N$ ]& x, Z3 X4 G! ]if (remainder who 5 = 3) [set k who
7 V. c4 N; `$ a( j* y3 R                          set x( Wid / 2)  ! O# E3 B. Z( @
                          set y (0 - Dep / 2 ) ]
$ x. ?% U( ~& P                          set f int (k / 5) * 58 A* Q* m% C: W7 d! c0 g
  setxy   ( xcor-of turtle f + x )$ g: s" X( p' ?" ~* ~
           (ycor-of turtle f + y )
" U2 Y; R' g" E: b: x- o           
4 g6 C5 n+ L( v0 l' u% U7 |+ _           ! o0 X. y( A2 Y0 Z; A
if (remainder who 5 = 4) [set g who. u8 F/ H! q9 g7 P
                          set x Wid / 2 ) U8 j; d: f6 V$ m3 `& k+ a) ?
                          set y  Dep / 2 ]$ a2 g. M- U& x6 M0 G' W! r7 k# @
                          set h  int (g / 5) * 5
$ e$ w( G. {, l- E9 R- ~7 o  setxy   ( xcor-of turtle h + x )
' G2 q7 Y! `9 w; ~7 F1 n4 A           (ycor-of turtle h + y ) $ b5 B8 C  m4 V/ [& I; q% U
                          
: v* ?4 n' p/ {, y: \                          7 `; b7 ~1 l1 E/ U
                          ]
1 x4 W$ j2 u# V. u' W% B4 oend2 p! Y( U2 w% s! q

% s2 |6 `5 G" @$ n- u8 [[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,5 I8 v6 V  l3 e2 S3 d$ }
应该是2 ]/ r$ W1 P: t  T
ask turtles [" @4 @, d: U9 {, R9 ]  s. k5 P
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ! M5 `2 x4 m' z. S! A
                          set y  Dep / 2
& d+ A$ F( r1 W$ r& E! e           set b  int (who / 5) * 5' {. |( N2 i# I( ~
    setxy ( xcor-of turtle b + x )* v. }/ ~; D5 t
          ( ycor-of turtle b + y )]]
; m2 _  Z3 Z& j; }9 o: F$ n0 I0 ^$ Send. t; m* B1 T! l) |
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-27 11:16 , Processed in 0.015720 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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