设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 7218|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。8 y; {4 m& j) I- j. g

" ~7 ]6 _# _" O6 }! V- Z) f但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。7 j  U% g$ [! e0 R( d& C* `6 C
7 G# ^& L1 o. p8 `7 M
turtles-own [a b c d k f g h
2 `2 U; `" L+ h0 A: R  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
# z# W2 P( @+ M. \, @! u4 M  k]
6 n/ Z- e) Z4 T1 {5 w, u  ato new2 o9 [4 a7 n/ u
  ca! L; U; u% `, z$ J
  crt 5 * num_of_building
5 F9 b; f% ^# Q) B8 f: t  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
; p' f9 @& m" W9 s2 O! D) z' y  scatter     ;;keep center-turtle random positions
3 w" W2 L& `. U: n  unit_plan   ;;make up the building plan) ~5 \2 S9 a2 @8 d$ f' g! R
end7 f8 d0 v  x" ]9 Y% A, E! K0 B$ R
to scatter
' C, t: u: q3 f: s2 s' t8 A) Cask turtles with [remainder who 5 = 0]4 d' }+ F' |+ Y' G& U
[
; ~3 U! Y! k$ f* pset xcor xcor - 6 + random-float 15
2 ]8 w6 i$ X0 d& T% x5 ~set ycor ycor - 6 + random-float 15
6 w) M- [& }* P# z1 D* g( P]. a) X- B- Y, ^
end3 u1 N# v# M: z- D- x( {4 h; ?/ G) A
to unit_plan
" I: k7 ?6 r  G# R, ~1 Xask turtles [
  N$ [# O1 O: k. N1 j# J0 Hif (remainder who 5 = 1) [set a who
7 N+ p% U1 A% Y1 W0 N                          set x ( 0 - Wid / 2 ) ' y; [; `+ C) T* ~/ d* p+ ~6 \3 Q
                          set y  Dep / 2 ]4 v. m1 t. h& z
           set b  int (a / 5) * 5, m( R: a4 k- d4 S
    setxy ( xcor-of turtle b + x )
7 `1 q) t7 `5 X3 F$ z          ( ycor-of turtle b + y )' ~+ `( x" U3 `9 x1 M
if (remainder who 5 = 2) [set c who
0 l. K7 }, W9 q* d; a                          set x ( 0 - Wid / 2 ) . }4 U* i8 N8 e! E3 [4 X5 G
                          set y (0 - Dep / 2 )  ]5 t) c- w$ g" B: R
                          set d int (c / 5) * 5
) Z$ i& q( {% ]4 a2 f: B   setxy   ( xcor-of turtle d + x )* A8 c2 ~7 @* ~/ k8 f0 |
           (ycor-of turtle d + y )
- L0 b! J  j- w0 y6 t; a0 B          ; I5 L# q! {# {0 z* q
            3 D' w+ R- I8 r9 \* U; q. u  Z
if (remainder who 5 = 3) [set k who
) q8 H" A8 q8 W, m/ [" [8 v+ @                          set x( Wid / 2)  2 L) c6 ?# {/ s* ~- @
                          set y (0 - Dep / 2 ) ]; _" }2 r1 m, p, ]9 h! V) m
                          set f int (k / 5) * 5( y( ~6 w9 y& B
  setxy   ( xcor-of turtle f + x )
! ~5 J$ z' p- b" D* x           (ycor-of turtle f + y )
3 k# C$ x3 D5 c' |           
5 D  \# k  r9 u; T: {% `  x! B) E           
% N* L; m" k( v4 lif (remainder who 5 = 4) [set g who
, Q8 l. d  \& L& h$ X  F                          set x Wid / 2
9 T9 }' q8 S6 M                          set y  Dep / 2 ]
9 ^/ @4 ?7 y1 F2 H- W5 }3 O                          set h  int (g / 5) * 58 I9 k5 ^& W( c" ~  s- F
  setxy   ( xcor-of turtle h + x )
* r1 @+ ]3 a. E+ d6 Q& y- Y           (ycor-of turtle h + y )
, N+ z( n* E+ {8 G: a                          
" u7 r  [0 |) D                          
- d$ f+ Z0 t8 u' h                          ]' b% k1 [; z1 l5 A$ z9 }' G
end. i# N' s& ^/ E) G5 t$ u9 |& f

1 h7 h0 r2 t, c) u. M6 F" e[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,: s4 t  g  u( X$ H9 K
应该是
; x! b: [, Z/ h) l: xask turtles [
2 G- q# y1 t* H6 iif (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) & M  s( M8 z0 ]( E0 V) q4 F
                          set y  Dep / 2
- F9 S' Q- e% G3 F$ M2 }# j           set b  int (who / 5) * 5
( j  N# a4 K- e3 ^( Z4 i, Q    setxy ( xcor-of turtle b + x )
( B# w1 w* v# E/ G! `          ( ycor-of turtle b + y )]]
* r4 H' A" H  Q8 ^1 q/ p6 cend
9 j1 }8 Y: V$ n% K# S1 q, u之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-1-19 00:01 , Processed in 0.018903 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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