设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7380|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。" P, S/ X) I; I  X* h% S

, ~" p/ \/ F4 W+ L+ [6 y但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。) f5 t7 u/ U9 @% f" t% g8 N! O

, l5 c( Q  Q: j* g0 F; c; A$ `turtles-own [a b c d k f g h
* W5 |9 F# Y$ \( P  x y     ;; these are the leaf-turtle's offsets relative to center-turtle ( V  X) o9 z8 S& t' f- F
]
% [' x3 a1 C. ^to new
9 h4 {( j( r' i% M/ H" i" w( Y  ca! {6 t4 M; @& m+ P0 Q8 }8 ?
  crt 5 * num_of_building/ o* S; D7 @# @9 u( O% d( c
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
9 Z/ B; m5 L  D; u8 U* W! p( R  scatter     ;;keep center-turtle random positions / c) @/ v2 V3 Z+ j: M* c
  unit_plan   ;;make up the building plan
3 E: u6 K6 i" Z+ i, {$ wend" K! |& L# `3 @9 e) y, ]* W
to scatter- l) _: E3 h/ u* U* |) P
ask turtles with [remainder who 5 = 0]
' x& _) L; c) C) Z/ I3 o[5 k* B- e8 ^5 |* l
set xcor xcor - 6 + random-float 151 d8 _' e4 x5 ]( `
set ycor ycor - 6 + random-float 155 T  B0 H) _5 O  T" y
]
0 p, q) A% T3 O& Fend
9 U1 T* o9 x+ ^. j. oto unit_plan 2 E; R& C. Q$ p
ask turtles [# k: D$ C: {4 U! N6 l4 W
if (remainder who 5 = 1) [set a who   |5 X, Q6 @: h7 n/ \
                          set x ( 0 - Wid / 2 )
+ f7 ]+ e, W% o. H# |                          set y  Dep / 2 ]
% S0 f- A! R) n; }* ~" |           set b  int (a / 5) * 5/ u# J& V! A& n0 n5 l
    setxy ( xcor-of turtle b + x )% `8 L1 ]: S0 @2 |
          ( ycor-of turtle b + y )
8 R3 D/ G# S6 ]; ?( q5 [if (remainder who 5 = 2) [set c who% Z( m. B1 D+ m
                          set x ( 0 - Wid / 2 ) ! A# j, |1 C5 c! M; y9 I& r9 P1 F
                          set y (0 - Dep / 2 )  ]% w5 {; y, x3 j0 q- d
                          set d int (c / 5) * 5( x* q# ^5 M2 a4 s
   setxy   ( xcor-of turtle d + x )
  R- \" C+ ?3 @" n- X" q% }           (ycor-of turtle d + y ) ) ~  {! M5 J9 _+ k- C; K
         
/ ?1 r& R, y! J% n6 p+ P) `            % \3 x. n3 c2 e+ x/ S
if (remainder who 5 = 3) [set k who  M8 C* z+ g2 c" f4 W! g
                          set x( Wid / 2)  
. F$ Z6 ^) b6 P8 ?                          set y (0 - Dep / 2 ) ]
! k; @! e& M* o  w% O8 Z+ T                          set f int (k / 5) * 5. h! g# R& Q) L, h) ]5 F; U3 [
  setxy   ( xcor-of turtle f + x )5 Y( D+ w2 O  y4 u2 N& G$ N
           (ycor-of turtle f + y ) 3 f- z/ F' ^4 _- f+ @. Q/ z
           
! J5 x% t; s6 g9 R; _; e           ' d/ Q0 f9 C3 m3 B' S# U0 r
if (remainder who 5 = 4) [set g who5 a! f8 }1 P& S% u" d" {
                          set x Wid / 2 * B( y: h  Q6 \- Q$ J0 D4 m& M
                          set y  Dep / 2 ]0 O  @7 d2 W6 w6 o* J6 v( w
                          set h  int (g / 5) * 5
' N/ X5 a% ^) v* A. z  setxy   ( xcor-of turtle h + x )! ?8 d( l) Y  }6 |) O' T
           (ycor-of turtle h + y )
2 @$ ^6 \+ q- b2 r. }                          ! @: K6 ~( _3 U) A# H) z
                          , @5 j) B% s" E0 M3 P# z
                          ]
) I/ E8 W4 S! M5 Zend
3 A/ q  w7 n+ G" E
2 @+ W5 \2 P7 h3 c; |% M" ]; x[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,6 j- t; x- S1 P$ [* [& U
应该是8 J: Y7 Y9 p3 [& `* R0 D+ a
ask turtles [
1 G' }4 ^/ N: K/ m5 U$ nif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 2 k6 b2 }7 Y& T8 f# Q
                          set y  Dep / 2
1 o7 y* I2 g0 t4 p' V           set b  int (who / 5) * 5
0 j4 h+ Z: }% F7 l2 d    setxy ( xcor-of turtle b + x )
. X" H9 m* s9 `4 _          ( ycor-of turtle b + y )]]
0 I6 p% n! I  `/ ?end
( a1 j3 H+ L7 E" u- C之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-5 20:17 , Processed in 0.014968 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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