识别网页中的颜色/图案

发布于 2024-11-02 14:42:02 字数 704 浏览 7 评论 0原文

我想尝试创建一个学习象棋应用程序作为学校项目。我的第一个计划是简单地让这个人工智能与自己进行较量,但要真正展示它是否成功,它需要能够展示它的进展情况。为了做到这一点,我希望它能够在 chess.com 等网站上玩评级游戏。然而,我相信他们(还)没有公共 API。

因此,我想用java制作一个识别颜色和图像的程序。它保留所有位置的内部二维数组,并识别棋盘上的棋子。我想我已经找到了一种方法,可以使用类似 Java 机器人类

然而,我希望它做的是在内部窗口中打开此网页并继续在后台执行此操作。有没有一种方法可以识别自己窗口内的颜色,而无需位于前景?

编辑:我计划使用我刚刚找到的这个浏览器组件。我注意到可以创建页面的全页快照并将其保存为 BufferedImage(?)。这会让做这件事变得更容易吗?

编辑2:我刚刚读到“完全禁止来自其他人、计算机/国际象棋引擎或残局表库的外部援助”。我想让计算机来完成所有的游戏肯定包括在内。所以我可能会尝试使用另一个网站,所以特定于 chess.com 的答案不会解决问题!

I want to try to create a learning chess application as a school project. My first plan was to simply pit this AI against itself, but to really show if it has been succesful it needs to be able to show how well it progresses. In order to do this, i want it to play rated games on sites such as chess.com. However, they do not (yet) have a public API, i believe.

Therefore, i wanted to make a program in java that recognizes colors and images. It keeps an internal 2-dimensional array of all the positions, and recognizes the pieces on the board. I think i have found a way to do this in a window using something like the Java Robot Class.

What i would like it to do, however, is to open this webpage in an internal window and keep doing this in the background. Is there a way to recognize colors within the own window, without needing to be in the foreground?

Edit: I'm planning on using this browser component i just found. I noticed that it is possible to create a full-page snapshot of the page and save it as a BufferedImage(?). Would this make it easier to do this?

Edit 2: I just read that 'Outside assistance from other people, computers/chess engines, or endgame tablebases is entirely prohibited'. I suppose letting a computer do all the playing does certainly include in that. So i might try using another site, so answers that are specific for chess.com won't cut it!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

皓月长歌 2024-11-09 14:42:03

我不知道它有什么帮助,但也许你可以看看 Sikuli 项目。
http://sikuli.org/

Sikuli 是一个处理与用户界面交互的程序(和 API)。例如,您可以编写一个脚本来在某些条件下单击图像或按钮。

对您来说特别有趣的是,有一个 Java 集成: http://sikuli.org/ docx/faq/030-java-dev.html

这是网站的摘录,可让您了解可以编写的代码。

编辑:在此代码中,请务必注意您正在使用图像定义新模式。 Sikuli 将能够找到匹配的模式。

import org.sikuli.script.*;

public class TestSikuli {

    public static void main(String[] args) {
            Screen s = new Screen();
            try{
                    s.click("imgs/spotlight.png", 0);
                    s.wait("imgs/spotlight-input.png");
                    s.type(null, "hello world\n", 0);
            }
            catch(FindFailed e){
                    e.printStackTrace();
            }
    }
}

I don't know it it helps but may be you can have a look at the Sikuli project.
http://sikuli.org/

Sikuli is a program (and an API) to handle the interactions with the User Interface. For instance, you can write a script to click on an image or a button in certain conditions.

Especially interesting for you, there is a Java integration: http://sikuli.org/docx/faq/030-java-dev.html

Here is an extract of the website to give you an idea of the code you can write.

EDIT: in this code it is important to notice that you are defining new Patterns with the images. Sikuli will be able to find matching patterns.

import org.sikuli.script.*;

public class TestSikuli {

    public static void main(String[] args) {
            Screen s = new Screen();
            try{
                    s.click("imgs/spotlight.png", 0);
                    s.wait("imgs/spotlight-input.png");
                    s.type(null, "hello world\n", 0);
            }
            catch(FindFailed e){
                    e.printStackTrace();
            }
    }
}
匿名的好友 2024-11-09 14:42:03

您应该考虑在提供 API 且允许使用国际象棋引擎的国际象棋服务器上进行游戏。有一个 互联网国际象棋俱乐部 (ICC),您必须付费才能拥有一个人工帐户,然后您可以获得一个为您的引擎提供免费的计算机帐户。还有免费互联网国际象棋服务器 (FICS),您和您的引擎可以获得免费帐户。

ICC通常是首选,因为那里的棋手水平较高,有很多国际大师和国际象棋大师在那里比赛。

与这些网站交互的最佳方式是实施 xboard 协议。这将允许您的引擎通过 Winboard 或 XBoard 接口(等等)进行播放,并且这些接口可用于连接 FICS 或 ICC 并在那里自动播放。

我希望这会有所帮助,即使它不能直接回答问题。

You should consider playing on a chess server where an API is avaible and chess engines are allowed. There is The Internet Chess Club (ICC) where you must pay to have a human account and then you can get a free computer account for your engine. There is also the Free Internet Chess Server (FICS) where you and your engine can get free accounts.

The ICC is usually prefered because the level of players is higher there with lots of international masters and chess masters playing there.

The best way to Interface with theses sites is to implement the xboard protocol. This will allow your engines to play through the Winboard or XBoard interface (among others) and theses interface can be used to connect on FICS or ICC and automatically play there.

I hope this help, even if it does not directly answer the question.

情绪 2024-11-09 14:42:03

我不确定您的输入是什么,但您有两个选择:

  1. 您可以处理 PNG 图像。将图像加载到 BufferedImage (docs) 对象并在那里检查它。您可以使用屏幕截图工具来创建它们。

  2. 似乎 chess.com 使用 HTML 和 JavaScript。您可以使用 HttpComponents 下载 HTML 并检查它以了解各个部分的位置。这样做的另一个好处是,您不必猜测哪一个棋子去哪里,因为 HTML 包含源信息。

I'm not sure what your input is but you have two options:

  1. You can work an a PNG image. Load the image into a BufferedImage (docs) object and examine it there. You can use a screen shot tool to create those.

  2. It seems chess.com uses HTML with JavaScript. You can download the HTML using HttpComponents and examine it to see where the pieces are. This has the additional benefit that you don't have to guess which piece goes where since the HTML contains the source information.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文