设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8931|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。0 j+ D& T5 z* v. x- T
. s9 w% D  S# R: Y) n- i
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
( ^! D; S. Q- D4 g  {. n6 h
! S  p. d8 A4 \7 T* ]- @4 [! dturtles-own [a b c d k f g h
) @$ m) l) {9 ~0 Z  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
6 S; |( a7 B+ f; d0 x; Q]% ~/ D# D  h0 J! i+ j0 O
to new
+ ?: F" g; C& j, a9 @  ca# d9 R2 h" L4 K5 R3 M
  crt 5 * num_of_building6 w+ S" R5 a; ]2 V/ {3 p
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]) Y+ o+ X! C6 |
  scatter     ;;keep center-turtle random positions ! R$ t  |' W) s) l( C$ L
  unit_plan   ;;make up the building plan
$ l; [, f4 |/ B# vend- n/ }$ B( @# |4 V
to scatter
& c8 i* s6 e" o+ g. uask turtles with [remainder who 5 = 0]$ w% V5 J3 {- u* ]% f1 V
[
. p! g. x8 l, L: Z( A4 S" I" u; Hset xcor xcor - 6 + random-float 15. A- {( m$ l  v& ^
set ycor ycor - 6 + random-float 158 s: P! p, R5 m
]3 _2 b" w0 ~: i  r
end
. e% u; R, e1 K; r* |2 `- wto unit_plan
( @( u) t  s, W: e# Oask turtles [
. ?' _2 J) R1 [* Y) jif (remainder who 5 = 1) [set a who
- J3 L) g0 z4 ^# g1 l2 `                          set x ( 0 - Wid / 2 ) / m1 K. K+ n% `/ H6 }8 A$ `: N
                          set y  Dep / 2 ]1 n5 q6 h9 N6 }7 C
           set b  int (a / 5) * 52 g0 [- m' l; J
    setxy ( xcor-of turtle b + x )( t9 F  }8 F8 p
          ( ycor-of turtle b + y )
0 c! C3 \# w- f: J# pif (remainder who 5 = 2) [set c who! V  a+ N7 P# p0 ]) P  ~% i) R
                          set x ( 0 - Wid / 2 ) . T$ R0 K/ r2 Q5 R
                          set y (0 - Dep / 2 )  ]
- j4 j8 s& v* ^( _- [( K                          set d int (c / 5) * 5$ i+ e$ @$ S+ e. y2 P' F9 p, ?6 ~
   setxy   ( xcor-of turtle d + x )  A' N8 T9 S5 ]! j" B" I( \- T
           (ycor-of turtle d + y )
/ y1 U6 Q9 v- [# l2 ]. _          7 a1 C" E; A1 D
            # u1 T3 t7 \& ^' v$ ^4 N
if (remainder who 5 = 3) [set k who$ Y9 Q7 o% `* Y. H" P* {# G
                          set x( Wid / 2)  ) [2 Y$ t0 F  P. C
                          set y (0 - Dep / 2 ) ]
+ ~6 Z. e# A* @                          set f int (k / 5) * 5
  j. q9 p- Q! D& q  setxy   ( xcor-of turtle f + x )6 j, m5 G, \3 o# y
           (ycor-of turtle f + y )
7 k+ Q' x/ {) I) D           . s6 g; v# z$ K0 [5 G4 j
             x1 l2 x# N3 w& q8 M
if (remainder who 5 = 4) [set g who; V/ o' h. }- g6 a
                          set x Wid / 2 % P: T( {4 b8 p$ v
                          set y  Dep / 2 ]
; h- p& v. S; q& s                          set h  int (g / 5) * 5% ^% a" n( e; ]
  setxy   ( xcor-of turtle h + x )1 L( r9 c$ ^, B9 o
           (ycor-of turtle h + y ) ( a* H3 S8 d8 x% A# K. G/ \6 }
                          8 ~1 l8 E7 G9 q! \' Y
                          
4 ?3 o1 k/ c( Q$ d( u! w9 ]                          ]
5 O' q, R! Z! T* a( W- ^end
, A0 g, C/ v" O8 S
$ ], ]' s$ t  C& T[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
) E# n. S( z! a% c2 e5 |应该是
5 ?0 f) a+ Q) V2 ~- y% H3 ]ask turtles [
. a0 Q  R3 c3 ~if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
7 e7 t3 R% d6 ]- G# {                          set y  Dep / 2 # V' ?6 V9 U2 ?- r5 a1 q
           set b  int (who / 5) * 5
7 q7 a! f: E" `; Y    setxy ( xcor-of turtle b + x )' }* I2 x. D- X0 ^
          ( ycor-of turtle b + y )]]1 S* G- a  m; D' k
end
: A  D6 Y. j, k1 H' u# p# C! A4 w之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-25 21:18 , Processed in 0.016216 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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