cgearhart / chessnut Goto Github PK
View Code? Open in Web Editor NEWPython chess model
License: The Unlicense
Python chess model
License: The Unlicense
Error trace:
File "build/bdist.linux-x86_64/egg/Chessnut/game.py", line 128, in apply_move
Chessnut.game.InvalidMove:
Illegal move: e8c8
fen: 1QQ1r3/3k1p1p/4p1p1/8/8/1N2P3/5PPP/2R3K1 b - - 0 40
The move cache only includes the moves from a single ray, and is not properly updated for moves that are eliminated by the filtering in get_moves(). Since the library doesn't currently support an "undo" mechanism, the easiest solution (for now) is to just eliminate the cache entirely.
Hey, I've found a fen string for that you'll not receive the correct list of valid moves. The minimal test:
from Chessnut.game import Game
chessgame = Game()
chessgame.set_fen('r3kb1r/p1p2pp1/2p4p/3Pp3/6b1/2P5/PP1NN2P/R2QK1q1 w Qkq - 0 16')
try:
assert (chessgame.get_moves() == ['d2f1', 'e2g1'])
print 'Test passed.'
except AssertionError:
print 'Test failed.'
The FEN corresponds to this position with white to move. Chessnut only returns the d2f1 move, but fails to return e2g1 knight capturing the queen.
It would be nice if we could input the moves using the short algebraic notation that is standard in the pgn format, e.g., e4 e5 Nf3, in addition to the long format currently supported.
The public api would get only one additional method, Game.apply_san_move(san_string)
. I have already implemented this and will open a pull request. I'd like to use Chessnut in a hobby project, but want to be able to read in pgn games.
Nice to have - if there were some state variable for who is in checkmate.
I tried using the module and get:
File ".../moves.py", line 122, in MOVES['k'][4][1].append(2) IndexError: list index out of range
Same for
MOVES['K'][60][0].append(62)
MOVES['K'][60][4].append(58)
and
MOVES['p'][8 + i][IDX].append(24 + i)
MOVES['P'][55 - i][IDX].append(39 - i)
What is the issue here?
edit
Sorry: Issue was due to python2 -> python3 conversion (i.e. / vs //)
Library works as expected. thx. Can be closed.
get_moves() for fen="2r2rk1/p4p1p/1p6/2qNP1pb/Q1p1nB2/2P1PPP1/PP5P/3R1RK1 w - g6 0 22" does not allow the legal move f3e4.
A move for a pawn going on the last line is a promotion : departure, arrival, promotion piece.
This special move format make the "in check" test fails when comparing king position to pawn destination.
Proposed fix : #16
There was an issue my team and I had when writing an AI that works alongside Chessnut. For some reason, even after following the installation instructions and pip installing into a virtual environment, we were unable to capture a piece that was putting our king in check. We had checked the list of moves (from Game.get_moves()) and the move was not found.
Here is the fen of the board state:
rnb1kbnr/pppp1ppp/4p3/8/2B1P3/5N2/PPPP1P1P/RNBQK1q1 w Qkq - 0 5
https://github.com/cgearhart/Chessnut/blob/graph/Chessnut/game.py#L242
Move that expose the king by lifting a piece can still be legal as long as the king is safe at the end of the move.
Is it possible to somehow detect whether the current position is mate or stalemate? One way to check would be to see if the list of moves is empty (than one or the other would hold), and then to confirm whether or not the king is in check...
If not, that would be a really really helpful feature...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.