设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 8174|回复: 1

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

[复制链接]
发表于 2008-4-10 16:36:43 | 显示全部楼层 |阅读模式
我的模型,原意是使得每五个turtle成一个矩形,这些矩形随机散布在一定范围内。
) t; T, i: Q  V) A& M7 A4 R3 S) {9 u. N- q$ C# ~' u
但是运行结果所有的矩形重叠在一起,只显示一个矩形。请大家帮忙看看。
) L% {/ I: y1 t/ }1 x, H" r
  e- ], A% R1 G/ X3 Oturtles-own [a b c d k f g h
- L7 t5 l  o  M; p" R  x y     ;; these are the leaf-turtle's offsets relative to center-turtle
" d# n4 m7 w7 ?: _5 @! S* ~]; _7 S3 [; E- c5 |: }% a
to new0 E& z* W9 I) V$ c* n) R
  ca
& _  E8 N: O& h8 z$ y. |  crt 5 * num_of_building5 x# b2 C. R1 o$ d1 u/ r
  ask turtles [ifelse (remainder who 5 = 0) [set color red][set color blue]]
% o+ G+ h  f6 L% b4 @. F  scatter     ;;keep center-turtle random positions % L/ o: {0 w7 G) ?0 i4 h# l
  unit_plan   ;;make up the building plan" @) V$ O$ c, R5 G( ?
end5 B, ~' A' Z) w3 y9 T$ @- }
to scatter  H6 S9 U* y, ]
ask turtles with [remainder who 5 = 0]& h6 d# S) |3 K
[. n+ B; D( q$ ]0 i2 ?$ U7 l
set xcor xcor - 6 + random-float 15
7 z2 H, ~) Y( \$ I3 K5 _% J( m+ [set ycor ycor - 6 + random-float 15
$ \: p, R2 ?4 ^, x! t]' f. B3 `! t% s9 |, Q
end: G4 g: q# |/ R- {$ i
to unit_plan
1 o% V. u1 d2 {4 T: e) U: e% [ask turtles [3 k/ a- V) O! T1 K' _
if (remainder who 5 = 1) [set a who
) g- c% H) }/ B" q. R                          set x ( 0 - Wid / 2 )
9 i+ x  H. l, D6 G3 \( B5 E0 B* u                          set y  Dep / 2 ]  J) |* N6 m6 o
           set b  int (a / 5) * 5/ L9 V& a9 \7 I+ t8 n/ P2 h, X
    setxy ( xcor-of turtle b + x )6 u. y- I3 T) [0 u) F# ^
          ( ycor-of turtle b + y )5 F- e  y3 h$ V0 ]* y
if (remainder who 5 = 2) [set c who
% m+ O0 Q; \/ q% s                          set x ( 0 - Wid / 2 )
+ S9 D5 D  J* a! W+ v# o0 c. B                          set y (0 - Dep / 2 )  ]: T& n, r) z. C* D
                          set d int (c / 5) * 5
) B. U2 l3 J( X5 i3 ]9 C# W   setxy   ( xcor-of turtle d + x )& |4 ]7 i4 l. ]$ w  L, h$ m
           (ycor-of turtle d + y )
0 f! T* n; {! X6 a7 j         
5 R1 @; c; @& l& N            # {# w1 i/ Y. d5 P
if (remainder who 5 = 3) [set k who4 c7 p1 M6 o. Y0 g$ J, C/ z
                          set x( Wid / 2)  % K: c' y) p; X; i( X9 m
                          set y (0 - Dep / 2 ) ]
! ?, D) r4 p, |: z                          set f int (k / 5) * 5
: T8 e8 ~" u: `+ H  setxy   ( xcor-of turtle f + x )
& |! B3 |) \7 Z- y( G           (ycor-of turtle f + y )
; b6 v, G% g! T2 B           
3 Y2 G% u6 G+ ?- i           
' K5 d5 r* W" }- oif (remainder who 5 = 4) [set g who
" w2 e& |$ t  F                          set x Wid / 2
$ r  R% @7 l- {. S6 D                          set y  Dep / 2 ]
2 Q  N, r7 V* N7 Q                          set h  int (g / 5) * 5
2 ~7 a- o* a* G* b4 w  setxy   ( xcor-of turtle h + x )
' n8 d* i+ O/ ]+ V" s           (ycor-of turtle h + y ) ( _1 n6 f3 T6 @( `: M
                          
7 M" ^8 G3 F9 z/ Y5 F5 F% Q                          
" |$ J; s, P4 Y$ G! o                          ]
' m# m3 I0 o$ n2 i2 D) g9 Eend
# O- ?7 U. u& a$ U0 V- q4 \. `, t$ e: `5 q6 Q1 |
[ 本帖最后由 etamina 于 2008-4-10 16:41 编辑 ]

本帖子中包含更多资源

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

x
 楼主| 发表于 2008-4-11 13:26:12 | 显示全部楼层
已经解决了,* q9 J6 F5 p. }! d/ ^+ t
应该是2 o4 }! o, G0 O# t; N/ o
ask turtles [( m* u$ V8 {: Q) g1 v
if (remainder who 5 = 1) [set x ( 0 - Wid / 2 )
3 k: x8 U$ p$ \7 M( ?                          set y  Dep / 2
; m$ r! t  {7 t$ n8 \2 I' M           set b  int (who / 5) * 5
% Q- ?7 v5 {2 v  H    setxy ( xcor-of turtle b + x )
2 w$ T# Q8 o  b9 n5 O          ( ycor-of turtle b + y )]]
/ f) y$ m7 w  A+ C# g' F& fend
6 C# [; x; t8 l8 h& p' u# y之前有个括号位置不对没发现
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-5-14 16:15 , Processed in 0.015802 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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