设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5933|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。' D( d- C! I4 O# \- k
' V3 K7 L) s9 g
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
8 `7 F: n; }) Z, Y5 m% Z) ?4 i6 _* U# X: A
turtles-own [a b c d k f g h
" r" `3 `$ m+ I' \  x y     ;; these are the leaf-turtle's offsets relative to center-turtle % T9 S5 E" w, Q% u
]
3 _; M% y' e/ r& \/ Eto new9 q# n8 y2 o- h- G, `, l
  ca9 H( O% ]$ p% d' e8 R! c6 N
  crt 5 * num_of_building
" a: F* ]  W/ G& {4 p1 c( t  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]2 z# M3 R% n5 Q, c; v% Y# z; W& u! c
  scatter     ;;keep center-turtle random positions 2 D5 `$ ^2 C; i. y3 E7 L' ?
  unit_plan   ;;make up the building plan& d- f; [: y- A
end
' U* Y. p# l  |+ Kto scatter: Z  x8 L- ?+ [4 ^5 m% C6 n
ask turtles with [remainder who 5 = 0]# R) y. `7 `5 R2 d7 E' k8 S+ \
[
+ B4 F/ M. D* S4 [set xcor xcor - 6 + random-float 157 L4 w' w; p! M& N+ @
set ycor ycor - 6 + random-float 15
/ @/ u  l# G! Y]0 K; I5 s! W, A( w
end
! w! t/ E5 L  Z: M% c* Gto unit_plan * G3 J1 W. p0 e7 X6 w6 k
ask turtles [
4 f# ]) }/ |: V& D# x) u# {if (remainder who 5 = 1) [set a who
, o+ Y/ `0 P" w* Q; S                          set x ( 0 - Wid / 2 )
+ L, r, g/ n: C4 f                          set y  Dep / 2 ]# `. @2 H1 i  a1 ~* [
           set b  int (a / 5) * 5
6 G! C# q7 h# Z    setxy ( xcor-of turtle b + x )& T0 Q, T! R/ N- @, W
          ( ycor-of turtle b + y )$ J  D  G; d+ v" x. I
if (remainder who 5 = 2) [set c who' T) U) Y: z" N9 g# z# \6 v; [
                          set x ( 0 - Wid / 2 )
0 J9 P2 h* F- H' `6 j" ?) S                          set y (0 - Dep / 2 )  ]/ X1 W1 V5 s2 x, u% b* K" \2 y% }
                          set d int (c / 5) * 55 k+ k2 ]2 Q! |- c
   setxy   ( xcor-of turtle d + x )
* Z6 D) f# `  U( ?           (ycor-of turtle d + y )
; s9 m# @- p& L6 `5 X" R         
& V5 t) H* P/ k7 h% }            
, g+ ~  F1 q- p  k3 W$ ^if (remainder who 5 = 3) [set k who
+ s& ?; Q- l+ L0 K6 C5 }+ q1 t8 k6 \                          set x( Wid / 2)  
! p: k- c1 W0 [; M+ O                          set y (0 - Dep / 2 ) ]4 [# x/ R% e$ ~: j2 \
                          set f int (k / 5) * 5
4 v7 r6 p$ ?7 [! M  setxy   ( xcor-of turtle f + x )0 I8 u  k, C6 \
           (ycor-of turtle f + y )
% @" K' `2 ^6 A5 k0 W; Z7 X           5 B( B* f% C- e5 h. S1 E
           
% x! O1 j1 G, `  Z1 o4 X0 Eif (remainder who 5 = 4) [set g who5 P+ A# c2 t% h
                          set x Wid / 2 1 q% E/ ?- `4 |2 v- p
                          set y  Dep / 2 ]
. r) |: g8 H& P( R- n; K                          set h  int (g / 5) * 5$ d; J7 V. J; p4 ]  ~. B* L
  setxy   ( xcor-of turtle h + x ); f' L0 _$ c$ e; h6 c
           (ycor-of turtle h + y )
5 _3 k8 D2 Y9 H* {7 d                          
. ?" J) y  E7 u7 E1 u                          
+ C* ~3 U4 @& v8 m$ D' v" P6 c2 g                          ]
* E' ~3 i! g" B# t4 b9 n5 Lend; a+ W) Z' \3 S5 r  V7 ]
  |: U+ O! A5 P) O$ L
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,5 V  G  p( D6 Q3 l1 B5 P
应该是8 f! s; x) g4 M2 e4 A! Q. n1 u
ask turtles [
+ l. J. M, {* ?' I5 ?! s* _1 J( Pif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) # r( X- c7 Q& j3 m1 k( l7 S# M5 s$ e  Y
                          set y  Dep / 2 4 X* g" }; M# X' I. I" ]
           set b  int (who / 5) * 5$ I" I0 ]8 y' u( t3 t* U2 b1 N6 L
    setxy ( xcor-of turtle b + x )
3 H7 H' {& z# `5 `- w) Y9 J          ( ycor-of turtle b + y )]]' H. m& D# @/ c" ^
end
3 G. S' {7 g' C* ?4 Z! Z$ v$ Q之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-7-7 06:11 , Processed in 0.015460 second(s), 16 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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