设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4878|回复: 2

[交流] 代码逻辑问题

[复制链接]
发表于 2008-4-12 15:04:09 | 显示全部楼层 |阅读模式
在这段代码中我设定了一个stopped?变量,初始状态设为false 。运行过程不能输出stopped?为true 。始终为false
& f) R% K0 [% i( N5 r+ yto go: z7 Z1 j7 Z' I$ u
if not any? turtles with [not stopped? ] [ stop ]  
0 F3 F9 ~9 b% zask turtles with [remainder who 5 = 0] [
4 M* _4 V. ?6 T  \. l8 t! J$ \set close-mates  (turtles with [self != myself])with[' B2 E* a# k$ P( N+ d$ c% J
(abs(xcor -(xcor-of myself)) < X-Dist + Wid ) 4 z: b; H' I$ p
and (abs(ycor -(ycor-of myself)) < Y-Dist + Dep )
% P3 G8 K; x- V+ G$ [and remainder who 5 = 0 1 a( D7 l" n$ V! q
]                   1 d9 l0 X7 p+ u, l( t( B; w# r
ifelse any? close-mates
( O  ^  A  U# z/ h- h# l[                                                               
; e6 n2 k8 J: x. l9 uset closest-one min-one-of (close-mates with[self != myself] )[distance myself]
9 E- h5 C. N) y, I5 l7 \5 l  Vface closest-one
8 d! G# n: r( J% B" P" rrt 180
) J0 p5 G5 r) _0 g8 ffd random-float step-size
2 O0 [' o; }  |2 I( ]avoid-walls8 r; s5 ^( a; O& P/ G  O! _
set stopped? false]
0 S9 C' h+ ]; T& c5 o8 y[set stopped? true]
7 N5 O* ?& Y" }7 i& m  X]
 楼主| 发表于 2008-4-12 15:05:12 | 显示全部楼层
是逻辑有问题吗?
 楼主| 发表于 2008-5-2 17:02:02 | 显示全部楼层
上述问题,如果最先的if语句改成! S% v- h; k* y! K9 f
if not many? turtles with [remainder who 5 = 0] with [ not stopped?][ stop]
9 _- r5 U+ O5 L% P7 N( L- J则可以顺利的终止go程序* p& m) X9 y% D; t
但是从我的程序逻辑上,编号非5的整数倍的turtle分别与最近的一个五的整数倍turtle tie在一起,5的倍数turtle为根turtle,所以没有turtle运动和没有5的整数倍turtle运动是等价的,if语句两者逻辑没有实质区别,但为什么执行起来会有区别呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-9-5 09:47 , Processed in 0.015146 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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