设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6328|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。0 g0 g$ M0 {' G' u: y3 U
: z6 \4 S1 D, V- q( o8 [8 E! T$ f, N
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。% A2 P2 v2 \. N, c' O
5 z- ?) D, `- V; A/ [
turtles-own [a b c d k f g h" G' M$ X# |, T3 s
  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
* \2 F4 Q2 L9 C4 l+ [' []0 S2 r: t' L! ]9 J5 o" x
to new
9 E, z* f; X6 V* x4 G* X9 k  ca
5 Y% X% s1 ^# ]* {! V, b" E9 n  crt 5 * num_of_building1 {- i* B4 n8 E' J% P
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]) M/ k+ J: D- r7 s/ t# g& d5 Z9 `2 @- T. x
  scatter     ;;keep center-turtle random positions 1 \( w6 I. N7 k) P
  unit_plan   ;;make up the building plan
0 U" y4 ^9 t. h- s5 H. o' wend" t' {- @! E6 z" p& N$ ~, D
to scatter
, @  P* @. c' g1 |  \9 t; Mask turtles with [remainder who 5 = 0]
$ t9 G/ }' j$ ?; |  _[, T# t" e1 G* U% G! b8 l7 P  s  ^
set xcor xcor - 6 + random-float 15( W# G. z6 X/ l/ p
set ycor ycor - 6 + random-float 15
2 r3 J1 c: B  z9 a, A]3 l: K* u  u+ f, h
end
  |! G6 h3 Z/ p+ L; C" Z2 q* `2 Qto unit_plan ! L: `; V4 B8 ]1 T" i' x# K
ask turtles [
' E' m6 V- O1 O% G! A: {3 ?if (remainder who 5 = 1) [set a who 5 Q: J0 r/ E; q: L
                          set x ( 0 - Wid / 2 ) 9 Z. P1 A! C! ?
                          set y  Dep / 2 ]; W* i- Y# k  C. d2 ~) x4 F5 D
           set b  int (a / 5) * 5) P9 v  ?! d) ?) J4 Q
    setxy ( xcor-of turtle b + x )
5 M9 n1 i) u5 f6 I          ( ycor-of turtle b + y )
) M3 H, n& S6 Tif (remainder who 5 = 2) [set c who
5 H. c. {% l7 @) A! g                          set x ( 0 - Wid / 2 )
" W8 t5 Z5 c: k, Z2 j2 J                          set y (0 - Dep / 2 )  ]' |$ g4 v! X, `; C
                          set d int (c / 5) * 5# ^# j8 J  _* Q
   setxy   ( xcor-of turtle d + x )1 r4 i4 U4 r* ~; I$ V
           (ycor-of turtle d + y )
: ?4 O3 K6 l' h" a8 k  Q         
/ p' o! y% F- a. R8 b            $ i( `8 N' e6 x' u
if (remainder who 5 = 3) [set k who
3 a# P' x. w2 H                          set x( Wid / 2)    a$ ^' T7 `8 n
                          set y (0 - Dep / 2 ) ]! k) i' V6 K9 p% V' [* s( Z
                          set f int (k / 5) * 5
/ |, K! k2 ?  R, g- I) o  setxy   ( xcor-of turtle f + x )
/ Y' u( ~9 |; P$ M- Y% a           (ycor-of turtle f + y )
0 [5 h9 E* J* ]% x% C$ g9 H0 y           
( U& ?+ X- ?( w, S/ s& U: n           
/ s2 l# i" Y4 n  J; z5 V  y3 T7 T, Tif (remainder who 5 = 4) [set g who) @# w0 ^2 }7 W/ V! R0 L
                          set x Wid / 2
* r$ P4 N# o5 c5 U                          set y  Dep / 2 ]- ~/ l9 j7 E* S8 _; q; m
                          set h  int (g / 5) * 5
4 g7 c- i( U2 L' e0 O7 ~( \2 t: A  setxy   ( xcor-of turtle h + x )* F0 b* S* G3 q# e
           (ycor-of turtle h + y )
, E$ B6 y+ G1 Y8 f                          
+ O' V2 u+ g% q                          8 a/ I( w8 U% ~/ y7 v/ {
                          ]
8 D2 d  l3 x  V; ]$ C+ g0 ]end5 f9 {$ N" p9 V6 K* a. ^8 M

* v* Q7 d) a# |[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,, B0 E& e0 {0 ?8 A4 g( K6 `
应该是% Z. [- @- O/ W% ]
ask turtles [3 M% A& s2 z, |6 E/ x8 Y( A
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
, h, ~, e. D! ^1 A1 p7 V  Z                          set y  Dep / 2
; V, q1 J  D0 V/ X  i           set b  int (who / 5) * 5
- p# S# Y% G& [" J9 U1 s7 G; f# d; ?* M    setxy ( xcor-of turtle b + x )" {4 l/ k  A2 a1 ~
          ( ycor-of turtle b + y )]]" \2 p7 z: D5 [6 _
end0 D: D. N( I; `8 s+ T* N
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-14 10:39 , Processed in 0.013948 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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