设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8155|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
/ p6 b: {, {1 C# @* S! {: x; ]6 L: Q- ^! e! D* y" t8 C6 Y, |4 W7 `. B% j
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。. w: @8 U7 g# g/ N& B8 f) _# W* L1 V0 q

/ }& J$ N+ G: s& y- J' x5 qturtles-own [a b c d k f g h
& \- a4 v1 w6 E  v9 d- b! R! k  x y     ;; these are the leaf-turtle's offsets relative to center-turtle 0 g# t* }! v) S! m  j# q4 D/ B; i
]. H* T* f. a: D' w8 X. ]
to new) n" @7 G0 h, a7 A# M
  ca
) B6 h; q9 E7 t3 Z! F' g  crt 5 * num_of_building# O6 o& @( ?9 |
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]2 t& s1 y0 Z4 N- b& J; a, A
  scatter     ;;keep center-turtle random positions 7 o7 b5 x& t, T' Q. i) |( q
  unit_plan   ;;make up the building plan5 @$ L$ W/ R! {+ F" j
end4 n! }! s! w1 N* t- p3 u+ f
to scatter
! J: ]% m- o: K2 P# eask turtles with [remainder who 5 = 0]
( V1 X6 S' G3 l2 E# A) q[  t- S# ?: ^4 o
set xcor xcor - 6 + random-float 15! `6 y  ?& z! W8 s
set ycor ycor - 6 + random-float 15# `) x, G% K' X& s, q6 ]7 Y
]
+ R$ e3 i7 [) U6 x7 R4 Pend
% t5 ~; _$ E4 @  O# Xto unit_plan
) h! c- F' a4 j- w- ~ask turtles [
1 W+ u& C. L! s7 @  t6 Dif (remainder who 5 = 1) [set a who
! c- b# J2 |$ n) L                          set x ( 0 - Wid / 2 )
3 A- [) N- i1 p                          set y  Dep / 2 ]. L7 X6 V: m. Y- p/ P9 c  F2 {
           set b  int (a / 5) * 5
/ ?9 Q7 S  Q  U3 Z" ]3 N    setxy ( xcor-of turtle b + x )& z5 C% A- C* d* }9 ?
          ( ycor-of turtle b + y )9 f' O9 r$ p7 K
if (remainder who 5 = 2) [set c who) ?5 `& {+ I$ }9 N% i
                          set x ( 0 - Wid / 2 )
' Q3 V8 e) R; U$ }2 R                          set y (0 - Dep / 2 )  ]
' b% J% n4 w5 ^% b$ ^- ]( J& \+ P                          set d int (c / 5) * 5" }/ W3 L9 T; u, [
   setxy   ( xcor-of turtle d + x )
% u& F* f# Q* V           (ycor-of turtle d + y )
) @% F+ x3 [/ B+ a0 f7 a0 |          ' p4 P& o, `, M: r* i
            
# R: \. d% b( F& Aif (remainder who 5 = 3) [set k who
; p3 E8 {3 _( N6 ]8 V3 Z& {                          set x( Wid / 2)  5 e# [0 d. K& U8 G; h& X
                          set y (0 - Dep / 2 ) ]
; s( W& n' I6 f* C' ?6 N; W# F                          set f int (k / 5) * 5- j  {) F% l0 |" d9 q% m; [; e
  setxy   ( xcor-of turtle f + x )
' x5 r: s% [# j) o6 ]) S           (ycor-of turtle f + y )
6 M* o4 S6 a6 @6 o) x; o' V  W           % V9 L( ]( N5 k8 Q8 }
           
3 f) `: e9 h! Eif (remainder who 5 = 4) [set g who
8 A/ d& \+ j: ?/ w2 Q1 R                          set x Wid / 2 ) h3 Z( V5 z) T$ r4 _- M, r
                          set y  Dep / 2 ]. V5 J8 o. p2 N" L. `
                          set h  int (g / 5) * 53 h9 v% B. N4 |+ J7 w4 ]  b8 M
  setxy   ( xcor-of turtle h + x )1 a; S( t. v3 n2 k. T% m
           (ycor-of turtle h + y )
) l4 w! H3 E/ h$ g                          & |4 K! q. m; t/ j9 E! V
                          + q+ x2 x0 f6 b$ }& z
                          ]7 g3 _2 b0 G: ~* o
end
% l* z) F! w# v+ y& `6 K/ z: U+ I* w
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,
! l! r7 v2 S" M应该是
( @  c2 `$ I' H/ P" O5 cask turtles [  l# Z0 Z- c5 G8 U+ C# a3 p# [
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 ) , x; O% _/ d- d7 e
                          set y  Dep / 2 8 Z; d% `$ h6 r( G8 T, ]: G2 ^% L& \% D
           set b  int (who / 5) * 5
5 ~5 d; U- k) Y! c    setxy ( xcor-of turtle b + x )+ c2 }8 K% l2 v2 a9 h( ]
          ( ycor-of turtle b + y )]]
/ w2 f* F+ T% {* |1 X- Qend3 x3 H+ G  Q( _' \' w+ y( M6 }
之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-12 08:33 , Processed in 0.019568 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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