从库python-chess on line命令可视化完整的国际象棋棋盘 [英] Visualize the full chess board from the library python-chess on line command

查看:109
本文介绍了从库python-chess on line命令可视化完整的国际象棋棋盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在基于该库进行国际象棋游戏: https://pypi.org/project/python-chess/ https://github.com/niklasf/python-chess

I am working a chess game based on this library: https://pypi.org/project/python-chess/ or https://github.com/niklasf/python-chess

在Jupyter Notebook上,如果我运行以下代码:

On Jupyter Notebook, if I run this code:

import chess
board = chess.Board()
board

它将显示一个漂亮的棋盘(即颜色,形状,看起来像国际象棋棋盘的棋盘).如果我这样运行:

It will display a nice board (i.e. with colors, shape, looking like a chess board). If I run like this:

import chess
board = chess.Board()
print(board)

它将以更基本的方式用字母显示面板.

It will display the board in a much more rudimental way with letters.

问题在于,使用"board"命令查看精美木板的唯一方法是使用Jupyter Notebook.如果我尝试在Visual Studio或行命令上运行,则命令"board"将不会发生任何事情.似乎line命令将不支持"board"的使用(在他们的网站上:支持Python 3.6+和PyPy3.IPython/Jupyter Notebook集成).

The problem is that the only way of seeing the nice board, using the "board" command, is if I am using Jupyter Notebook. If I try to run on Visual Studio or line command the command "board" nothing will happen. It seems that the line command will not support the use of "board" (from their website: Supports Python 3.6+ and PyPy3.IPython/Jupyter Notebook integration).

有没有解决的办法?换句话说,我仍然可以在命令行上运行木板"并可视化漂亮的国际象棋棋盘吗?

Is there a way around this? In other words, can I still run "board" on command line and visualize the nice chess board?

推荐答案

如果您只想以图形方式显示职位,则可以安装并使用

If all you want to do is simply graphically display a position, you can install and use the chess-board package. I use it in tandem with the one you are talking about in the following example:

import chess

from chessboard import display
from time import sleep

board = chess.Board()

move_list = [
    'e4', 'e5',
    'Qh5', 'Nc6',
    'Bc4', 'Nf6',
    'Qxf7'
]

display.start(board.fen())
while not display.checkForQuit():
    if move_list:
        board.push_san(move_list.pop(0))
        display.update(board.fen())
    sleep(1)
display.terminate()

但是,在灵活性和良好性方面,目前感觉缺乏此软件包.您至少必须打开软件包display.py文件,并在start()函数的开头添加一行.否则,您将无法使用display.update().

This package however currently feels quite lacking when it comes to flexibility and well... sanity. You would have to at least open the packages display.py file and add one line at the beginning of the start() function. Otherwise, you will not be able to use display.update().

def start(fen=''):
    global gameboard

我看到您很久以前发布了此问题.尽管如此,我希望您觉得这很有用.

I see you posted this question a long time ago. Nonetheless, I hope you find this useful.

这篇关于从库python-chess on line命令可视化完整的国际象棋棋盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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