设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5384|回复: 2

[交流] 代码逻辑问题

[复制链接]
发表于 2008-4-12 15:04:09 | 显示全部楼层 |阅读模式
在这段代码中我设定了一个stopped?变量,初始状态设为false 。运行过程不能输出stopped?为true 。始终为false# p9 R+ e% k1 ?* _. [
to go) A' d! w+ A, d5 u3 M
if not any? turtles with [not stopped? ] [ stop ]  
" E! \5 ]! g+ R8 J2 F; h' {" R9 wask turtles with [remainder who 5 = 0] [
# ?3 E- b) z0 f, Iset close-mates  (turtles with [self != myself])with[: U) k" c, z( R0 b. D) a. |+ }! x
(abs(xcor -(xcor-of myself)) < X-Dist + Wid )
+ t2 h; L+ K5 w7 T9 ]* @. @and (abs(ycor -(ycor-of myself)) < Y-Dist + Dep )
/ K4 [6 a# f, A- X; q4 _2 I/ Gand remainder who 5 = 0 + `: C+ d  o3 i/ N
]                  
$ s9 U! S( f- [: }- O. aifelse any? close-mates
9 I+ |) s( f* L% ^- T% U1 u* b' J[                                                               
, g) L5 q- A/ S) xset closest-one min-one-of (close-mates with[self != myself] )[distance myself]
/ m6 q! r# h( ~% S' B, M/ qface closest-one
( d7 m5 p0 C# T$ t% V! {% |# Krt 180! C. q8 k9 B( o2 ~# H- S
fd random-float step-size
4 A! Z9 x( C5 o& ?# |6 {' Mavoid-walls
- D; p, i! `0 l  M% Kset stopped? false]
1 f1 |" F/ _  s! `2 G: r3 E) ][set stopped? true] 8 p- w$ [! w/ D: V
]
 楼主| 发表于 2008-4-12 15:05:12 | 显示全部楼层
是逻辑有问题吗?
 楼主| 发表于 2008-5-2 17:02:02 | 显示全部楼层
上述问题,如果最先的if语句改成) f7 z; V9 y) L7 ~5 H; ]
if not many? turtles with [remainder who 5 = 0] with [ not stopped?][ stop]$ b) H$ ^7 K0 \$ Q
则可以顺利的终止go程序
: |( F3 Z. G4 p+ K: L3 [但是从我的程序逻辑上,编号非5的整数倍的turtle分别与最近的一个五的整数倍turtle tie在一起,5的倍数turtle为根turtle,所以没有turtle运动和没有5的整数倍turtle运动是等价的,if语句两者逻辑没有实质区别,但为什么执行起来会有区别呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2025-12-14 00:54 , Processed in 0.019603 second(s), 15 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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