设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7883|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。4 ~# x* u! ?* u- O: Y( Q

! i" O+ x/ X$ {但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。4 I" E5 L# t" [
* ^  K; I/ L& w( L
turtles-own [a b c d k f g h3 c% H/ G! J4 W9 u% B" e+ _% G; w
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 2 w) R1 ?6 y0 m3 Y/ `% H) K7 W
]% i$ q- E2 ~: h6 e7 U2 w8 K0 y& [
to new
2 F5 c0 ^4 X9 I1 _) B3 e  ca( E( u8 B+ w$ d" X4 D# A
  crt 5 * num_of_building& x# E$ m3 J7 l- H& l
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]) _" ^: e# F+ N8 X# C% [
  scatter     ;;keep center-turtle random positions ( D1 f7 g+ T  O
  unit_plan   ;;make up the building plan
+ H& [& O/ O, ]! `end
! A1 R, I! N: R. w3 Jto scatter
8 y. A* W: U6 ~ask turtles with [remainder who 5 = 0]
0 `& |$ O$ D7 W* Y6 T9 i( k[
# a& H  r5 m4 l! P0 ?set xcor xcor - 6 + random-float 15
4 J) J7 z; D: L% C! l# W# r0 wset ycor ycor - 6 + random-float 15
9 X4 L6 l% T9 j]
& O- H' ~$ S+ r+ nend- M' E" P9 \# ?, u) g
to unit_plan " h# r9 F5 p8 S. Q6 {
ask turtles [
; A3 Q3 _  S4 |if (remainder who 5 = 1) [set a who
' ~/ ?. f0 N6 C2 w) V                          set x ( 0 - Wid / 2 ) . W" N" d" P  \. o7 ^$ s' R) v
                          set y  Dep / 2 ]9 m  L3 k" X( \7 I6 n5 N" z7 R: Y# L
           set b  int (a / 5) * 55 d" K; y$ f; \: Z2 t8 ?
    setxy ( xcor-of turtle b + x )2 E* @- B% c2 U% P; I. n
          ( ycor-of turtle b + y )
6 S# R( f5 J+ v4 _7 s: t; b: i4 `$ ~if (remainder who 5 = 2) [set c who
& n" I1 [" M: F" P$ C7 y, V" k                          set x ( 0 - Wid / 2 )
1 A8 U# X; e: l1 j% {                          set y (0 - Dep / 2 )  ]  A  S! j& B4 F
                          set d int (c / 5) * 5
1 R+ _) f! c  V   setxy   ( xcor-of turtle d + x )
: T2 k: F4 `, _5 A) B6 L6 M" C           (ycor-of turtle d + y )
/ p( y: f" _# T$ u- {5 v          : K( e# p, n/ `9 ]' i9 E
            5 H0 B- m, |/ a9 w
if (remainder who 5 = 3) [set k who
! _: F/ E( a" X8 x                          set x( Wid / 2)  
) l" {, d( e5 z6 }                          set y (0 - Dep / 2 ) ]
% D, }: p+ T3 U0 S5 {& F5 F                          set f int (k / 5) * 5
" ]5 H" f9 l( z1 ]  setxy   ( xcor-of turtle f + x )
" D5 c9 h. ]" f7 ~8 B           (ycor-of turtle f + y )
4 I# G6 F( F( D           , L1 q8 `5 e* W3 `
           ; X, K- v( g' x0 U
if (remainder who 5 = 4) [set g who
6 ~( v5 f/ p2 r) n' D% D                          set x Wid / 2 - C& e& B) o& H4 A) l- a; _
                          set y  Dep / 2 ]( P8 M, ?& x" B- f9 m4 U0 k8 o# R
                          set h  int (g / 5) * 55 u2 \% R& A. j4 u7 \! U
  setxy   ( xcor-of turtle h + x )3 R' c3 x5 F7 U+ g  V/ Z
           (ycor-of turtle h + y )
1 Z  k- x/ q' X( o$ C. |                          
$ x0 s8 w' A+ T                          
& O7 g+ V0 X* v# q5 e                          ]9 {0 B3 ?+ ]* V8 L# ?" l& i6 O
end
( V% F; l8 \4 I' V) B
* q- A( u* \7 X8 t% b[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
% F8 ?  f6 l% N* x4 }( h应该是( i, X9 ]7 [+ R3 Y
ask turtles [- j( W8 p3 c  E; W, m- [5 f
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 6 ^- n1 @( C( h/ ~6 R+ P
                          set y  Dep / 2 , X3 d$ x' `: I& m
           set b  int (who / 5) * 5* C4 I( c+ a- E3 j/ y' }
    setxy ( xcor-of turtle b + x )3 S7 }* P! I6 D+ e/ Y' O1 E6 Z% c0 q
          ( ycor-of turtle b + y )]]% |" C( |  J( ?# {
end
% X8 q5 ?0 ~8 u6 e/ b, ^1 T之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-14 22:55 , Processed in 0.021241 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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