python:国际象棋走法验证
有谁知道某处是否有免费的 python 国际象棋移动验证功能?
我需要什么。我有一个存储为字符串的图表,并移动候选者。我需要的是查看移动候选者是否对图表有效。
如果可能的话,我真的很想看看例子。
该字符串看起来像这样:
emememememememememememememememememembbememwpemememememememwpemembkememememememememememememememememwbembrememememwkemememememem
我知道这可能看起来很愚蠢,但我发现用这种方式编码位置是最简单的。对我来说,调动候选人就是另一个这样的职位(发生在下一步调动之后,我认为可以改变这种行为)
Does anybody know if there is a free python chess moves validation function available somewhere?
What I need. I have a diagram stored as a string, and move candidate. What I need is to see if move candidate is valid for the diagram.
Would be really interested to see examples, if possible.
The string looks this way:
ememememememememememememememememememembbememwpemememememememwpemembkememememememememememememememememwbembrememememwkemememememem
I understand it may seem stupid, but I find it the easiest to encode position this way. Move candidate for me is just another such position (which happened after next move, can change this behavior I think)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您缺少信息,例如轮到谁移动、每个国王是否曾经移动过(意味着不允许易位)、每个棋子的“en passant”状态。除此之外,使用不太复杂的板表示(例如描述的 10x12 元素数组)来编写自己的板表示是一个非常有指导意义的练习 此处(除非您将其线性化为 120 个元素的数组)。
You are missing information e.g. whose turn to move, whether each king has ever moved (means castling is not allowed), the "en passant" status of each pawn. That aside, it would be a very instructive exercise for you to write your own, using a not-very-complicated board representation like the 10x12-element array described here (except that you'd linearise it to a 120-element array).
我知道这是一个相当老的问题,但我和我的兄弟正在寻找同样的东西,我们遇到了这个很棒的小 python 模块,名为 栗子。
这是它的使用示例:
这里生成的输出:
太棒了! :)
感谢cgearhart!
I know this is a rather old question, but my brother and me were looking for the same thing and we came across this awesome little python module called Chessnut.
Here is an example of its use:
and here the generated output:
Awesome! :)
Thanks cgearhart!
只需使用 Python Chess 程序之一的源代码,例如 PyChess 或 Python Chess
具体来说,pychess 的有效动作:https://code.google.com/p/pychess/source/browse/lib/pychess/ Utils/lutils/validator.py
Just use the source of one of the Python Chess programs like PyChess or Python Chess
Specifically, the valid moves for pychess: https://code.google.com/p/pychess/source/browse/lib/pychess/Utils/lutils/validator.py
查看旁边的一些相关答案不会有什么坏处:国际象棋移动验证库和https://stackoverflow.com/questions/1239913/smallest-chess-playing-program对我来说很突出。
虽然我个人赞成建立你自己的。
Wouldn't hurt to look at some of the related answers on the side: Chess move validation library and https://stackoverflow.com/questions/1239913/smallest-chess-playing-program stand out to me.
Though personally I'm in favor of building your own.
查看 ChessBoard。
不幸的是它有一些缺点:
好处是代码是 GPL,所以只要你愿意,你就可以使用它遵守该许可证。
Check out ChessBoard.
Unfortunately it has some drawbacks:
The good thing is that the code is GPL so you can play with it as long as you stick to that license.
我在这里做了一个带有移动验证的简单国际象棋实现:https://github.com/akulakov/pychess
验证逻辑位于每个棋子的“moves()”方法中,您可以通过生成完整的棋步列表并检查您的棋步是否存在来验证您自己的棋步。
I've made a simple chess implementation with move validation here: https://github.com/akulakov/pychess
Validation logic is in each piece's "moves()" method, and you can validate your own move by generating full list of moves and checking if your move is there.