与XBoard(国际象棋引擎)(C ++ / C) [英] Communicating with XBoard (chess engine) (C++/C)

查看:253
本文介绍了与XBoard(国际象棋引擎)(C ++ / C)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是玩弄一个基本的国际象棋引擎。我能够从 http://web.archive.org/web/20070704121716/http://www.brucemo.com/compchess/programming/alphabeta.htm ,但真实网站已关闭,并非所有网页存档。 (任何人知道在哪里可以找到完整版本的Bruce的网站?)

I was just toying around with making a basic chess engine. I was able to get a lot of advice from http://web.archive.org/web/20070704121716/http://www.brucemo.com/compchess/programming/alphabeta.htm, but the real site is down and not all the pages are archived. (Anyone know where to find a full version of Bruce's site?)

但现在到真正的问题:如何与XBoard沟通?我理解是通过stdin和stdout,但我一直在代码中有问题。基本上,要开始使用,我只需要

But now to the real question: how do I communicate with XBoard? I understand it is via stdin and stdout, but I've been having problems in code. Basically, to get started, I just want to


  1. 从XBoard接收输入并将其打印到控制台/屏幕

  2. 给XBoard移动硬编码的输入,并让它移动

  3. 程序效用函数,并有一个随机棋子ai选择随机移动。

之后,我可以开始实现像alpha-beta搜索这样的实际操作。

After that, I can start implementing real things like alpha-beta searching.

我现在陷入前两件事。这里是一些我试图写/借的​​代码。

I am stuck on the first two things right now. Here is some code I have tried to write/borrowed.

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define STR_BUFF 256

using namespace std;

int main (int argc, const char * argv[])
{
    char input[STR_BUFF];
    char output[STR_BUFF];
    while(true){
        fflush(stdout);
        // read input
        if (!fgets(input, STR_BUFF, stdin)){
            printf("terminated");
            return 0;;
        }

        printf("%s", input);
    }
    return 0;
}

我只是回到C大约6个月后,这是第一个项目,我使用stdin / stdout管道与另一个程序(减去几个基本程序)进行通信,所以我会感谢任何帮助和任何解释。我知道编程国际象棋引擎是一个艰巨的任务,但我已经编程棋的规则,我可以找到的布鲁斯的网站是绝对惊人的。

I am just getting back into C after about 6 months break and this is the first project that I have used stdin/stdout pipelines to communicate with another program (minus a few basic programs) so I would appreciate any help and any explanations. I know programming a chess engine is a herculean task, but I have already programmed the rules of chess before and what I can find of Bruce's site is absolutely amazing.

推荐答案

你做的几乎是正确的:从XBoard用 fgets 获取一个命令,然后使用 printf fflush 。 (有一件事是错误的:你不需要'打印命令到控制台/屏幕';你不是与控制台/屏幕通信;你只从XBoard读取命令,并发送移动回到XBoard)。

You are doing it almost right: get a command from XBoard with fgets, then report a move with printf and fflush. (One thing is wrong, though: you don't need to 'print the command to the console/screen'; you are not communicating with the console/screen; you only read commands from XBoard and send moves back to XBoard).

也许,从一些现有的代码开始会更容易。尝试阅读 GNU棋的来源。或下载任何其他象棋引擎的来源,支持XBoard协议。

Probably, it would be easier to start with some existing code. Try to read sources for GNU Chess. Or download sources for any other chess engine, supporting XBoard protocol.

这里是有关国际象棋引擎编程的许多信息的其他问题:什么是一些好的资源写一个象棋引擎?

And here is other question with lots of information on chess engine programming: "What are some good resources for writing a chess engine?".

这篇关于与XBoard(国际象棋引擎)(C ++ / C)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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