设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7947|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。6 t, f7 @, h% N% h" T

% ?  H9 G( r% r9 j但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。2 S2 l' C, l  S7 `( @0 c+ \& K' q

- Q3 J. N: l7 |: mturtles-own [a b c d k f g h
; g7 M1 E; ~* E1 E& ]6 J  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
' z* H6 s/ y5 p( Z]
# o0 I% v/ c! z6 A. ~& H* F' Y- `to new9 @0 ^  g% U7 |( J- y
  ca
5 \/ @2 i& d! E5 |9 `$ r2 e9 r  crt 5 * num_of_building
( Y) N/ F7 F9 H! @  }3 S  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]3 Q+ k- S& p: l4 C+ m9 d
  scatter     ;;keep center-turtle random positions
9 R* O( s* U! T) T3 V5 a0 q! p- y  unit_plan   ;;make up the building plan5 B4 Q5 D4 e7 F
end
$ M. {' C: L. }/ w5 U) Cto scatter
" E% u. a" a4 r* a/ ^6 l% d' wask turtles with [remainder who 5 = 0]' E) D0 k/ {  t
[& v. H3 O! F1 g( {
set xcor xcor - 6 + random-float 15
% T0 D# b) f" P! h6 pset ycor ycor - 6 + random-float 15
* ?- f  n# e$ D]
9 f) F3 n6 c6 _$ F- ^6 oend
$ x5 m. ^' F9 o& i6 |to unit_plan
9 X. s- g/ k3 @5 l4 K2 Dask turtles [' L  p  \7 o3 e  G0 L( Y: C
if (remainder who 5 = 1) [set a who
0 A# f& [& S, n3 s( `. A4 i/ r                          set x ( 0 - Wid / 2 ) ' u  L0 I2 M% Y; v
                          set y  Dep / 2 ]3 S; o$ G7 H# v  N1 X
           set b  int (a / 5) * 5
$ S2 Z2 J' _4 B7 g5 q, m    setxy ( xcor-of turtle b + x )
7 u6 w! c: \2 v% C; E" R9 O          ( ycor-of turtle b + y )
2 y# W9 s0 R7 ?: v4 P# u5 P! Dif (remainder who 5 = 2) [set c who( y5 D1 }' Z! _: t) t
                          set x ( 0 - Wid / 2 ) ! r' a( I9 n' l  v; _
                          set y (0 - Dep / 2 )  ]. K$ a" n) O% C! `- D: b
                          set d int (c / 5) * 5
( x0 h6 a3 j- z" h3 m   setxy   ( xcor-of turtle d + x )+ L8 D0 o/ [( S. V- D# g4 a
           (ycor-of turtle d + y )
: Q  w' p$ G8 G6 ~3 n# H' h# X          9 _0 S6 H$ D6 _1 h) q2 f
            
' a5 b2 `! ^. K" k. A2 K4 _if (remainder who 5 = 3) [set k who
# J: g3 ~5 R0 s# S, @                          set x( Wid / 2)  
+ J1 H7 T9 O( E! I# Y9 [0 c                          set y (0 - Dep / 2 ) ]
$ C" L! y( W( J4 y* I" N  v% }                          set f int (k / 5) * 54 z! ]0 n9 a7 `7 p* }! i
  setxy   ( xcor-of turtle f + x )( ^# C4 h6 @- m4 O4 W+ B
           (ycor-of turtle f + y ) 7 R! q- \. L- }
           - f) h2 Z: _4 C% }% N( u
           8 k  K! W8 N- K2 d; H
if (remainder who 5 = 4) [set g who
2 P0 V# M0 _" X                          set x Wid / 2
* o! X' P: N  t3 a. M* B8 Q$ ~                          set y  Dep / 2 ]" Y6 c9 K* E: m! `- k
                          set h  int (g / 5) * 5
+ S3 M! g* P- f) ?; H  setxy   ( xcor-of turtle h + x )1 _. r/ R# `9 W0 N$ c# e
           (ycor-of turtle h + y )
- J) b8 z+ Y; p5 t- X7 q: ]" L                          
/ [2 W, G% W% a' M                          3 f$ y! F1 P# L4 A- a1 g
                          ]
3 I0 x0 d& z5 \( A3 k# I$ {end
" `, S, ~" A1 e6 `: d8 i
- V1 f* m' a# r- `3 X3 s. Z* h" O[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,1 a7 Y, _' L# n# t9 W" V8 D* Z
应该是
' f4 H, h5 s4 ]. Task turtles [3 q# x" {) I2 ~
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 0 h/ C5 D; ]9 x2 S  o' _7 P
                          set y  Dep / 2
% A- }. b4 W: L           set b  int (who / 5) * 5
$ h0 M; E- n: y) D: _- k    setxy ( xcor-of turtle b + x )
$ C2 u7 Q$ v$ b8 b          ( ycor-of turtle b + y )]]
; A+ G" |9 K: fend
; U* F$ h6 Q8 J; v! K0 ^7 Y" x之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-20 19:58 , Processed in 0.019973 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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