设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8016|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
  n) x2 M! g) t! }! P$ b+ j$ v) x( U* c. I' [- @# E0 n
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。; w: \% O" g& `0 i9 V" \

  |) ~6 r( s* e' q3 w7 S# \turtles-own [a b c d k f g h
& [# }+ s4 P, e% I. V9 v; X3 N  x y     ;; these are the leaf-turtle's offsets relative to center-turtle * d4 c+ S) |8 J" K1 v; H
]% m, \9 s9 y( d+ \9 K4 n# R9 |4 f( F
to new; P  C/ Z+ h. z4 t
  ca$ }6 f6 ]6 A, R' I& k. G& I3 @
  crt 5 * num_of_building6 e. G/ F7 |* K( w0 x
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
  c- z/ f4 j( {& P3 i! D  q4 |3 }- J  scatter     ;;keep center-turtle random positions . m6 C% D2 Q3 ~' I; @% `+ F
  unit_plan   ;;make up the building plan
# l1 i% J& o0 x. Pend
- z! D# c+ m! L* s( o& [$ ~, qto scatter
, W7 S# ~8 k1 E& I" u; O% E% b1 Qask turtles with [remainder who 5 = 0]
! L6 s4 ]2 z: w[
8 h: |8 |6 n* Z( mset xcor xcor - 6 + random-float 15
, @: Y$ l' p% r7 M# Qset ycor ycor - 6 + random-float 15
& d6 ~. @9 s( ~* g6 ^  N]* L) e+ Q( V2 s" p( ]! Q; E
end6 O) c# V% w$ p# A3 F/ H
to unit_plan
& R' m, g7 o8 u% e2 @* f' Nask turtles [
0 i9 M" n! X3 `% Y3 ~& Gif (remainder who 5 = 1) [set a who 7 D' l+ j: L3 U5 C: u0 n- i  F* o
                          set x ( 0 - Wid / 2 )
; o  z$ o) y+ K                          set y  Dep / 2 ], r7 l* a5 B+ o0 c' h
           set b  int (a / 5) * 51 z; ^- [7 s) B& z1 r- u) }" \0 L
    setxy ( xcor-of turtle b + x )$ a4 F: G0 ]0 p# O! Z5 _
          ( ycor-of turtle b + y )+ I6 a) {3 s0 S' q( N  E
if (remainder who 5 = 2) [set c who
6 l/ n+ ?3 A+ o, A9 O: r                          set x ( 0 - Wid / 2 )
" {  F* y7 J7 o" O7 Y- [                          set y (0 - Dep / 2 )  ]
, q# U4 @+ r1 J                          set d int (c / 5) * 5
, B& g9 C7 G. y9 {$ s/ J& \   setxy   ( xcor-of turtle d + x )3 \2 [# z0 y  ?+ B2 _) h
           (ycor-of turtle d + y )
2 p  m3 T4 N3 h/ Q         
9 g/ r5 v( v. D3 k7 U: ]: p; z            
$ h8 z$ i! J0 Aif (remainder who 5 = 3) [set k who: C( e1 y% r. W- E% d
                          set x( Wid / 2)  9 x! }, u9 }9 K0 O" v5 x$ U
                          set y (0 - Dep / 2 ) ]
# _9 b1 ^+ p, f) v& P  o5 s/ V4 L                          set f int (k / 5) * 5' R: E9 x# ?# [& [9 u& [+ S
  setxy   ( xcor-of turtle f + x )1 [6 F) O; @* s/ \0 F( H9 q4 g
           (ycor-of turtle f + y )
& y1 M! _9 |3 n; e, A           
, v! N$ ]( a5 x4 i2 B% ]0 a3 Y           1 R9 M" x2 Y" P9 Z  P# P, j' Y
if (remainder who 5 = 4) [set g who! f& }. L! q* h; c' \1 H
                          set x Wid / 2 0 e: x& d( t1 G. j% L
                          set y  Dep / 2 ]) [) [: b, I4 a; t# x! J+ D- `
                          set h  int (g / 5) * 5
: g+ A& n* d6 n1 }6 b  setxy   ( xcor-of turtle h + x )
$ R1 x3 D7 _+ \" u# r7 X           (ycor-of turtle h + y )
8 |" F9 ?& y2 y8 D6 y4 S                          ' o$ R; b  P/ h- B4 N4 q: ]' b' o
                          & [  {# E  Y' Z! R$ o- n
                          ]
- F& G# _$ D  }  Y& O2 S# t) Aend; {( X; }+ \4 {/ ]& n

8 Y/ E! |+ {0 {$ ?3 V[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,8 g8 m3 Y! t8 U& n' T+ f4 ~( x" |1 a
应该是  c4 [6 l, q) J" L; z
ask turtles [
/ w8 B+ X' a! d8 x" f# Eif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
2 l- }+ h$ |+ G5 t9 U                          set y  Dep / 2
+ m/ W4 h2 ^; s           set b  int (who / 5) * 5
# V2 f' r& @) H" L& {8 W0 o    setxy ( xcor-of turtle b + x )( e/ y9 f8 s! r
          ( ycor-of turtle b + y )]]
# P+ g& S2 i" _5 w  P/ d& {6 Vend: q  v! n7 q0 x) B9 p9 J
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-29 01:42 , Processed in 0.020086 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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