如何从Node.js连接到nethack?

我正在为游戏nethack开发一个AI机器人,但我无法绕过源代码中的“人机验证”。我提到的代码段位于nethack/sys/unix/unixunix.c

#ifdef TTY_GRAPHICS    /* idea from rpick%[email protected]     * 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(如果可能的话,不使用其他语言或框架)的“黑魔法”来解决这个问题?


回答:

这种检查有点无效,因为伪终端(ptys)在isatty()中会返回true。伪终端允许程序伪装成终端。这就是Xterm和Screen的工作原理。如果那个检查不允许这些程序通过,你将无法在它们中玩NetHack。

我从未使用过,但pty.js绑定到你会在C代码中使用的东西,并且接口看起来很合理。

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注