Python: checking hosts for chess

Does anyone know if there is a python checkerboard validation function somewhere available?

What I need. I have a chart stored as a string, and moving a candidate. I need to check if the candidate is valid for the chart.

It would be really interesting to see examples, if possible.


The line is as follows:

emememememememememememememememememememembbememwpemememememememwpemembkemememememememememememememememememwbembrememememwkememememememem

I understand that this may seem silly, but I find it easiest to code the position this way. For me, moving a candidate is another such position (which happened after the next step, can change this behavior, I think)

+5
source share
5 answers

You do not have enough information, for example. whose turn it is to move, regardless of whether each king has ever moved (meaning castling is not allowed), the status of "en passant" of each pawn. As an aside, it would be a very instructive exercise for you to write your own using a not very complex representation of the board, such as the 10x12 array described here (except that you linearize it into a 120-element array).

+5
source

I know this is a pretty old question, but my brother and I were looking for the same thing, and we came across this amazing little python module called Chessnut .

Here is an example of its use:

#!/usr/bin/python
from Chessnut import Game

chessgame = Game(fen="rnbq1rk1/ppppp1bp/5np1/5p2/2PP4/2NBPN2/PP3PPP/R1BQK2R b KQ - 4 6")
print chessgame  

print chessgame.get_moves()

# apply a move 
chessgame.apply_move(chessgame.get_moves()[1])

print chessgame

:

rnbq1rk1/ppppp1bp/5np1/5p2/2PP4/2NBPN2/PP3PPP/R1BQK2R b KQ - 4 6
['b8a6', 'b8c6', 'd8e8', 'f8e8', 'f8f7', 'g8h8', 'g8f7', 'a7a6', 'a7a5', 'b7b6', 'b7b5', 'c7c6', 'c7c5', 'd7d6', 'd7d5', 'e7e6', 'e7e5', 'g7h8', 'g7h6', 'h7h6', 'h7h5', 'f6e8', 'f6d5', 'f6e4', 'f6g4', 'f6h5', 'g6g5', 'f5f4']
r1bq1rk1/ppppp1bp/2n2np1/5p2/2PP4/2NBPN2/PP3PPP/R1BQK2R w KQ - 5 7

Awesome!:) cgearhart!

+4

ChessBoard.

, :

  • it seems to be abandoned because the errors reported more than a year ago in the comments do not seem to be fixed.
  • the code does not meet the requirements of PEP-8
  • some methods are very ugly and large, not all methods have docstrings
  • there are no unit tests, so delving into this code can be a problem (I already tried this at least twice and couldn't)

It's good that the code is GPL, so you can play with it while you stick to this license.

0
source

All Articles