设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7190|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。5 g2 \4 M7 E) V% a/ L
6 k1 [! h: N- l6 P( {
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
5 D# d" [4 t- s, W5 v0 t: b( [9 i2 N9 C  J" e6 J( a' E
turtles-own [a b c d k f g h* A+ o" Z6 h+ J" j0 r
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 2 S! X0 |) t) d3 d
]7 t# y$ R( Z% ^8 \- R# Q# [1 Q7 Z2 B
to new; v" V( N) A* l
  ca8 C& m7 H. F. }# O8 u) V
  crt 5 * num_of_building
* Z; U  v% C* d1 d' S+ g/ d  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]], d9 [7 Y+ _6 P# T  E* o
  scatter     ;;keep center-turtle random positions 7 z( H& o0 x% [* q6 S6 v% \
  unit_plan   ;;make up the building plan
$ P+ O# c% ?6 P3 K1 Tend
! g: q4 O* W/ C- E( `to scatter  f! S# x' _; y  m
ask turtles with [remainder who 5 = 0]
4 d3 Q7 s+ H/ T$ P0 z[
9 S* K3 J- ~7 ~! Q! {( B" iset xcor xcor - 6 + random-float 152 n+ d0 [" z) N# E1 L& q
set ycor ycor - 6 + random-float 15; e8 N) ?" J8 h; S# m: k2 ^
]
: G8 X4 P7 h" J# `end$ a5 o+ l. \8 A1 S  w! k$ E8 ?$ }$ e
to unit_plan & g3 A1 t' Y! _
ask turtles [0 l8 V+ W) F5 k7 U# X
if (remainder who 5 = 1) [set a who # P6 A# X7 c+ i! Q
                          set x ( 0 - Wid / 2 )
8 ]8 e3 I6 g/ F% ~                          set y  Dep / 2 ]4 u, d5 c- n8 r1 [0 C
           set b  int (a / 5) * 5
9 n. }( m4 G) |% }8 Y$ J    setxy ( xcor-of turtle b + x ); U" j* U) d+ B, r, ^
          ( ycor-of turtle b + y ); c) w6 a6 Y1 p# o- T
if (remainder who 5 = 2) [set c who
) F$ [# n* M9 V& T5 t+ l4 j# m                          set x ( 0 - Wid / 2 )
4 J2 Z  X$ b; C* o3 W                          set y (0 - Dep / 2 )  ]0 d! G- X: x7 z7 D
                          set d int (c / 5) * 5/ L7 J( n* q7 |
   setxy   ( xcor-of turtle d + x )
& m2 `7 `! M1 N3 m" I& T           (ycor-of turtle d + y ) & k  x) n8 H# v! h6 A/ x
         
$ J9 v2 F# }: P6 L" g# C            
+ R; Y9 y9 C+ V7 Kif (remainder who 5 = 3) [set k who3 C5 _4 A3 p7 x" |  Q' o9 f! A
                          set x( Wid / 2)  5 k" e! z) p/ ~- D6 h: H2 |
                          set y (0 - Dep / 2 ) ]2 `! _& N: J- T$ l! @
                          set f int (k / 5) * 5+ A4 k) \1 y: K5 d" d
  setxy   ( xcor-of turtle f + x )/ P1 l6 C4 b2 d
           (ycor-of turtle f + y )
& y( ]' A5 |8 ^3 k8 u' D8 Y; o           / g# `0 ]+ p$ H9 A! v7 m
           
2 T: f% `+ J9 j7 |; K/ [: s# x$ vif (remainder who 5 = 4) [set g who
9 H3 O. f& p6 u: v                          set x Wid / 2 % i( p8 {0 D: j, S
                          set y  Dep / 2 ]
- o) Q# K4 z  ~4 P3 l0 f4 t0 t, ?                          set h  int (g / 5) * 5
+ X" q& e6 M( W8 F/ ^7 R  setxy   ( xcor-of turtle h + x )* _: O5 H, E( `
           (ycor-of turtle h + y )
- @+ ^0 F. t* a+ R/ v) c                          
( N& D" f' E' t1 n' T) ^, n3 e; E6 Y                          
5 R* e, s! d& F7 |6 g                          ]$ V$ J+ h0 ]+ i2 U" k9 i
end* b( Q7 |8 r! T1 Y
4 g8 A- |8 l- ^
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
% Y. r7 n$ ^% D- J  U9 s" b: ~应该是8 t/ o2 y0 ~  u1 h1 z$ m
ask turtles [% ^" k& _" q/ p% D) [! ]
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
! F3 ]& i2 R6 i; b: I' Q6 |5 a                          set y  Dep / 2
/ G7 J! D7 j# M, T1 g/ r           set b  int (who / 5) * 5
7 \4 U4 P" }# T9 U9 w$ X- p. M3 R& b    setxy ( xcor-of turtle b + x )
0 o" a1 y6 V* d8 A) Q8 G; T          ( ycor-of turtle b + y )]]
) {% K/ N) l6 H: W6 k3 oend! L! P  Q4 v8 ~1 l, t
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-14 22:07 , Processed in 0.015146 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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