设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7291|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。; O# H8 Q( i! c0 n& K9 z6 Q
6 q, n0 V! ]1 C
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
( N9 z+ C4 ^) ^; i4 P+ H$ s! L
* L+ W- q$ h. C9 zturtles-own [a b c d k f g h4 x" [8 U0 h' J4 ?% C
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
$ C9 j3 J' N4 c* k]
! U2 f2 f) B; G3 J. A: C# Ito new
9 V" m- x! L( o7 F% t  M& o  ca
* T/ Q# y5 K* ~3 A; |) P, A* q7 T  {  crt 5 * num_of_building/ M1 k$ M4 L* Y0 D7 h
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]], G9 ~$ s& ~4 A3 U% B1 M8 ]1 t0 `
  scatter     ;;keep center-turtle random positions ) K: e1 p; A  d
  unit_plan   ;;make up the building plan
! V! Z- Y2 a; wend6 j& Q8 |5 Z+ i: s( A* W
to scatter7 u% Y  A* c$ u! W2 E/ E
ask turtles with [remainder who 5 = 0]7 c/ g* B/ s( x0 ~! N7 A/ F5 c
[" ~+ _9 e9 G5 a+ r( H- X0 S8 E
set xcor xcor - 6 + random-float 15
8 ]( ]' |! u- F8 ]2 ]set ycor ycor - 6 + random-float 15
+ m3 ]5 L1 F" D0 A' K]
0 S) J8 a  v4 V8 F; o$ T/ Vend+ W+ v, [. @5 Z/ [
to unit_plan
& F" Z/ l- i% S- B# xask turtles [
; b7 J  P6 P  {) Eif (remainder who 5 = 1) [set a who 4 H# z# M3 }! C2 Y) v* G
                          set x ( 0 - Wid / 2 )
, E' n2 b" z( p6 ?# E3 t/ r                          set y  Dep / 2 ]$ _! h+ Y7 O7 ]
           set b  int (a / 5) * 5$ \. D( {$ G3 ~1 k5 O- F8 l
    setxy ( xcor-of turtle b + x )" g1 j: I6 s! V7 h5 P% Y& r
          ( ycor-of turtle b + y )3 @/ H. ^: v% j  V, r8 }& A
if (remainder who 5 = 2) [set c who2 e0 N  D/ S0 s: |( V8 p2 z" v
                          set x ( 0 - Wid / 2 ) 0 V$ I3 {. ~( g( h
                          set y (0 - Dep / 2 )  ]/ C0 Z8 A& P, K
                          set d int (c / 5) * 57 x5 B- _- ^/ a/ q' F# L: C
   setxy   ( xcor-of turtle d + x )
/ }: v- z* V4 R           (ycor-of turtle d + y )
5 ^  b. c1 [& h          0 Y7 B+ j9 A) I# C" o2 f8 T& {
            9 l" B0 t$ x4 h0 K
if (remainder who 5 = 3) [set k who
8 P. k, L8 H  A; i! x9 G                          set x( Wid / 2)  6 j7 ~; Q+ X  n3 s7 r0 r
                          set y (0 - Dep / 2 ) ]3 L, T' L" ?) u( h7 m! h
                          set f int (k / 5) * 5  G+ z* e  _" D. ?; O# H4 {
  setxy   ( xcor-of turtle f + x )
, v- j3 N0 `* f( V1 M% N) n* B           (ycor-of turtle f + y ) 7 w+ ^: m) ?. {: ]
           
; h2 \& ^) \+ E+ P8 Y" T           ! w) v7 B5 k+ P% q
if (remainder who 5 = 4) [set g who4 b) W# a% X- P2 y9 o
                          set x Wid / 2 : l* O; L& k' p. w) q# R9 r( L$ ?9 u
                          set y  Dep / 2 ]
2 b- _( M0 T2 [8 S2 `                          set h  int (g / 5) * 5
1 R# e, V& _# c4 b  setxy   ( xcor-of turtle h + x )& |( f6 F4 j; h( q4 c0 O0 a
           (ycor-of turtle h + y )
9 u; y6 r3 I6 c% [8 o& x                          
) O4 F* J9 \# C                          
$ `; Y- N/ m9 s- y; o; q3 ?                          ]
( ~- X" k* T. ^( yend
: b+ H7 M- O: Z, f$ ?: [
  \! o' B0 v1 s, r" H& O[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
2 t8 S) w* J: T/ u2 o应该是, u+ X# C/ }% l# |7 Z( V
ask turtles [
9 |% D  g! H; ^: Aif (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
; S/ s- e) O) {. z% m                          set y  Dep / 2
% c2 G$ {4 A. U) q& k' [9 F3 d, a           set b  int (who / 5) * 5( x6 Z5 F3 p' y6 _; U* s
    setxy ( xcor-of turtle b + x )
9 V9 i  j: p. i, T4 Z          ( ycor-of turtle b + y )]]
$ V8 V3 l! n1 l% k" }  ~# {! oend% _2 X) q4 O$ ]. D) s0 V' k' u2 o
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-26 00:52 , Processed in 0.017632 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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