标签: chess

国际象棋:Alpha-Beta中的错误

我正在实现一个国际象棋引擎,我已经编写了一个相当复杂的alpha-beta搜索例程,具有静止搜索和转置表.但是,我正在观察一个奇怪的错误.

评估函数使用了方块表,就像这个用于典当的:

static int ptable_pawn[64] = {  
   0,  0,  0,  0,  0,  0,  0,  0,
  30, 35, 35, 40, 40, 35, 35, 30,
  20, 25, 25, 30, 30, 25, 25, 20,
  10, 20, 20, 20, 20, 20, 20, 10,
   3,  0, 14, 15, 15, 14,  0,  3,
   0,  5,  3, 10, 10,  3,  5,  0,
   5,  5,  5,  5,  5,  5,  5,  5,
   0,  0,  0,  0,  0,  0,  0,  0
};
Run Code Online (Sandbox Code Playgroud)

当它转过黑色时,表格会在x轴上反射出来.具体来说,如果你很好奇,查找会发生这样的情况,其中AH列映射到0-7,而行的颜色是白色的0-7:

int ptable_index_for_white(int col, int row) {
    return …
Run Code Online (Sandbox Code Playgroud)

algorithm chess artificial-intelligence minimax alpha-beta-pruning

11
推荐指数
1
解决办法
652
查看次数

什么RESTful API将用于回合制游戏服务器?

您如何将回合制游戏服务器建模为RESTful API?例如,国际象棋服务器,您可以在其中与同一API的另一个客户端进行国际象棋游戏.您需要某种方式来请求和与其他客户协商游戏,以及某种方式来玩游戏的各个动作.

这是REST(RESTful)API的良好候选者吗?或者这应该以不同的方式建模?

rest chess

10
推荐指数
1
解决办法
9351
查看次数

任何人都知道一个好的.Net国际象棋引擎

我正在寻找一个体面的.Net国际象棋引擎.如果有一个好的国际象棋现有的,任何建议,一个好的候选人移植到.Net?

.net chess

10
推荐指数
2
解决办法
7729
查看次数

确定两个国际象棋位置是否相等

我正在为一个国际象棋变种引擎调试我的换位表,其中可以放置碎片(即最初不在板上).我需要知道我经常遇到关键的碰撞.我正在保存每个表索引中的片段列表以及通常的哈希数据.我确定两个位置是否相等的简单解决方案是转换失败,因为我是线性比较两个列表.

请不要建议我应该以板为中心而不是以件为中心进行存储.由于可放置和捕获的碎片的独特性,我必须存储碎片清单.这些状态中的碎片就像它们占据了重叠且无位置的位置.请查看存储片段的说明.

// [Piece List]
// 
// Contents: The location of the pieces.
//           Values 0-63 are board indexes; -2 is dead; -1 is placeable
// Structure: Black pieces are at indexes 0-15
//            White pieces are at indexes 16-31
//            Within each set of colors the pieces are arranged as following:
//            8 Pawns, 2 Knights, 2 Bishops, 2 Rooks, 1 Queen, 1 King
// Example: piece[15] = 6 means the black …
Run Code Online (Sandbox Code Playgroud)

algorithm chess

10
推荐指数
3
解决办法
2142
查看次数

Java编程 - 国际象棋移动(基本,没有AI)

我在设计国际象棋游戏时需要帮助.我已经开始了,但还没有走远,因为我对Java很陌生,实际上是编程新手.

无论如何,我有我的抽象类Piece和各个部分作为子类.我有一个方法movePiece,在我的抽象类中,我想为所有子类定义.

它目前所做的就是将这件作品从一个方格移动到另一个方格.我有一个可以容纳Piece对象的Square类,该板由64x1 Square数组组成.

我知道碎片是如何移动的,但我如何实际编程呢?我想尝试应用MVC模式,但这是我第一次使用模式.

基本上我正在考虑使用Graphics2D为每个Square创建一个盒子.然后,当玩家点击一块时,移动后可用作目的地的方块将以某种颜色勾勒出轮廓.玩家点击其中一个方格后,我在movePiece方法中已有的代码将运行.

我想要做的是在Piece的每个子类中覆盖我的movePiece方法.问题是,代码如何在其中一种方法中看到?以Pawn子类为例.

我不是要求复制/粘贴代码,只是关于如何执行此操作的一些指示,最后是一些示例代码.

谢谢!

public class Game {


@SuppressWarnings("unused")
public static void main(String[] args){
    Board board = new Board();
} }

public class Board {

Square[] grid;

public Board(){
    grid = new Square[64];
}   
public Square getSquare(int i){
    return grid[i];
}   
public void setDefault(){

}   
public Boolean isMoveValid(){
    return null;    
} }

public class Square {

private Piece piece;

public void addPiece(Piece pieceType, String pieceColour, String pieceOwner) 
        throws ClassNotFoundException, InstantiationException, IllegalAccessException{

    PieceFactory factory = new …
Run Code Online (Sandbox Code Playgroud)

java chess

10
推荐指数
1
解决办法
4万
查看次数

未来的棋子流动性

我目前正在用C#开发一个国际象棋引擎,我在开发代码时遇到了一些障碍,以确定任何给定棋子在1,2和3次移动中的未来移动性.基本的想法是奖励可以提高行动能力的奖励,并惩罚行动不便的作品.

棋盘表示为64个正方形的阵列,从0(a8)到63(h1)开始,例如

Piece[] _chessboard = new Piece[64];

我以这个棋盘位置为例:

Black Rooks on squares 3 & 19 (d8 & d6)
Black King on square 5 (f8)
Black Knight on squares 11 & 12 (d7 & e7)
Black Queen on square 16 (a6)
Black Pawns on squares 13, 14, 17, 18, 19 (f7, g7, b6 & c6)

White Rook on squares 58 & 42 (c1 & c3)
White King on square 53 (f2)
White Knight on square 40 (a3)
White Bishop on square …

c# chess

10
推荐指数
1
解决办法
1363
查看次数

Alpha-beta prunning with transposition table,迭代加深

我正在尝试使用转置表来实现alpha-beta min-max prunning增强功能.我用这个伪代码作为参考:

http://people.csail.mit.edu/plaat/mtdf.html#abmem

function AlphaBetaWithMemory(n : node_type; alpha , beta , d : integer) : integer;
    if retrieve(n) == OK then /* Transposition table lookup */
        if n.lowerbound >= beta then return n.lowerbound;
        if n.upperbound <= alpha then return n.upperbound;
        alpha := max(alpha, n.lowerbound);
        beta := min(beta, n.upperbound);
    if d == 0 then g := evaluate(n); /* leaf node */
    else if n == MAXNODE then
        g := -INFINITY; a := alpha; /* save original alpha value */
        c …
Run Code Online (Sandbox Code Playgroud)

algorithm chess artificial-intelligence minmax alpha-beta-pruning

10
推荐指数
1
解决办法
8336
查看次数

计算一定深度的Minimax树中的移动得分

我在C中实现了一个国际象棋游戏,具有以下结构:

移动 - 代表在char板上从(a,b)到(c,d)的移动[8] [8](棋盘)

移动 - 这是一个有头部和尾部的移动链表.

变量: playing_color是'W'或'B'.minimax_depth是之前设置的极小极大深度.

这是我使用alpha-beta修剪和getMoveScore函数的Minimax函数的代码,该函数应返回之前设置的某个minimax_depth的Minimax树中的移动得分.

我也在使用getBestMoves函数,我将在这里列出它,它基本上找到Minimax算法中的最佳移动并将它们保存到全局变量中,以便我以后能够使用它们.

我必须补充说,我将​​在这里添加的三个函数中列出的所有函数都正常工作并进行了测试,因此问题是alphabetaMax算法的逻辑问题或getBestMoves/getMoveScore的实现.

问题主要在于,当我在深度N处获得最佳动作时(为什么还没有计算出来),然后使用getMoveScore函数在相同深度上检查他们的分数,我得到的分数与得分不匹配那些实际的最佳动作.我花了几个小时来调试这个并且看不到错误,我希望也许有人可以给我一个关于找到问题的小费.

这是代码:

/*
* Getting best possible moves for the playing color with the minimax algorithm
*/
moves* getBestMoves(char playing_color){
    //Allocate memory for the best_moves which is a global variable to fill it in   a minimax algorithm//
    best_moves = calloc(1, sizeof(moves));
    //Call an alpha-beta pruned minimax to compute the best moves//
    alphabeta(playing_color, board, minimax_depth, INT_MIN, INT_MAX, 1);
    return best_moves;
}

/*
* Getting the score …
Run Code Online (Sandbox Code Playgroud)

c algorithm chess minimax alpha-beta-pruning

10
推荐指数
1
解决办法
907
查看次数

更有效地检测支票(国际象棋)

我目前正在开发一个国际象棋引擎,该引擎目前正在运行,但需要很长时间才能生成棋步。由于必须生成许多移动,因此检查检测花费的时间最长。

在尝试了很多事情之后,我陷入了困境,并且无法真正弄清楚如何使其更有效率。这是我如何做到的:

要检查移动是否允许/合法,我会检查进行移动的一方是否在之后受到检查:

    def allowed_move(self, board, pos, move, colour):

    copy_board = copy.deepcopy(board)

    (x, y) = pos
    (new_x, new_y) = move

    if copy_board[x][y] == "k_w":
        self.white_king = (new_x, new_y)
        copy_board[new_x][new_y] = copy_board[x][y]
        copy_board[x][y] = " "
        self.in_check(colour, copy_board)
        self.white_king = (x, y)

    elif copy_board[x][y] == "k_b":
        self.black_king = (new_x, new_y)
        copy_board[new_x][new_y] = copy_board[x][y]
        copy_board[x][y] = " "
        self.in_check(colour, copy_board)
        self.black_king = (x, y)

    else:
        copy_board[new_x][new_y] = copy_board[x][y]
        copy_board[x][y] = " "
        self.in_check(colour, copy_board)


    if colour == "_w" and self.white_check:
        return False …
Run Code Online (Sandbox Code Playgroud)

python chess

10
推荐指数
2
解决办法
449
查看次数

国际象棋中合法移动生成的java库

我正在寻找一个API来在国际象棋中生成合法的移动验证,最好是用Java语言.

我可以自己写,但这将是一个天真的实现,它会很慢.所以我需要一个工作库,允许或多或少的以下操作:

Board board = new Board();
board.reset();
board.isMoveLegal(playerNum, fromSquare, toSquare);
board.inputMove(playerNum, fromSquare, toSquare);
Run Code Online (Sandbox Code Playgroud)

我想要避免的是必须使用GUI,互联网连接或其他功能浏览完整的国际象棋游戏的代码源,而不是移动生成.对我来说这将是一个很大的浪费时间,我宁愿花几个小时来编写我自己的移动验证器,无论多慢.我也不需要任何编写自己的库的指南,因为我在互联网上找到了很多.

我在这里问这个是因为我在google上运行了几次搜索并没有找到我想要的内容.所以如果你知道的话,你可以指出一个这样一个工作代码的链接.谢谢.

java open-source chess

9
推荐指数
1
解决办法
4206
查看次数