设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7960|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。& y1 g( f+ t. @
$ z" e- L3 T4 R, i& u
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
9 ~6 n3 b; W- ^! q" M) Y0 @7 }% |4 D2 |1 P% `% z9 y6 I
turtles-own [a b c d k f g h
8 x" m. ?, t, D* Z) H  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
* N4 \( R$ i! y]5 u( h$ v2 y8 E; |: g
to new% z& Q5 \4 U6 _2 l$ K
  ca* a. k9 ^6 c, r* \: k$ `
  crt 5 * num_of_building
, h  x9 o' ?( i  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
1 O% k1 @' @2 A. }' F  scatter     ;;keep center-turtle random positions
5 ^- V8 H4 M5 f8 {# e+ p4 q/ _8 w0 i7 C  unit_plan   ;;make up the building plan
3 ?. P4 D- E- _( `, Rend" c, C8 ?' W# R  j: q: ?
to scatter7 }5 u: f3 |. d0 q* |) n1 p
ask turtles with [remainder who 5 = 0]( O1 a0 J, W2 z7 p4 L) d3 r, f
[5 p  [7 G$ g6 L, f/ i
set xcor xcor - 6 + random-float 15! P1 i$ }6 H7 e0 Y: I4 A
set ycor ycor - 6 + random-float 15
5 S9 Z, _& k  n9 O5 [, ?$ U- @]
3 {4 J' }! u2 M+ b* Kend
1 J3 ?" e0 G1 S, i+ l! a7 mto unit_plan
& n4 ?3 p- m! c1 p+ Oask turtles [
) o9 I& V" ?8 }" f2 M- a; ], J) yif (remainder who 5 = 1) [set a who ! B4 V$ m* c# n  q( `
                          set x ( 0 - Wid / 2 )
7 W3 R& m# `1 s4 R# p! h                          set y  Dep / 2 ]
+ r" a4 Q: E0 v1 i4 J           set b  int (a / 5) * 5! G( s8 J% }! X- L: s
    setxy ( xcor-of turtle b + x )
$ I2 Z* j$ a5 E( P3 C          ( ycor-of turtle b + y )
# n" ~3 x( e4 Hif (remainder who 5 = 2) [set c who
0 q  i5 L  \7 b) g  x5 N                          set x ( 0 - Wid / 2 ) ; C4 V6 z+ U) @" w
                          set y (0 - Dep / 2 )  ]
( A) D" q4 S- ~3 ~6 ~# t                          set d int (c / 5) * 5; y1 v( P% v: V: v" L- P, w
   setxy   ( xcor-of turtle d + x )$ }  b) T$ S' f9 \8 [) x, p% i" r
           (ycor-of turtle d + y )
) z. b3 H7 @" N$ S         
# a0 H  \/ v) f1 }7 P& z. h8 U              L7 M" z7 f% |* E2 N
if (remainder who 5 = 3) [set k who
3 k  K, Y) W% y7 N                          set x( Wid / 2)  ) G+ I' p+ ~. K2 Q5 f
                          set y (0 - Dep / 2 ) ]: t! r" L. |& Q- D9 h
                          set f int (k / 5) * 5# [! L8 s; r! ?: d: x
  setxy   ( xcor-of turtle f + x )
/ j! t' H6 e& r  S2 I: n" F           (ycor-of turtle f + y ) , }6 V9 X* L" ^! x8 i
           
# T- [0 m  B# E% ~           . F7 o; T! R+ x' b$ Y3 Z
if (remainder who 5 = 4) [set g who) o+ S/ z, {& H4 p1 G
                          set x Wid / 2
3 T* q) ~. u. l' I- i                          set y  Dep / 2 ]
/ N7 V) v+ T9 f3 X: U! T+ }4 I3 O* L                          set h  int (g / 5) * 5) U) A5 X9 T- Z2 D! i. D
  setxy   ( xcor-of turtle h + x )# p8 @9 i! C  j8 K  A7 N: {4 F
           (ycor-of turtle h + y ) 1 f( c/ F) x1 E! [8 _; y2 q* _
                          
3 w5 y1 B! x2 Z/ q! V                          ) R! \2 {. a% x! |/ V* Q2 h
                          ]
. T, I' A& H8 r( Lend
3 o# H" E! y0 `8 P/ k7 _+ L  `& X: t6 g" v: M
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了," s4 W4 m4 U: e4 M
应该是
/ e/ ~" B: V6 ~0 y. _) Rask turtles [8 I$ _% P( b. `( {
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
* Y5 x/ a4 @# ^7 m5 ~3 d0 b, S0 `' f                          set y  Dep / 2   w7 h0 v. x0 J/ x% X
           set b  int (who / 5) * 5! z" n5 J: b5 X6 D$ c6 B
    setxy ( xcor-of turtle b + x )
  z; L* i. p% ~3 P          ( ycor-of turtle b + y )]]
4 \0 m! m' O- @9 C, T1 Cend- r: \* Z2 E, a* G& M5 j
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-22 07:21 , Processed in 1.172758 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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