设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8989|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
. e, b4 X; R& e8 e& J' d- T  B% W/ F' I7 q6 `) U8 d
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
9 j3 _# X; c/ K' W4 g/ |" ?8 _( k
turtles-own [a b c d k f g h
- t2 N: x" [  w2 m) a# l( G+ c/ ^; {1 U  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
3 c$ b: M+ }. r* r]1 r" r7 s3 A+ o# H# L8 F( z
to new) Z2 L0 p7 |% v0 o9 N( r  c
  ca
6 G8 D# y0 ^+ }5 l7 a# Q+ b  crt 5 * num_of_building
% ]+ E6 T  C. O6 O( h  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]' E* ~2 K, [) Z+ ~& q7 w
  scatter     ;;keep center-turtle random positions * t+ P( x' A" }! J# \
  unit_plan   ;;make up the building plan6 y) X+ z; a& S: d5 W
end
1 d- r5 m9 `% o* U& Fto scatter# c1 w* g' U& @, j) g& E8 n3 R
ask turtles with [remainder who 5 = 0]
/ `. n+ t( P# L7 q* N[" H2 r1 E7 A% |
set xcor xcor - 6 + random-float 15! c2 }" J5 H8 F( ~+ r" K- e
set ycor ycor - 6 + random-float 15; l4 m3 Y% G$ A' X) R: b& v% W
]8 i5 z! P  N0 l3 b4 h
end& d$ P2 ~; p- B, K# [
to unit_plan ; z$ x0 u0 T( Z, n* C+ Y" {0 w
ask turtles [7 V) I/ \3 P' W: ]$ C
if (remainder who 5 = 1) [set a who
9 K& H9 t0 `1 Z6 m8 D; C                          set x ( 0 - Wid / 2 ) 1 C- N2 R0 O. b- t
                          set y  Dep / 2 ]# b8 h5 T9 _. j" n
           set b  int (a / 5) * 5
1 [+ k! k+ G/ J* `! V! E0 M* w* W    setxy ( xcor-of turtle b + x )
0 A7 x& w0 R8 a9 e          ( ycor-of turtle b + y )- [$ A3 Z4 N, S; N6 F* E" z6 m
if (remainder who 5 = 2) [set c who
5 e  I9 z& h; E: }- @( b3 V                          set x ( 0 - Wid / 2 )
4 V$ Q7 P( a4 }/ v# C                          set y (0 - Dep / 2 )  ]* r* l# \6 B; y) [6 m* b
                          set d int (c / 5) * 5* g2 L0 W6 s) z+ p5 p
   setxy   ( xcor-of turtle d + x )
4 ~# T5 u& h! h0 C           (ycor-of turtle d + y ) % `7 \; q' A# D5 c8 t" J, q2 |
         
" \9 H6 r( D" y. D) f& j! X% s  I  ^            3 Z. y2 }$ z. |2 j3 s# w: l
if (remainder who 5 = 3) [set k who/ D; u2 Z/ l0 R* b( p
                          set x( Wid / 2)  6 G7 \: p* o" a7 j- @1 O5 r
                          set y (0 - Dep / 2 ) ]9 O5 l  a; I2 I/ s
                          set f int (k / 5) * 5
3 Q" m' a5 L: J4 E2 d3 F% B  setxy   ( xcor-of turtle f + x )9 H  k2 I0 Q' [! Y2 S& T
           (ycor-of turtle f + y )
5 b% S; _. z/ H7 ]' t- Q& \           
0 a/ N0 w, z( V, G; W           + @$ Q9 A) o5 m8 p! w! u5 _( U
if (remainder who 5 = 4) [set g who4 D) {) h  B1 |/ p4 r
                          set x Wid / 2 / |6 e$ F! t7 e
                          set y  Dep / 2 ]# F- H( {# p$ v5 V# E5 E2 k
                          set h  int (g / 5) * 56 t; b" Q; O3 d$ g3 |- n9 M
  setxy   ( xcor-of turtle h + x )
% O) b0 p# W9 h% [& f           (ycor-of turtle h + y )
9 R. G( z; o: F  I                          
! c" s, L! l8 Z                          
0 R& p+ w9 X+ C% r8 Q3 B5 F9 |: R+ N                          ]4 Z% l8 A% t2 F
end
3 h# r5 p8 G0 W( P& Q/ x" D
# ]  y& m2 N+ C[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
3 N0 d$ h# f8 K应该是
" {' b/ `8 W: W6 Jask turtles [
  k( W6 D* E( f: p& n7 |; }if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
8 X' S4 L; r) _) }                          set y  Dep / 2 . O8 _* _, y" [" K  W, n
           set b  int (who / 5) * 51 I+ X3 a5 Y- |0 A3 U
    setxy ( xcor-of turtle b + x )4 W, K$ _4 N5 b
          ( ycor-of turtle b + y )]]
7 S3 }2 A& L" pend8 S: [8 ~, k" O! g
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-3 09:34 , Processed in 3.924875 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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