设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7542|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。; K9 b- }$ Q- K: A4 C

2 c. E0 k9 B4 F' D但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
; ]: g, V% J' l0 l+ a# ^* r" \8 j4 _. Z% I8 _
turtles-own [a b c d k f g h
2 S4 Y5 n0 c" _2 Q8 f  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ' F# D6 a/ O& \
]0 L7 u* }& Y' w- k0 L& ^& c& B
to new; ?! i0 M9 V/ i$ S
  ca
9 B* B( o/ e+ a9 M1 x- ]  crt 5 * num_of_building' w/ Q6 d/ T/ |2 e2 ]
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]], z2 d8 N% ?2 A' K# E
  scatter     ;;keep center-turtle random positions $ ?: @9 P; X, f8 n" x" N$ b
  unit_plan   ;;make up the building plan
- b* f/ M% f9 H/ I9 K4 aend
( ?& j* W. w* F5 V9 nto scatter" O* R2 f1 l7 h& u" f. |
ask turtles with [remainder who 5 = 0]
( ]. O9 X3 m% A/ R[
! C8 f- _0 U' U( l0 q4 V  C* Uset xcor xcor - 6 + random-float 15
( p! n" m* `& A- {/ |$ j" ^set ycor ycor - 6 + random-float 15% ]( q3 r0 G; _2 Z" Q
]2 W; e$ s" ?; v5 C
end
  n0 ~/ c0 R7 y3 d0 r. xto unit_plan
% E/ o1 M1 P  Sask turtles [  w/ F) `/ ]4 o2 B9 O
if (remainder who 5 = 1) [set a who 6 r6 J2 J& Q/ }. F
                          set x ( 0 - Wid / 2 )
8 k$ }) Q$ F, p" @. e: q' {                          set y  Dep / 2 ]/ A! n5 m* V0 ~  J% h( i4 L
           set b  int (a / 5) * 5
6 L; F, P) U$ I5 y, J    setxy ( xcor-of turtle b + x )
6 \* g' P" N' r  z          ( ycor-of turtle b + y )
% X: ?5 S. K( C3 A4 F5 Zif (remainder who 5 = 2) [set c who
( y% L6 g/ B0 b                          set x ( 0 - Wid / 2 )
4 ?. |# x2 r# M# R2 _3 d+ D5 Q                          set y (0 - Dep / 2 )  ]" M% B1 c9 V9 h$ }9 V5 L
                          set d int (c / 5) * 5
  |$ y9 }5 _' x9 H' t2 i3 }* a   setxy   ( xcor-of turtle d + x )
% r3 t1 N) I) V           (ycor-of turtle d + y ) & o1 `4 l6 V7 ?' A
          5 Z# a  e& s2 u0 ~4 v2 f
            
7 a5 U0 [6 d9 Vif (remainder who 5 = 3) [set k who  c# \. h9 V1 {1 @8 X+ Y
                          set x( Wid / 2)  
" y$ ]2 t1 w  P                          set y (0 - Dep / 2 ) ]) k1 z  M  D& B
                          set f int (k / 5) * 53 ]! C5 T3 \  V8 y8 F/ T; h7 P# l
  setxy   ( xcor-of turtle f + x )  a9 ]6 f. b% U- ?( p/ q
           (ycor-of turtle f + y )
+ K' ?* S! B  L5 {" z8 b6 N           # D8 S; a6 Y+ A$ a/ ~
           
" Y/ K6 l; x6 ^! w+ o; N7 j& Fif (remainder who 5 = 4) [set g who
8 n$ x* ^6 ^' Z$ Q5 X- _                          set x Wid / 2
, S. _7 q9 q% O" l0 L' o' `8 J. S, b                          set y  Dep / 2 ]
( m0 E/ i  a  ?& p* }% Q2 Z                          set h  int (g / 5) * 5
! `2 ]  r" L" Z6 P8 n, E0 @9 c+ B  setxy   ( xcor-of turtle h + x )
. J6 F+ b% S# s( I9 E' P" }           (ycor-of turtle h + y ) 8 c: F5 H6 _1 d/ H. g
                          
( n8 r+ h" g4 M6 N) x                          
4 B7 N. o# r) R6 H# t; B7 X- a                          ]
9 r! D6 u- H& c& I1 }, cend
0 Q! k$ Q% z2 Y% d: `- ^! m3 j+ |( R9 m, k3 _/ N' A
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,; ^4 c6 a( |$ |
应该是3 r  s0 x8 k; E
ask turtles [
5 q# S4 ]0 E1 a8 Q, i* a- sif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
  [. V+ |( |6 {7 F6 |7 n- \2 w6 z                          set y  Dep / 2 ; U7 D" s, B6 Y! `+ `; J* t
           set b  int (who / 5) * 5/ U4 l+ ]4 f: Q% g9 K1 s9 c
    setxy ( xcor-of turtle b + x )
  G; W$ ?$ K$ O* Q          ( ycor-of turtle b + y )]]* B, k, o; G$ A1 a' V
end/ z( C* {! x' z5 @8 T4 Y
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-24 12:26 , Processed in 0.016009 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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