设为首页收藏本站

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

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 5971|回复: 2

[交流] 代码逻辑问题

[复制链接]
发表于 2008-4-12 15:04:09 | 显示全部楼层 |阅读模式
在这段代码中我设定了一个stopped?变量,初始状态设为false 。运行过程不能输出stopped?为true 。始终为false3 ^% y- C! _5 c: S: g, @
to go; [" A3 `( p) {0 f; q
if not any? turtles with [not stopped? ] [ stop ]  9 w$ r3 k- [4 F5 @) C1 ]
ask turtles with [remainder who 5 = 0] [
. F: G" ?9 w- [set close-mates  (turtles with [self != myself])with[9 K) x% O+ h) J% @& {- r+ r$ S
(abs(xcor -(xcor-of myself)) < X-Dist + Wid ) 9 G) [  S7 W( g+ B" {9 }
and (abs(ycor -(ycor-of myself)) < Y-Dist + Dep )   h8 r, m4 @- q" [
and remainder who 5 = 0 ! \6 R) u4 W/ D% K
]                  
  T" }' B) @3 r# w* U2 {3 gifelse any? close-mates
8 ?7 y7 k- n- N8 e& h[                                                                8 V/ T, Y' G7 Y/ B4 W/ D
set closest-one min-one-of (close-mates with[self != myself] )[distance myself]" c( @4 r8 x1 ~( {  ]% H' Q
face closest-one% d9 E5 C7 U9 |: |; z
rt 180
4 {" A" x0 @7 q0 s& F' Bfd random-float step-size; ~/ B+ S; s  ^3 n4 r1 I9 x% J
avoid-walls8 r- \+ b; l6 f1 a' H3 i
set stopped? false]
* a0 d( ?2 \3 r% ^  i[set stopped? true]
( R- q# F, x- N9 j]
 楼主| 发表于 2008-4-12 15:05:12 | 显示全部楼层
是逻辑有问题吗?
 楼主| 发表于 2008-5-2 17:02:02 | 显示全部楼层
上述问题,如果最先的if语句改成
7 e/ `9 a& `+ s; G5 Hif not many? turtles with [remainder who 5 = 0] with [ not stopped?][ stop]% _) l) d9 ?$ Q5 D& B
则可以顺利的终止go程序0 L7 G; z' d+ D, b( C
但是从我的程序逻辑上,编号非5的整数倍的turtle分别与最近的一个五的整数倍turtle tie在一起,5的倍数turtle为根turtle,所以没有turtle运动和没有5的整数倍turtle运动是等价的,if语句两者逻辑没有实质区别,但为什么执行起来会有区别呢?
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2026-4-30 08:52 , Processed in 0.013371 second(s), 14 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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