设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7452|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。1 S, f  J" E# J- `9 o

4 `' p0 l, K. N. X4 T但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。: |, @3 P. J) M7 l6 {# R

5 z$ S9 c3 z  v  }turtles-own [a b c d k f g h
8 q6 B; w: a( s  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
2 Y( o' k3 \& L) B' u; E3 k]$ a4 V2 ^' P2 F  V$ b1 e! i
to new3 s- N2 k! n+ }& W: n- ]
  ca0 l( z# J6 I9 ]
  crt 5 * num_of_building, |8 ?. ?  z: R! A/ K
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
. K* \; P* i" e1 v4 K+ ~  scatter     ;;keep center-turtle random positions
2 B+ h* @' n+ k6 t  unit_plan   ;;make up the building plan: [) J( ?* Z# @
end1 Z. c5 W3 N/ |0 g& x8 G1 K
to scatter
( y5 Y6 G5 d: x/ d2 X3 lask turtles with [remainder who 5 = 0]. G# }0 ~0 g3 `; T; M% a1 j' P# u' ^
[# B% p0 _' p% v7 t$ V3 I* x7 W
set xcor xcor - 6 + random-float 15
! l1 G, m: T2 Z8 v- Yset ycor ycor - 6 + random-float 15
5 {2 e( i# L) j0 p9 c]2 t5 Y' G) t- {$ \6 Q1 O. n7 O
end
9 W# c; q7 y2 `$ Qto unit_plan
8 F3 B# D# a& o% t( w/ u9 u3 Y! bask turtles [
" X; t* G- y. ~if (remainder who 5 = 1) [set a who
, x* C/ }3 o, {, R7 b# s& _1 C                          set x ( 0 - Wid / 2 )
5 }% U/ {: A3 G1 {( Y2 l                          set y  Dep / 2 ]# G9 ~9 T" Q( F  n/ T
           set b  int (a / 5) * 5
3 s& K+ P" G. D0 ]. w9 x    setxy ( xcor-of turtle b + x )( I- j0 B) h2 o) E  l
          ( ycor-of turtle b + y )
' h6 R0 L0 P4 {" p& l7 yif (remainder who 5 = 2) [set c who9 Y$ D% ^& w/ X1 x% }- r& J
                          set x ( 0 - Wid / 2 ) ( O! Q+ {2 U0 U2 v$ A' P
                          set y (0 - Dep / 2 )  ]
" g$ e0 }+ o1 B" [3 w' H. @- \                          set d int (c / 5) * 5) B1 h% Q+ \4 K# C; v+ q, `: p) W
   setxy   ( xcor-of turtle d + x )3 d% e$ r1 K8 @0 E; ^
           (ycor-of turtle d + y )
" |9 g* D# P! I          : \$ y. a- ^& p# d
            
# _  e! n9 b+ c" t- P, ^8 J, H6 H# Uif (remainder who 5 = 3) [set k who8 |) l$ z' W6 Z2 x8 q7 y) \1 Q
                          set x( Wid / 2)  
; d) V, c; H: w  W+ s# A* [                          set y (0 - Dep / 2 ) ]
! _0 ?4 V  D# J2 W                          set f int (k / 5) * 5
* j+ J- O  M4 C7 c( E" T  setxy   ( xcor-of turtle f + x )2 g) a! A; M. P
           (ycor-of turtle f + y ) " C0 ]. f7 ^* \' U$ l. s
           
; p/ n7 S. W3 M9 x/ u, \           : {8 m' R* b8 S4 d3 \: v
if (remainder who 5 = 4) [set g who
- {5 q' D, I) i: Q                          set x Wid / 2
: Q0 ]! J3 @5 j9 a                          set y  Dep / 2 ]7 {* t" ~0 e  P9 K; ~
                          set h  int (g / 5) * 5
+ I/ c6 j; B: T9 `8 w- n- w; W  setxy   ( xcor-of turtle h + x )
) L0 x% H% }+ n) C           (ycor-of turtle h + y )
, L( U0 C5 h( ?                          8 `% B- Y7 r5 o
                          9 K* ?5 `  ~7 `' H: l
                          ]+ a1 O* r$ _0 e
end
( V, f+ i8 Q4 w9 ]7 T# t" t) i+ t8 M5 _# Z# |# D8 ^8 {! {
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,4 R. N, I3 R4 m& c
应该是
. ~4 b' i% ?1 Bask turtles [. J* m2 O/ V2 C- O* n0 ~7 \* K
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
9 Y! t: T  ~. g  R. Q                          set y  Dep / 2 # g5 m, {; H, Y* j( n
           set b  int (who / 5) * 5
# ~1 I' ~# e0 m0 ~0 y- f    setxy ( xcor-of turtle b + x )
6 z+ o$ I6 c. M6 A3 W' Y/ y          ( ycor-of turtle b + y )]]
. Q& s9 _6 c$ ]) D  K& Dend! C% u/ |- A6 r. ^/ O9 X
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-12 21:00 , Processed in 1.900753 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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