设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8181|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
* }- D* `+ h+ |& l% ^: e2 v
+ Y; Z* q% \2 L0 @8 z9 L但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。: y( z9 i2 P0 t  w+ p* @
; ~. G' m- m  t
turtles-own [a b c d k f g h' z0 Z* g" p% `9 @; L
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
0 h- B* s% ^7 H% i" a]1 G9 ]* [2 q# C* R+ D; |
to new
. {3 l! ]( I+ g/ U; \  ca9 P% X2 L- N6 q# b  @
  crt 5 * num_of_building3 \6 y$ e0 ~( p, j, Y- S
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
. N3 C1 O  X4 _! o8 Z- Q  scatter     ;;keep center-turtle random positions
3 `4 E" a1 D# ^/ x& y2 x' F  unit_plan   ;;make up the building plan7 v, l5 g+ j$ {( p1 \5 Q
end
8 M1 \) `7 A; L3 kto scatter
9 ]8 \% t4 _; u1 N) D& Pask turtles with [remainder who 5 = 0]
6 C1 d0 l1 ~4 p' A: v* ~& |[
* ~& x9 P) Z( fset xcor xcor - 6 + random-float 15
" G6 T* T3 ~6 wset ycor ycor - 6 + random-float 15, J, e4 y% A" G0 |
]5 Z9 G0 H, `2 V1 r; M' Q* z
end, h* v4 j/ B( J) @
to unit_plan 1 V2 O4 d0 i7 q
ask turtles [
4 Z' ~% B6 r0 N. Gif (remainder who 5 = 1) [set a who
3 w+ F* ~" ?1 c                          set x ( 0 - Wid / 2 )
: L: N/ S0 W9 `2 l                          set y  Dep / 2 ]
+ ~4 I" A( x$ U           set b  int (a / 5) * 5
: O& \9 K% M/ }" Y7 k    setxy ( xcor-of turtle b + x ): B& \/ y( z( X9 W  X
          ( ycor-of turtle b + y )" l: U# M. x# C
if (remainder who 5 = 2) [set c who
# E3 U4 d( w3 T: f" J% K" z                          set x ( 0 - Wid / 2 )
$ F4 T( t! A# f& I" C8 G- c, t, V                          set y (0 - Dep / 2 )  ]
! M8 L3 o9 d7 x' D+ g* g% c                          set d int (c / 5) * 5' D! u5 a* z& ^6 A- D# ?
   setxy   ( xcor-of turtle d + x )
! v, k$ R1 `( x2 d5 M           (ycor-of turtle d + y )
- x8 W: q9 i6 |; D         
+ ~$ N/ C8 h; N( n$ R5 z0 S            
. [  a' H% d$ q" J- ]/ rif (remainder who 5 = 3) [set k who3 v' b+ H6 f- U% M: H+ q1 u; k6 H3 i
                          set x( Wid / 2)  
% K$ u1 C4 `4 l( K4 {5 S" Z                          set y (0 - Dep / 2 ) ]
! F; }/ O, C( P# S0 ?; V  e" I+ m                          set f int (k / 5) * 5
2 V5 ~& i  G4 y# z( ~  c- }) |* U  setxy   ( xcor-of turtle f + x )
: P' K$ s7 ^) n1 u# L           (ycor-of turtle f + y )
, ~7 ^/ G' A! d! K( w7 S2 q% W           
8 e* y4 y, i8 n" }. x  b           
& S" y- P" G6 l9 F1 h7 Cif (remainder who 5 = 4) [set g who
% I2 S- ?4 }- [9 |                          set x Wid / 2 0 e# I3 m) o$ X! R
                          set y  Dep / 2 ]
7 g2 C( c1 p, ^% x3 _                          set h  int (g / 5) * 5
. W/ E5 B$ K$ n( G, c0 b; R6 g  \' M- d0 k4 n  setxy   ( xcor-of turtle h + x )9 p8 [' l9 L+ ?! A0 l1 z3 g3 ]( \
           (ycor-of turtle h + y )
2 K( `1 l+ E) N2 L                          . x' I4 l+ H: T$ W6 [
                          
( r- ]: m  B* B6 @1 q                          ]2 p8 [9 y; [5 Q' |
end% P1 `- U% W; _( g$ s) k' p

, n5 f& n5 i0 V. A$ l6 b: B& a[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,& x, p& j( k/ ^
应该是" G9 B5 e5 M! `
ask turtles [
+ Z7 J$ w4 n5 l% uif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) 3 Q2 V3 }/ |: |1 S" |! u
                          set y  Dep / 2
$ J3 `/ Z# T6 {+ I4 R9 |- ]           set b  int (who / 5) * 5
2 j) I" s* [8 g; {2 O  x: }& p    setxy ( xcor-of turtle b + x )
0 H' a  [0 ^4 O6 O  @3 {          ( ycor-of turtle b + y )]]4 ^$ Y. }0 m- f' N9 v9 R
end
( e  o' G( j4 c1 x2 B之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-15 12:14 , Processed in 0.021353 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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