设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8874|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
& Q& T+ U( c* N7 N" a  P7 V2 z5 o/ p: F9 `$ L" g
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
4 B  [2 ~& b6 t5 V- q; m$ N5 Z4 o' X9 [
turtles-own [a b c d k f g h
+ a, G. P  z# ^5 _8 }1 r- p  x y     ;; these are the leaf-turtle's offsets relative to center-turtle & m6 g5 y. [) Z. A9 ?* U( k
]3 a# \# P3 W! c: b& a" O( J
to new$ \& D" @" l4 t! I" K1 K- y0 N$ o
  ca
/ c  D) Y) `6 h3 ~0 o7 E) m0 l  crt 5 * num_of_building
$ V# v5 L) c' B  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
3 j; H. u/ {  I8 l! W* ]+ |  scatter     ;;keep center-turtle random positions
" t1 B4 ^2 h3 ~) [; N. v+ h5 T  unit_plan   ;;make up the building plan5 b' |# ^0 V+ q; g$ X0 P/ B9 m
end
% ]3 P7 K, r! T; D: _( K! ]to scatter; V' k8 D' a9 d/ [
ask turtles with [remainder who 5 = 0]
! E! t# d! F9 s1 [8 E[
% t2 G+ Q" |9 B0 i7 N5 Nset xcor xcor - 6 + random-float 15; C* A8 a  P& N- k
set ycor ycor - 6 + random-float 15
- C# n' t+ F6 m; m+ [- [+ B]
3 E% }/ d( a% a& Fend
+ ^9 p8 V6 K* g+ M9 {6 O6 X  L$ xto unit_plan " [5 D4 V  V: X! w9 E3 ?" b
ask turtles [) w# ~( E; z3 y8 o
if (remainder who 5 = 1) [set a who
& ^$ k9 j2 _! Z& H/ s/ \( i* i, F                          set x ( 0 - Wid / 2 )
4 C$ |+ Q% I8 x                          set y  Dep / 2 ]
! W9 z3 x( f6 L4 Y           set b  int (a / 5) * 5. J* @  H  U8 \& S. u5 H
    setxy ( xcor-of turtle b + x )# q1 W% O4 [, S1 V% l. h
          ( ycor-of turtle b + y )* B" L( V3 t- F: t, K% ~
if (remainder who 5 = 2) [set c who# l' J5 ?+ j, {* c& F' c" k
                          set x ( 0 - Wid / 2 )
  [, {  F" f' o& R( W; `                          set y (0 - Dep / 2 )  ]
0 Z: |2 P1 \1 n: G8 \3 J0 X$ E3 c% A                          set d int (c / 5) * 5. B; C, I& l  m1 b6 `
   setxy   ( xcor-of turtle d + x )
6 Q. L0 V: `% w- P3 E2 ~" j+ m4 T8 ?, w           (ycor-of turtle d + y ) & o+ }& o3 s7 q* f+ U% Q
          : e! ?. L# R' S( F) c7 }2 ?
            
0 V# O7 [4 |  G( K0 Kif (remainder who 5 = 3) [set k who8 z8 l6 ?. V6 x( N2 e
                          set x( Wid / 2)  ( Q" i; ]# M3 m, m4 l8 r
                          set y (0 - Dep / 2 ) ]$ p8 q# m0 z% H5 |& U. Y+ ]: {
                          set f int (k / 5) * 5
* f1 x' h% F# ?$ {$ \. }: j6 K1 R- L  setxy   ( xcor-of turtle f + x )" v) z' V2 a4 F
           (ycor-of turtle f + y )
7 B- b6 X; Q, x3 M           4 `; @+ X* w# [- @8 k
           
: G8 y: I; Q. N! m. Z0 a7 mif (remainder who 5 = 4) [set g who6 B* ~* K  f; e! [
                          set x Wid / 2
- |3 t* J2 t1 o" T                          set y  Dep / 2 ]
3 g4 n( @# J; o                          set h  int (g / 5) * 5
7 x7 \) e) Q9 L0 |( ?! o' Q  setxy   ( xcor-of turtle h + x )
0 H! O7 h7 J) N9 v  l' q7 M           (ycor-of turtle h + y ) , \% ]1 Q6 e9 ~0 x, I! h2 {3 ^
                          
; Z) Q* D* Z' ?- }) N! [                          ) s5 @. r! K: Y# o" f' @( {
                          ]2 u  J- D2 w% j" l
end* V/ q, y4 p. h8 a" [0 _

/ C% d" N! h' Z' N8 J4 C( H[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
2 E$ ?: t* f3 k. Y( q: w应该是. _$ B0 y& Z  n4 C) m& U
ask turtles [
; K* V% X8 X, Kif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
" \7 g* K  I5 E/ i                          set y  Dep / 2
; n0 ]  h' Q/ _' k! I3 |           set b  int (who / 5) * 5
% M. S/ W1 G! c! s    setxy ( xcor-of turtle b + x )" a9 k8 m% U2 p
          ( ycor-of turtle b + y )]]
2 y' N, Z5 G6 ]8 {2 l$ D, [7 a+ H; `end/ D& @8 \" S( M6 g* [" _. ]( f
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-15 01:55 , Processed in 0.018560 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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