设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6587|回复: 2

[交流] 代码逻辑问题

[复制链接]
发表于 2008-4-12 15:04:09 | 显示全部楼层 |阅读模式
在这段代码中我设定了一个stopped?变量,初始状态设为false 。运行过程不能输出stopped?为true 。始终为false
2 S( t0 t' d8 v3 N$ W8 }$ dto go
6 Z  b4 X4 H; tif not any? turtles with [not stopped? ] [ stop ]  " B1 v5 [: l7 _( _
ask turtles with [remainder who 5 = 0] [
) h. ?* b! Y0 V! I- n/ L. N  Bset close-mates  (turtles with [self != myself])with[
6 j) r1 H% F& W(abs(xcor -(xcor-of myself)) < X-Dist + Wid )
+ K$ h$ ]( c. C( |; pand (abs(ycor -(ycor-of myself)) < Y-Dist + Dep ) - r1 [, S* D2 u' H7 t+ m) p
and remainder who 5 = 0
0 ~3 N3 C9 b6 d9 L% f5 o]                  
% Q0 Y( p0 b8 Y6 `( {3 ^ifelse any? close-mates 2 y, q: ^) t  b' m
[                                                               
0 E3 n+ T( V+ @& ~" T! Iset closest-one min-one-of (close-mates with[self != myself] )[distance myself]
6 }2 [: X( f% e7 ~8 F2 C5 v  J$ aface closest-one6 \7 h5 O8 y1 `
rt 180* Z- n& s2 n: {8 P. z9 U
fd random-float step-size
8 M+ n4 L$ g- Wavoid-walls
% p% t6 C2 V: X( |* Lset stopped? false]9 G& p8 N9 P4 Y: O% e
[set stopped? true] . {; X; P3 [9 J1 u: N) v1 M
]
 楼主| 发表于 2008-4-12 15:05:12 | 显示全部楼层
是逻辑有问题吗?
 楼主| 发表于 2008-5-2 17:02:02 | 显示全部楼层
上述问题,如果最先的if语句改成
0 D5 P1 g- s2 N0 x# C' k  \if not many? turtles with [remainder who 5 = 0] with [ not stopped?][ stop]* H% f! B, K# D* r
则可以顺利的终止go程序
' _4 N) O5 Y( u但是从我的程序逻辑上,编号非5的整数倍的turtle分别与最近的一个五的整数倍turtle tie在一起,5的倍数turtle为根turtle,所以没有turtle运动和没有5的整数倍turtle运动是等价的,if语句两者逻辑没有实质区别,但为什么执行起来会有区别呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-8-26 07:56 , Processed in 0.013625 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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