我该如何正确地检查易位国际象棋AI? [英] How do I correctly check for castling in chess AI?

查看:167
本文介绍了我该如何正确地检查易位国际象棋AI?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个国际象棋的AI,这并不总是知道它是否能城堡与否。白嘴鸦和国王有移动计数器,只允许他们参加在城堡当移动计数器的值为零。当移动计数器都是零,也没有碎片挡住了城堡,但敌人件具有从远处阻止城堡的能力出现了问题。

I have a chess AI that doesn't always know if it can castle or not. The rooks and kings have move counters that only allow them to participate in a castle when the value of the move counter equals zero. A problem occurs when the move counters are zero and there are no pieces blocking the castle, but an enemy piece has the ability to block the castle from afar.

例如,假设你是小白,你想使王后身边的城堡。此举计数器是零,那么你的作品取得了零的动作,和你的白衣骑士,主教和皇后都没有了。在你认为你可以城堡。但是你却不能城堡,因为有敌人车有明确的界限攻击延伸一路下跌到你有你的白乌鸦,白王的第一行。如果您易位,国王将不得不穿过攻​​击黑车的路线。你是AI而这种情况搞砸了你。

For example, imagine that you are white and you want to make a queen side castle. The move counters are zero, so your pieces have made zero moves, and your white knight, bishop, and queen are gone. The you thinks that you can castle. But you actually cannot castle because there is an enemy rook with a clear line of attack that extends all the way down to the first row where you have your white rook and white king. If you castled, the king would have to cross the black rook's line of attack. You are the AI and this situation messed you up.

现在你[人]可能知道一种方法,使您[艾]聪明,当涉及到易位。你会如何​​,作为一个程序员,解决这个问题,使得AI不会犯这个错误了吗?

Now you [the human] might know a way to make you [the AI] smarter when it comes to castling. How would you, as a programmer, fix this problem such that the AI doesn't make this mistake anymore?

下面是一些更多的信息.​​.. 我的主板重新presentation为int板[8] [8]。我有一个包含所有可能的白块[最多2个皇后,17个总]数组,诠释whitePieces [17],和阵列包含所有可能的黑片,诠释blackPieces [17]。此外,为了跟踪的运动,是有MOVETO []数组以及包含,对每一个帘布层,所述移动件的副本之后它移动和之前它移动一个moveFrom []数组。片整数的最右边的位是y值和4位的十六进制值一个比从即x值。整数片还包含字节数据重新presenting片类型,片颜色,在whitePieces阵列或blackPieces阵列的片的位置,和一个移动计数器,保持的移动次数的轨道,并用于确定是否国王或车已经移动,因而不能城堡。

Here's some more information... My board representation is int board[8][8]. I have an array that holds all possible white pieces [max 2 queens, 17 pieces total], int whitePieces[17], and array that holds all possible black pieces, int blackPieces[17]. Also, to keep track of movement, there is a moveTo[] array and a moveFrom[] array that contains, for each ply, a copy of the moving piece after it moved and before it moved. The rightmost bit of the piece integer is the y value and the 4 bit hexadecimal value one over from that is the x value. The integer piece also contains byte data representing the piece type, the piece color, the pieces location in the whitePieces array or the blackPieces array, and a movement counter that keeps track of the number of moves and is used to determine if a king or rook has moved and thus cannot castle.

推荐答案

您的AI应该有某种0股威胁电网,其中显示出每一个敌人一块可以移动的下一回合。使用此信息,看看国王和<打击>车(S)最后王车易位的位置(S)之间的平方要么占用或受到威胁。

Your AI should have some sort of 0-ply "threat grid" that shows where every enemy piece can move next turn. Use this info to see if the squares between the king and rook(s)the final castling location(s) are either occupied or under threat.

这篇关于我该如何正确地检查易位国际象棋AI?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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