设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 9172|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。8 @1 a0 g/ ~1 _8 k
2 Y# K$ R6 b" f; X/ x5 B
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。2 X! b6 l9 V8 [& {2 K3 J
" q# r7 m7 H. y) \' @
turtles-own [a b c d k f g h
$ U* v) g* t/ c$ [" l, x* S  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 0 s2 A2 O5 I* t, i+ U# x
]' u$ x8 e+ t7 A/ _( S
to new; o; N- T/ ~9 d8 F+ U: G
  ca) {) O6 }# v0 A, }! n: j* W
  crt 5 * num_of_building* w9 ^2 d3 V/ Z. c
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
# Z& P5 H5 y3 Q: B2 v  scatter     ;;keep center-turtle random positions
' \5 z. o4 [2 d  unit_plan   ;;make up the building plan
+ B# Z1 P3 e/ I- h( y* C: v; K8 fend
  _# r: r" L: W* jto scatter
! A2 Q) f6 a- D' K" C2 task turtles with [remainder who 5 = 0]
# V/ ]' a& H" f1 L" _[
# L* b% b5 {- y) j* xset xcor xcor - 6 + random-float 15
9 @+ t$ ^& {" T3 hset ycor ycor - 6 + random-float 15
* x1 B6 t& L4 [/ o4 e  w5 g* m]
+ }7 |% ]3 B6 W/ Rend
" a! k) i5 I% |to unit_plan * j# n0 {3 ?* K3 n8 i4 N4 y. ^
ask turtles [
, ]% B2 o% l  X+ o5 g9 \if (remainder who 5 = 1) [set a who ; P8 g3 w. y; `% s
                          set x ( 0 - Wid / 2 )
: ~* R* A0 Y+ H                          set y  Dep / 2 ]
6 i- C& e. \8 A; m           set b  int (a / 5) * 5% O9 B9 }* Q, L6 ?+ g
    setxy ( xcor-of turtle b + x )
8 A& R9 K3 O- d          ( ycor-of turtle b + y )1 X6 P4 g: T/ q3 F
if (remainder who 5 = 2) [set c who& z' y4 z+ o0 e. V; m, b  o+ x
                          set x ( 0 - Wid / 2 )
9 c* N7 x; N: J0 ^) n                          set y (0 - Dep / 2 )  ]( O9 j5 m, d. V$ a/ d. b- j
                          set d int (c / 5) * 54 M& _; g' G( A: W0 h
   setxy   ( xcor-of turtle d + x )3 X9 i" G0 b( u$ C6 }3 D6 l4 l; h
           (ycor-of turtle d + y ) . ~6 @( J1 V5 |
          . ?7 Q8 Z5 W0 g' Z" ~/ ?7 l( a) l
            
" ?1 i  q! ^. `1 c/ Lif (remainder who 5 = 3) [set k who
+ H) z1 _# A, s+ h                          set x( Wid / 2)  
! P8 d0 I! n% T! t9 S" k- v                          set y (0 - Dep / 2 ) ]4 m5 Q2 h( i' j: C5 I8 @& ~- M( q: C
                          set f int (k / 5) * 5
4 J1 y5 N! r6 K0 C  setxy   ( xcor-of turtle f + x )
) I  _0 e4 S: }. }* V           (ycor-of turtle f + y )
6 C) D, J' ?+ J0 s  {- G8 q           
1 T4 i4 A1 g5 Y$ f' ]3 x1 @" D           " Y. Y3 K. a" c) G# Y3 C
if (remainder who 5 = 4) [set g who. w* \3 A* r* [0 F, i
                          set x Wid / 2
! [- h& \0 U, X* {) ]0 d                          set y  Dep / 2 ]
; H. n3 N$ x& Q                          set h  int (g / 5) * 5( Z* F5 H# |$ |4 z' O; Y5 Z+ n
  setxy   ( xcor-of turtle h + x )
& z' W6 @$ y1 p2 _+ c           (ycor-of turtle h + y ) 1 H" ^4 ^* t7 }& G$ f5 W- g/ M+ C
                          5 e* E6 O" {$ Y7 m; Z7 O8 ^
                          1 m/ ~2 u- E( |" a4 C" {/ r
                          ]
; l1 L  f5 L9 \" p" N" Uend" B7 j4 {  V: [

  Z: F. D0 o9 P, c: U[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
- j* Q$ @( q( }0 l应该是
; Y1 f( Y) o. C: x% Z2 X. Bask turtles [( p0 g# ^0 M9 B5 X; U
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) / E3 ?' W5 s7 x# {% Q; c1 m
                          set y  Dep / 2
: ]8 R: Z3 P" L' N3 s( O           set b  int (who / 5) * 5
$ T' G9 N' a  f# u, E  ^5 ~    setxy ( xcor-of turtle b + x )
' z# V; Q; M9 h0 Z2 a- Z; K  A          ( ycor-of turtle b + y )]]: Z# u( t, W, \- ~% Y6 \
end) d  J2 B  d+ ^& M" h) J
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-9-26 11:24 , Processed in 0.019711 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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