【发布时间】:2012-04-06 15:03:41
【问题描述】:
我刚刚为游戏 nethack 启动了一个 AI 机器人,我无法绕过源代码中的“人工检查”。我说的这段代码是nethack/sys/unix/unixunix.c:
#ifdef TTY_GRAPHICS
/* idea from rpick%ucqais@uccba.uc.edu
* prevent automated rerolling of characters
* test input (fd0) so that tee'ing output to get a screen dump still
* works
* also incidentally prevents development of any hack-o-matic programs
*/
/* added check for window-system type -dlc */
if (!strcmp(windowprocs.name, "tty"))
if (!isatty(0))
error("You must play from a terminal.");
#endif
我正在使用 JavaScript(更具体地说是 Node.js),由于上述原因,它不会让我从程序中运行,即使我正在生成一个 bash shell 子进程并告诉它开始nethack。我需要想办法绕过上面的代码而不重新编译源代码。
我当前使用的代码是:
"use strict";
var env = { TERM: 'tty' };
for (var k in process.env) {
env[k] = process.env[k];
}
var terminal = require('child_process').spawn('bash', [], {
env: env,
});
terminal.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
terminal.on('exit', function (code) {
console.log('child process exited with code ' + code);
});
setTimeout(function() {
terminal.stdin.write('nethack');
terminal.stdin.end();
}, 1000);
程序的输出是:
stdout: You must play from a terminal.
child process exited with code 1
我可以使用什么 Node.js/JavaScript(而不是任何其他语言或框架,如果可能的话)黑魔法来解决这个问题?
【问题讨论】:
-
我不确定这个,你可能想看看节点的TTY module。此外,this thread 可能会引起您的兴趣。
-
是的,我检查了 TTY 模块:似乎 v0.6+ 弃用了
tty.open()方法,这可能是我想要的,但该方法使用了弃用的 @987654330 @ call,我找不到任何文档。不过我会检查线程。谢谢。 -
很好奇这对你来说是怎么回事?我也希望开始使用 NetHack 和 JavaScript 做一些事情。
-
@Jay 虽然这是几年前的事了,但遗憾的是我在放弃这个概念之前没有取得任何进展。我现在要做的可能是从源代码中编译 nethack,删除该行或以某种方式从节点伪造一个 TTY。 Node 在这一点上可能内置也可能没有这样的功能,但如果你只想在本地破解,老实说从源代码编译 nethack 似乎是一个很好的解决方案。
标签: javascript node.js artificial-intelligence tty nethack