设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7357|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
1 l# D) W" a5 V0 Z9 a1 K! R4 M+ T* u3 m; y) v
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
- B' @' I4 [# u! \, {$ ~) ^# A* u1 M. ^# H. v; B
turtles-own [a b c d k f g h
/ k0 }3 x% q- D9 \7 f  p  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 9 e/ s4 E5 U: ], ~3 C+ H, v! Y
]
5 l# F- c% F- q* ]1 q& ~  K1 k! v# X" dto new
( n/ A. k; ^* N7 c2 P6 F  ca. F0 j! R# q2 E! P
  crt 5 * num_of_building
; m# M- I# N3 f0 f& p: x  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
9 ~7 w. S9 M2 M8 r  scatter     ;;keep center-turtle random positions
* L" E" p" r1 @, o4 u6 r  unit_plan   ;;make up the building plan6 |/ ]7 H+ ~# l$ v7 [- g
end
! x4 |: ?* }) y& m/ X5 T; C5 d; d6 @  Vto scatter
$ ?1 a. L$ ^: n) B; ?# ~ask turtles with [remainder who 5 = 0]6 x4 t; f+ D. R/ R0 Z$ G3 f
[% S' B+ i) u. u
set xcor xcor - 6 + random-float 15
* {* h, P0 I% Sset ycor ycor - 6 + random-float 15; a+ m" V1 {; |- W& r  `2 m
]
  r- m/ {2 K" R, |end
  n: F4 b2 m% g0 Jto unit_plan
2 M5 p& d1 s' m! d: N; y$ task turtles [& S& V4 q( B- U5 F) l$ g2 U
if (remainder who 5 = 1) [set a who 7 `9 `  L' t) a/ K# j, F% \
                          set x ( 0 - Wid / 2 ) * N: v) N; u! X2 B# O
                          set y  Dep / 2 ]2 D" z7 q5 P2 D& S4 F# v! V9 ~! h
           set b  int (a / 5) * 5* G6 ^  _8 a1 V' n
    setxy ( xcor-of turtle b + x )" g4 r( ]5 ]4 ]
          ( ycor-of turtle b + y )2 A) }! d1 [9 {0 |- O* O
if (remainder who 5 = 2) [set c who0 s  {0 c: Y  Z. M2 d  U9 J' [, n
                          set x ( 0 - Wid / 2 ) & W" L: X& C- P" a" k6 t
                          set y (0 - Dep / 2 )  ]- e- K- L7 A8 e0 g% s! J  G
                          set d int (c / 5) * 5
: s! ~+ g$ ]! [* `# B   setxy   ( xcor-of turtle d + x )& K- `) @# U0 `2 |3 B3 I7 b7 ~
           (ycor-of turtle d + y ) & h. ?# b6 ?/ x
         
+ b- Y$ ?2 I, K4 ~* V5 V            
8 R$ e; D0 m. {( U7 C: H* ~1 z0 iif (remainder who 5 = 3) [set k who! U1 f; y. z' b7 R3 o
                          set x( Wid / 2)  8 |$ d5 O  M  F' `4 R9 k
                          set y (0 - Dep / 2 ) ]& ^: s/ l3 R* M  d# G) v
                          set f int (k / 5) * 5
7 z$ U8 D. B& U' J& [  setxy   ( xcor-of turtle f + x )% ?3 u3 W& Y4 G6 E& T! r( P
           (ycor-of turtle f + y )
4 ~. L* e) D5 u% r           
" @4 ?+ u* B" l* e           
9 {, C$ b: `) y  X, _# dif (remainder who 5 = 4) [set g who0 R6 G& y0 \" j; I
                          set x Wid / 2 2 `: E& m" e1 f1 v9 P* t0 ~9 P: u
                          set y  Dep / 2 ]
; ?$ v( C% |+ D$ M; l  b, B9 F) t                          set h  int (g / 5) * 58 a' Q4 l: y1 F' g, N9 L
  setxy   ( xcor-of turtle h + x )# c8 R$ L- C2 E
           (ycor-of turtle h + y ) ' {: F/ t/ z/ T) Q7 r4 C$ ]
                          * v8 P. \" ^9 m0 u. t
                          
. S# {8 [: e+ s' n7 }5 z                          ]
# ]+ F$ \& B" `8 H& c4 \: j' Eend) L( P, g4 |1 Y5 O7 Z
  u. ]0 E, R) ?( \" G
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
6 _9 r9 F0 a7 t& T应该是6 x; ?* [  H2 j- x! O6 G  ]
ask turtles [
3 W7 z5 F; r- Vif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
; I3 L1 a3 `% L) j                          set y  Dep / 2 - u0 o  F) A9 z# n
           set b  int (who / 5) * 5
3 ]( ^. t+ s- @8 E    setxy ( xcor-of turtle b + x )
$ I2 |. ~% j3 |5 v: X          ( ycor-of turtle b + y )]]
9 T: i5 i! g7 y" s% s+ Yend
( V0 C: T1 V) ?: U之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-2 13:46 , Processed in 0.019321 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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