python: Chess moves validation

Oleg Tarasenko picture Oleg Tarasenko · May 18, 2010 · Viewed 7.5k times · Source

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)

Answer

John Machin picture John Machin · May 18, 2010

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).