设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8297|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。6 t/ ]' d4 L( g5 a, s

. m! w1 W7 P0 B1 ?! X但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
; A: q5 R; W/ \2 R) h. u6 \' u  Q* b# n5 `* F' J
turtles-own [a b c d k f g h9 R, S" |  e/ M
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
+ Y1 [# a2 r) b]$ P" G9 S: O, K+ t" r; M; Z6 ~8 D
to new6 |1 r$ n" {) \+ g
  ca/ D0 L! T0 T# T9 v2 _
  crt 5 * num_of_building
0 {' f  k( O: e6 v1 g2 \, w* ?0 S  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]- I9 r7 i3 ]. L! V! ^9 L" y
  scatter     ;;keep center-turtle random positions
* L- |, }! @5 E+ D; D/ ^  unit_plan   ;;make up the building plan# j5 S, A# b- P- z- O, ?
end- i/ d, j& V( x. p: \$ u% a
to scatter# R5 Q+ [! E, L1 l
ask turtles with [remainder who 5 = 0]  d5 t2 P; ~$ G8 J
[
" h( B4 t5 q2 z4 x# L  ]set xcor xcor - 6 + random-float 15; z  i9 f; Q! w9 o6 O
set ycor ycor - 6 + random-float 15: F$ O: M% {$ e- n
]
  B8 j1 F; s2 o; bend0 _: ^# `% A" f" \
to unit_plan
8 S* {0 t( k9 t5 p' c1 @ask turtles [
4 h2 r9 I/ ^# ?3 X) \8 z1 Jif (remainder who 5 = 1) [set a who
& t& j" u; R$ B$ p* r( N& I# i& i2 c+ \                          set x ( 0 - Wid / 2 )
: ^  @+ s) E) P6 g$ A$ \                          set y  Dep / 2 ]% Y' c' J# \! H4 l+ v9 E6 P+ [
           set b  int (a / 5) * 5
: O% j% s$ C1 J" n/ W' Q1 ^6 W' n    setxy ( xcor-of turtle b + x ). f! ?# N3 P+ x  B$ g9 g9 I  N4 J, a
          ( ycor-of turtle b + y )
+ n0 y( }% a$ j0 H& gif (remainder who 5 = 2) [set c who
8 l4 E6 N6 `. k8 U& k1 ?8 e1 s9 D                          set x ( 0 - Wid / 2 ) : l6 v  O# T$ J
                          set y (0 - Dep / 2 )  ]3 V0 J2 X& H7 c! O7 e8 P& P
                          set d int (c / 5) * 5
/ v! x. `4 h4 y   setxy   ( xcor-of turtle d + x )
$ I7 p8 s) U5 s, E. p           (ycor-of turtle d + y )
4 `' i) v' T' R          , W5 K5 g+ B. r+ Z9 C- o5 h
            
2 F* A& c4 N, Y, U2 h! nif (remainder who 5 = 3) [set k who; }9 L+ `" V1 N4 t
                          set x( Wid / 2)  
7 i8 u! a" ]9 V% b1 L                          set y (0 - Dep / 2 ) ]3 n/ X" L7 ^' [
                          set f int (k / 5) * 56 ]: M  l( f% {- @- k
  setxy   ( xcor-of turtle f + x )
! {7 B+ N/ ?  l* x+ M6 @6 s9 T  E$ I# `           (ycor-of turtle f + y )   \3 j3 `/ @% }
           
9 E7 h& g5 Y' X7 O           4 O- O- i0 G) {9 x# e
if (remainder who 5 = 4) [set g who% L& D# s0 ]: s' q: b! J
                          set x Wid / 2 * ~# P2 B# x$ C
                          set y  Dep / 2 ]
8 v7 T9 [6 E! \3 ]' D- e                          set h  int (g / 5) * 5
# Q: S) h8 Y3 J0 |7 v  setxy   ( xcor-of turtle h + x )2 y  B# k1 v+ d" l$ j% p
           (ycor-of turtle h + y )
: h" E1 k% \/ e. [                          
" M5 a/ |5 _, x6 H) _9 b                          ' l4 V* ~* v" ]% C" N& i* t) F
                          ]( G) `: u+ g# \) ?
end3 `+ g0 ?6 N" @1 v3 I! {

5 l; K# K  Q3 P8 o1 J4 T2 y[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,( N6 W* p, r/ ^
应该是" w  ?' t( h, [* O( ]+ f% Y
ask turtles [* @( B  L8 A* }( ^7 }
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
+ D7 s' m, w  q8 M' N                          set y  Dep / 2
' s  Q$ `6 z0 X0 I1 p7 o* Q           set b  int (who / 5) * 5
. @- M2 `  |0 o! N, r& a" C. x    setxy ( xcor-of turtle b + x )
4 a9 I8 }8 s" k1 c, X          ( ycor-of turtle b + y )]]
/ j- f# b4 b. w+ z' Y! v! b; vend" V- P6 p9 A/ I; u
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-2 20:34 , Processed in 0.015301 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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