设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7440|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
" }7 M+ W& e) v+ f, t0 u" Q: ]4 U: h, K3 l5 u+ J7 _
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。. F) k3 j1 E4 [+ k
: o% k7 G2 Z/ P$ e( l# {
turtles-own [a b c d k f g h
$ e2 M& N1 e2 U, V- E; G5 i  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 8 \% Z, }" x; d! V( }0 u8 W
]5 f- E  l$ u; e( c' e5 e
to new
: ]9 y, m* q' g  ca' n* a5 ^  Y. Z% w. b% d
  crt 5 * num_of_building
, F9 i2 Q" J1 U( D  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
; ~: W4 T! p, P1 [  scatter     ;;keep center-turtle random positions : C" m5 B! S2 O1 ]1 {  P
  unit_plan   ;;make up the building plan5 M! q0 a* \7 t  ]/ {$ n" l
end
! z2 ~( \" p/ q1 @4 j) T4 ~) G7 [to scatter
: R+ z& s8 c* f  gask turtles with [remainder who 5 = 0]& a- V! x5 v3 R6 |+ R% W4 T5 }
[4 N3 u7 G! B' W- O
set xcor xcor - 6 + random-float 15
+ o: t3 e9 o* |! X0 N) m2 Tset ycor ycor - 6 + random-float 159 @2 i) _+ `2 j3 O# S+ h
]; f/ L- k( }0 L6 U
end9 r5 O- t, s; g
to unit_plan 2 l1 p# J  P  X& f4 q
ask turtles [
7 L% O0 f$ ~- O2 ]9 D! Q2 D  Rif (remainder who 5 = 1) [set a who
0 ?8 u4 V& V' W; A5 q/ Z                          set x ( 0 - Wid / 2 )
' W8 a: d# R6 \! V, W                          set y  Dep / 2 ]
- w  x8 l% Z# A- T8 x9 p% @2 ]           set b  int (a / 5) * 5( L7 C7 p5 ?# y: P
    setxy ( xcor-of turtle b + x ), L! x9 ?& r0 Y9 z# I
          ( ycor-of turtle b + y )3 n" k4 S+ r; o6 Y! r
if (remainder who 5 = 2) [set c who
9 C3 [6 {0 e/ j9 ^& N                          set x ( 0 - Wid / 2 ) ; @* ?; Q: [+ b3 r9 T$ l! u
                          set y (0 - Dep / 2 )  ]
( ]! R9 d8 d# Y5 @$ g                          set d int (c / 5) * 5/ b9 F5 t0 d+ G
   setxy   ( xcor-of turtle d + x )% u9 v) z+ X! D! e  e) ^
           (ycor-of turtle d + y ) 8 ?$ F% ^9 O  ]4 s8 ~& b
         
: Z6 z$ j/ }, G5 i) D            * F/ R. p. q- Y! i5 p
if (remainder who 5 = 3) [set k who
) p" F' E) q7 J/ `: e4 I                          set x( Wid / 2)  
, ]: N, G) i# g& f                          set y (0 - Dep / 2 ) ]: {* {8 m7 O5 @" h# G
                          set f int (k / 5) * 51 X2 G, R8 p  C* V
  setxy   ( xcor-of turtle f + x )# a7 b: G6 V* W9 o5 K- F" a
           (ycor-of turtle f + y ) ) }2 ]! T' A9 M  _9 @) V
           
' |, K4 v& z  }- g' |           
& Y/ H# r% h$ A& E5 K5 L& [if (remainder who 5 = 4) [set g who
. Y6 w% e( v' K" y8 Q+ u+ L- h                          set x Wid / 2 ( d0 C8 M! {. t% H! T
                          set y  Dep / 2 ]+ K/ y; z; h6 `  B
                          set h  int (g / 5) * 5
7 M! |" B. b, ^+ c; ]  o. F. s: S  setxy   ( xcor-of turtle h + x )
! _' A" S. \3 I, P           (ycor-of turtle h + y )
5 e" K" Y# I- W                            F0 y9 O: E8 U% V0 @* I8 E; }
                          
( A2 d0 ^; o$ }' M                          ]
' N. T; j  k# ]6 I. Uend1 P2 W& H$ t, K9 a
/ n; w2 q. m/ i! ~8 ~1 p1 G/ K
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,+ q* _/ ]1 H+ C6 w: ^& g
应该是1 F2 }% b7 C* r$ F# \
ask turtles [
' L- v  s8 w: vif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) ) R! v4 d3 }) a. V8 P
                          set y  Dep / 2
$ x8 N3 d% u7 E           set b  int (who / 5) * 51 b$ n4 O- x2 O
    setxy ( xcor-of turtle b + x ); X* i$ G  S, t4 L6 F3 J' s
          ( ycor-of turtle b + y )]]+ x5 |2 K% {; P
end9 G5 Z7 N8 ?# i
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-2-11 09:11 , Processed in 0.016319 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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