Prolog用户输入中的时间限制(已读) [英] Time limit in Prolog user input (read)

查看:111
本文介绍了Prolog用户输入中的时间限制(已读)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个游戏翻译.用户将其移动输入到解释器,然后程序执行该移动.

I'm writing an interpreter for a game. User enters its move to the interpreter and program executes that move.

现在,我想为每个决定实施一个时限.玩家的思考时间不应该超过30秒,然后按Enter键.

Now I want to implement a time limit for each decision. Player shouldn't be able to think more than 30 seconds to write a move and press enter.

call_with_time_limit似乎很相关,但它不能正常工作:

call_with_time_limit seemed relevant but it doesnt work properly as such:

call_with_time_limit(30,read(X)),Problem,write(Problem).

call_with_time_limit( 30, read(X) ), Problem, write(Problem).

在这种情况下,它等待输入,输入后,计时器将随后启动.但是我希望计时器从头开始.

In this case, it waits for input, and when input is entered, timer starts afterwards. But I want the timer to start at the beginning.

我该怎么办?

推荐答案

如果您对与I/O相关的超时感兴趣,请考虑

If you are interested in I/O related timeouts please consider wait_for_input/3 or set_stream/2. The built-in you found, call_with_time_limit/2 is not a simple and reliable interface.

我只是看到您使用read/1进行输入.请阅读上面的文档,了解如何避免在read/1中阻塞.我不清楚您为什么需要这样做,但是用户可以只输入 Return ,从而避免了初始超时. read/1现在会读到'\n',但随后将等待进一步的输入-没有超时,而用户则大肆浏览Wikipedia寻求答案...甚至可能会问关于SO的问题...

I just see that you use read/1 for input. Please read in above documentation how to avoid blocking in read/1. It is not clear to me why you need this, but a user might simply enter Return, thereby circumventing the initial timeout. read/1 would now read that '\n' but then would wait for further input - without a timeout, while the user lavishly skims Wikipedia for the answer... might even ask the question on SO...

这篇关于Prolog用户输入中的时间限制(已读)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆