设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8464|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
, n# ^2 D! @. U% G7 i6 n' e9 w8 i
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。8 o* |+ A8 h' P) U, P, |0 n# {- T
9 z- z) ^! X9 g$ B0 i7 C8 l  n5 K
turtles-own [a b c d k f g h
* d) K4 |; V6 U; O! ^1 }  x y     ;; these are the leaf-turtle's offsets relative to center-turtle - g# V% M: f+ M" V
]
5 a1 B( J; E5 y7 l% ?( ito new% b1 K) k0 D1 ?2 [5 L
  ca* l% y( V8 p* l7 [; b
  crt 5 * num_of_building2 X" |* g9 J2 y: N: E& p
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
- z0 W7 w# U& N" ]1 T# m' @  scatter     ;;keep center-turtle random positions
" C7 b- N' n4 _5 g4 R  unit_plan   ;;make up the building plan) I, c3 f. P1 E3 O" J, W5 ~; D
end
) y* F6 a2 X: @% ]& k+ xto scatter8 A9 h2 C6 l! e2 d  ?% w2 x' m
ask turtles with [remainder who 5 = 0]
* @3 ]: ]  ~& d; k5 V2 f. s2 A. a[
+ Y* M8 t. B0 N9 N  v. \  [set xcor xcor - 6 + random-float 150 N6 s# ^7 \3 ?3 P# \3 |) q. f: O! y
set ycor ycor - 6 + random-float 15
2 E, U% p7 C$ \- n' d5 Y]
/ T% n  ^  H5 O8 uend
" n9 g4 `& P1 z4 b# {to unit_plan
$ G, o. ?2 `, eask turtles [
( j; A% l& o4 Y5 b6 Wif (remainder who 5 = 1) [set a who : r' r- R4 _" q3 I
                          set x ( 0 - Wid / 2 )
6 ~5 Z! [% a' `- z                          set y  Dep / 2 ]
5 V0 [; J7 k4 g' @5 M% x$ d5 V% i4 d           set b  int (a / 5) * 5
9 f6 I3 m/ U2 Y+ J    setxy ( xcor-of turtle b + x )! M7 X- a( N& v  A$ |2 S# U
          ( ycor-of turtle b + y ); H0 S7 B5 V! y' G8 Z
if (remainder who 5 = 2) [set c who/ y3 V9 Q& G# c+ _! C
                          set x ( 0 - Wid / 2 )
; {0 Q6 P( u1 q( z/ u% J                          set y (0 - Dep / 2 )  ]$ ~* ?( a- s: b4 K( J+ }3 R: q1 s& Q6 m
                          set d int (c / 5) * 5- s2 z  f. u( J  x
   setxy   ( xcor-of turtle d + x )1 X5 _" L& `9 ]8 q6 o/ s
           (ycor-of turtle d + y )
: }7 Z; j% C$ R         
$ t# j- T$ x7 R3 C            1 u" ~! `  o2 K: G. G
if (remainder who 5 = 3) [set k who
& q* V2 Z/ R7 B/ p                          set x( Wid / 2)  
( X8 F. `9 S9 g                          set y (0 - Dep / 2 ) ]5 i6 u) l2 [' |0 R
                          set f int (k / 5) * 5+ n9 B0 z, G6 e6 K+ D5 K
  setxy   ( xcor-of turtle f + x )- m8 G$ C' B& T, ]! j
           (ycor-of turtle f + y )
4 m" H5 q1 s0 d& Z* I/ b% l$ L           3 I# B% s: f8 I! f
           1 N. I4 D1 Q4 v7 Z% }
if (remainder who 5 = 4) [set g who1 X6 h9 Q8 _: t: `
                          set x Wid / 2 $ M( n" T; o7 J; [
                          set y  Dep / 2 ]! z/ K8 v! [5 G& n5 p# i9 F
                          set h  int (g / 5) * 58 a0 Q2 y$ W) o) P/ a9 S
  setxy   ( xcor-of turtle h + x )2 C6 q' z2 w" m/ o
           (ycor-of turtle h + y ) , n$ b8 p) x3 S% [7 B# N/ N2 R
                          
% _' }4 |' R7 a7 o8 T* \$ |                          
& \7 p* `3 {! G3 A                          ]8 `3 i" o4 q. O0 C
end
- q; V- h( y0 H
8 G6 g7 l) ~! k) I  D, L: `0 }+ C[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
0 K1 w$ q) v9 q7 o) V应该是6 N2 R$ T0 f2 f$ G% O: e
ask turtles [' G- A/ f( {/ x+ a# F! H
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
& \1 f. v$ E7 C8 L% u9 f! c                          set y  Dep / 2
6 }. C  }& |4 b1 V  P2 \           set b  int (who / 5) * 52 T' @7 I8 F& H+ T6 C
    setxy ( xcor-of turtle b + x )8 a2 D) C/ [7 o( I( R% u- d! t
          ( ycor-of turtle b + y )]]
2 q1 L& p7 }( ?! N" Z: i2 wend: _4 E. ]1 D$ P0 |& E' K- ^
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-6-29 21:40 , Processed in 0.015028 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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