如何构建在线 Flash 游戏机器人?

发布于 2024-10-03 17:14:25 字数 293 浏览 1 评论 0原文

有很多 Flash 游戏要求你做重复的动作。例如 FarmVille 或获取在线扑克游戏的统计数据。

在屏幕上看到的内容、机器人算法和鼠标单击之间创建界面的最佳方法是什么?

所以基本上,当我在 Facebook 上玩德州扑克时,如果我得到 AA,我希望机器人点击全押。如果我没有得到 AA,我想弃牌。这只是一个例子,不是实际的策略。或者另一个例子是 Farmville 中的路由任务。

所以基本上。它必须抓取屏幕的图片。识别模式并将其转换为算法的输入。输出算法将点击其他一些(可能相同)模式。

有什么建议吗?

there are a lot of flash games that ask u to do repetitive actions. an example would be FarmVille or getting statistics on on-line poker game.

What is the best way to create an interface between what you see on the screen, a bot's algorithm and clicking of the mouse.

so basically, when i'm playing a texas hold'em on face book and if i get AA i want the bot to click all-in. if i don't get AA i want to fold. this is just an example, not the actual strategy. or another examples would be routing tasks in farmville.

so basically. it has to grab a picture of the screen. recognize patterns and convert them into an input of the algorithm. the output algorithms would be clicking on some other (may be same) patterns.

any suggestions?

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

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

发布评论

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

评论(3

任性一次 2024-10-10 17:14:25

我有为在线纸牌游戏构建基于计算机视觉的简单机器人的经验。

我使用了一个名为 autopy 的跨平台 Python 库来处理自动鼠标单击和键盘输入。机器人每 0.5 秒捕获一次屏幕,然后将捕获的屏幕转换为 numpy 数组进行分析。 Python 具有良好的图像处理(PIL、OpenCV python 绑定)和机器学习实用程序(scikit-learn)。对于简单的图像模式识别,机器人会提取图像区域上像素亮度的平均值来做出决策。对于复杂的问题,使用 OpenCV 模板匹配和 SVM 分类器。

服务器第一次捕获了我的机器人,所以我猜想服务器端有机器人检测。在我添加更多随机性和灵活决策后,该机器人绕过了服务器端机器人检测。

这一切花了我一个星期六,我很享受星期天。

I have experience building a simple computer vision based bot for a online card game.

I used a crossplatform python library called autopy to handle automated mouse click and keyboard input. The bot capture screen every 0.5 sec, then convert the captured screen into a numpy array for analysis. Python has good image processing (PIL, OpenCV python binding) and machine learning utilities (scikit-learn). For simple image pattern recognition, the bot extract mean of pixel brightness over a image region to make decision. For complicated ones, OpenCV template matching and SVM classifier are being used.

The server caught my bot the first time, so I guess some there's bot detection on the server side. After I added more randomness and flexible decision making, the bot has bypassed serverside bot detection.

All took me a Saturday and I enjoyed Sunday.

一江春梦 2024-10-10 17:14:25

在尝试解析屏幕图像并产生鼠标点击(这将非常困难)之前,首先查看游戏在浏览器和服务器之间实际发送/接收的数据。像平常一样与游戏交互,并使用 WireShark 之类的东西来捕获数据包,看看是否可以自动化。

这不太可能(因为他们明确希望人们做你想做的事情),但与服务器的通信可能只是带有参数的简单请求。 (我知道很久以前 MySpace 游戏就是这种情况,例如 Dragon Wars 和 Mafia Wars。)

如果数据是您可以解析和理解的内容,那么您可以完全跳过 Flash 界面,只编写自己的界面。

Before attempting to parse screen images and produce mouse clicks (which would be exceedingly difficult), first take a look at the data actually being sent/received by the game between the browser and the server. Interact with the game as normal and use something like WireShark to capture the packets and see if it's something you can automate.

It's unlikely (since they specifically don't want people to do what you're trying to do), but it's possible that the communication with the server is just simple requests with parameters. (I know this was the case a long time ago with MySpace games, such as Dragon Wars and Mafia Wars.)

If the data is something you can parse and understand then you can skip the Flash interface entirely and just write your own.

ぶ宁プ宁ぶ 2024-10-10 17:14:25

我使用 C# 和一个简单的 webBrowser 控件制作了许多机器人。
然而,通常我尝试在元素上自动执行“单击”功能,而不使用实际模拟光标并调用单击。

示例:

webBrowser1.Document.GetElementById("elementid").InvokeMember("Click");

我发现这比实际模拟光标容易得多,但是模拟光标也可以相对轻松地实现,这是我通常使用的代码:

//Example of how to use it:
    Point controlLoc = this.PointToScreen(webbrowser1.Location);
    controlLoc.X = controlLoc.X + webbrowser1.Document.GetElementById("elementid").OffsetRectangle.Left;
    controlLoc.Y = controlLoc.Y + webbrowser1.Document.GetElementById("elementid").OffsetRectangle.Top;
    Cursor.Position = controlLoc;
    MouseSimulator.ClickLeftMouseButton();

public class MouseSimulator
 {
[DllImport("user32.dll", SetLastError = true)]
static extern uint SendInput(uint nInputs, ref INPUT pInputs, int cbSize);

[StructLayout(LayoutKind.Sequential)]
struct INPUT
{
    public SendInputEventType type;
    public MouseKeybdhardwareInputUnion mkhi;
}
[StructLayout(LayoutKind.Explicit)]
struct MouseKeybdhardwareInputUnion
{
    [FieldOffset(0)]
    public MouseInputData mi;

    [FieldOffset(0)]
    public KEYBDINPUT ki;

    [FieldOffset(0)]
    public HARDWAREINPUT hi;
}
[StructLayout(LayoutKind.Sequential)]
struct KEYBDINPUT
{
    public ushort wVk;
    public ushort wScan;
    public uint dwFlags;
    public uint time;
    public IntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
struct HARDWAREINPUT
{
    public int uMsg;
    public short wParamL;
    public short wParamH;
}
struct MouseInputData
{
    public int dx;
    public int dy;
    public uint mouseData;
    public MouseEventFlags dwFlags;
    public uint time;
    public IntPtr dwExtraInfo;
}
[Flags]
enum MouseEventFlags : uint
{
    MOUSEEVENTF_MOVE = 0x0001,
    MOUSEEVENTF_LEFTDOWN = 0x0002,
    MOUSEEVENTF_LEFTUP = 0x0004,
    MOUSEEVENTF_RIGHTDOWN = 0x0008,
    MOUSEEVENTF_RIGHTUP = 0x0010,
    MOUSEEVENTF_MIDDLEDOWN = 0x0020,
    MOUSEEVENTF_MIDDLEUP = 0x0040,
    MOUSEEVENTF_XDOWN = 0x0080,
    MOUSEEVENTF_XUP = 0x0100,
    MOUSEEVENTF_WHEEL = 0x0800,
    MOUSEEVENTF_VIRTUALDESK = 0x4000,
    MOUSEEVENTF_ABSOLUTE = 0x8000
}
enum SendInputEventType : int
{
    InputMouse,
    InputKeyboard,
    InputHardware
}

public static void ClickLeftMouseButton()
{

    INPUT mouseDownInput = new INPUT();
    mouseDownInput.type = SendInputEventType.InputMouse;
    mouseDownInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_LEFTDOWN;
    SendInput(1, ref mouseDownInput, Marshal.SizeOf(new INPUT()));

    INPUT mouseUpInput = new INPUT();
    mouseUpInput.type = SendInputEventType.InputMouse;
    mouseUpInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_LEFTUP;
    SendInput(1, ref mouseUpInput, Marshal.SizeOf(new INPUT()));
}

这将左键单击任何名为“elementid”的元素在加载的 webBrowser 控件中。请注意可以轻松实现的其他 MouseEventFlags:

这是右键单击的示例:

public static void ClickRightMouseButton()
{
    INPUT mouseDownInput = new INPUT();
    mouseDownInput.type = SendInputEventType.InputMouse;
    mouseDownInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_RIGHTDOWN;
    SendInput(1, ref mouseDownInput, Marshal.SizeOf(new INPUT()));

    INPUT mouseUpInput = new INPUT();
    mouseUpInput.type = SendInputEventType.InputMouse;
    mouseUpInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_RIGHTUP;
    SendInput(1, ref mouseUpInput, Marshal.SizeOf(new INPUT()));
}

I've made many bot using c# and a simple webBrowser control.
Usually however i try to automate the "click" function on a element without the use of actually simulating a cursor and invoking a click.

Example:

webBrowser1.Document.GetElementById("elementid").InvokeMember("Click");

I find this much easier than actually simulating a cursor, however simulating a cursor can also achieved relatively easily , here's the code i usually make use of:

//Example of how to use it:
    Point controlLoc = this.PointToScreen(webbrowser1.Location);
    controlLoc.X = controlLoc.X + webbrowser1.Document.GetElementById("elementid").OffsetRectangle.Left;
    controlLoc.Y = controlLoc.Y + webbrowser1.Document.GetElementById("elementid").OffsetRectangle.Top;
    Cursor.Position = controlLoc;
    MouseSimulator.ClickLeftMouseButton();

public class MouseSimulator
 {
[DllImport("user32.dll", SetLastError = true)]
static extern uint SendInput(uint nInputs, ref INPUT pInputs, int cbSize);

[StructLayout(LayoutKind.Sequential)]
struct INPUT
{
    public SendInputEventType type;
    public MouseKeybdhardwareInputUnion mkhi;
}
[StructLayout(LayoutKind.Explicit)]
struct MouseKeybdhardwareInputUnion
{
    [FieldOffset(0)]
    public MouseInputData mi;

    [FieldOffset(0)]
    public KEYBDINPUT ki;

    [FieldOffset(0)]
    public HARDWAREINPUT hi;
}
[StructLayout(LayoutKind.Sequential)]
struct KEYBDINPUT
{
    public ushort wVk;
    public ushort wScan;
    public uint dwFlags;
    public uint time;
    public IntPtr dwExtraInfo;
}
[StructLayout(LayoutKind.Sequential)]
struct HARDWAREINPUT
{
    public int uMsg;
    public short wParamL;
    public short wParamH;
}
struct MouseInputData
{
    public int dx;
    public int dy;
    public uint mouseData;
    public MouseEventFlags dwFlags;
    public uint time;
    public IntPtr dwExtraInfo;
}
[Flags]
enum MouseEventFlags : uint
{
    MOUSEEVENTF_MOVE = 0x0001,
    MOUSEEVENTF_LEFTDOWN = 0x0002,
    MOUSEEVENTF_LEFTUP = 0x0004,
    MOUSEEVENTF_RIGHTDOWN = 0x0008,
    MOUSEEVENTF_RIGHTUP = 0x0010,
    MOUSEEVENTF_MIDDLEDOWN = 0x0020,
    MOUSEEVENTF_MIDDLEUP = 0x0040,
    MOUSEEVENTF_XDOWN = 0x0080,
    MOUSEEVENTF_XUP = 0x0100,
    MOUSEEVENTF_WHEEL = 0x0800,
    MOUSEEVENTF_VIRTUALDESK = 0x4000,
    MOUSEEVENTF_ABSOLUTE = 0x8000
}
enum SendInputEventType : int
{
    InputMouse,
    InputKeyboard,
    InputHardware
}

public static void ClickLeftMouseButton()
{

    INPUT mouseDownInput = new INPUT();
    mouseDownInput.type = SendInputEventType.InputMouse;
    mouseDownInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_LEFTDOWN;
    SendInput(1, ref mouseDownInput, Marshal.SizeOf(new INPUT()));

    INPUT mouseUpInput = new INPUT();
    mouseUpInput.type = SendInputEventType.InputMouse;
    mouseUpInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_LEFTUP;
    SendInput(1, ref mouseUpInput, Marshal.SizeOf(new INPUT()));
}

This will Left click on any element named "elementid" in a loaded webBrowser control. Notice the other MouseEventFlags that can easily be implemented:

Here's a example for right click:

public static void ClickRightMouseButton()
{
    INPUT mouseDownInput = new INPUT();
    mouseDownInput.type = SendInputEventType.InputMouse;
    mouseDownInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_RIGHTDOWN;
    SendInput(1, ref mouseDownInput, Marshal.SizeOf(new INPUT()));

    INPUT mouseUpInput = new INPUT();
    mouseUpInput.type = SendInputEventType.InputMouse;
    mouseUpInput.mkhi.mi.dwFlags = MouseEventFlags.MOUSEEVENTF_RIGHTUP;
    SendInput(1, ref mouseUpInput, Marshal.SizeOf(new INPUT()));
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文