guilherme-vasconcelos / js-crazychess-lib Goto Github PK
View Code? Open in Web Editor NEWChess library
License: GNU General Public License v3.0
Chess library
License: GNU General Public License v3.0
Think about more edge cases for tests. Perhaps more tests in regards to check positions.
Most of the methods already have docstrings (although depending on the library used the docstrings might need some changes).
We either need a library that can automatically generate documentation, or perhaps create a docs/readme.md file with all API reference.
constants file to store certain values like colors.
Currently, we have a method to load a given FEN, but after that we don't track the position FEN anymore.
Features to be added in getCurrentFEN method:
Important: even though the basic method is already implemented, we still don't have support for castling, halfmove count and en passant. Because of that, the getCurrentFEN method does not work for these mentioned items.
Finish #1 before proceeding to implement the complete version of getCurrentFEN.
Rules: https://en.wikipedia.org/wiki/Portable_Game_Notation
Requires #10, because the notation used in PGN must be the move itself rather than the current initial_location -> final_location
pattern used in Board.move method.
The rules for en passant are:
In order to implement en passant, it would probably be useful to keep track of which moves were played and by which piece (this can also help with #17). This way we only need to check if last move played was a pawn move and whether it fulfills the required conditions for en passant or not.
Remember that if en passant is possible the FEN must also be updated. We should have an attribute Board.isEnPassantPossible so that the FEN can be updated accordingly when user calls Board.getCurrentFEN.
Currently the library does not have a contributing guide. It must have:
Requires #18.
The rules for stalemate are:
Implement a wrapper for Board.move called Board.play, which should allow the user to move pieces like this:
Board.play('e4')
rather than Board.move('e2', 'e4')
Board.play('Nf3')
rather than Board.move('g1', 'f3')
Note: sometimes, writing a move like 'Nd7' can be ambiguous if more than one knight can reach d7. Because of this, the library has to throw error in case of ambiguity, which can be avoided by playing something like 'Nbd7' to specify which knight to move to d7.
Sometimes it will still be ambiguous to specify the column in which the piece you want to move is located at, in which case you should specify its row with a number (e.g.: 'N7b6' means to move knight from row 7 to b6).
Line to adapt: const rowIncrementValues = { P: -1, p: 1 };
https://stackoverflow.com/questions/2274242/how-to-use-a-variable-for-a-key-in-a-javascript-object-literal
Replace P and p by WHITE_PAWN_NAME and BLACK_PAWN_NAME, respectively.
It will be useful for docs since some parameters are too vague (e.g.: Board's constructor accepts as parameter an Object).
https://www.typescriptlang.org/docs/handbook/declaration-files/introduction.html
https://stackoverflow.com/a/53710641/10416161
Add better install instructions for people who want to use the library.
After installing from GitHub, the user will be able to import the library like this: import { Board } from 'js-crazychess-lib';
In order to implement checkmates and castling (and perhaps other stuff) it would be useful to have a method to verify if it will be a check position after moving a certain piece from position X to position Y and not throw an exception. For instance, in order to implement checkmates one correct attempt would be to verify if, for all your legal moves available, all of them will result in a check position (this attempt may be inefficient, but it works and is only an example).
What we have at the moment:
What the new method will aim to achieve:
Considerations:
Implementation tips:
Sub-tasks:
The main purpose of the library is to allow some chess variants. In order for this to happen we have to analyze a few possible solutions:
OR
As soon as a pawn reaches the farthest available position in the board (i.e. from white's perspective: either the eigth row if it's a white pawn, or the first row if it's a black pawn) it can promote to another piece.
Rules for promotions:
Currently everything is using a generic Exception class, so the exception tests are messy.
If in doubt about the exception message when implementing the custom exceptions, ctrl + f the files (helpers, pieces and board) and search for throw new
.
When calculating legal squares available, the rule that must be taken into consideration in regards to checks and mates are:
If none of the conditions above will get the king out of check, then it is checkmate.
NOTE: Checks do not apply to some of the variants that will be implemented, so there should be some trigger to ignore checks and mates
Progress:
It could be useful to verify legal moves, number of pieces or other things.
Implement a method to return all pieces (either from a specific color or not).
Currently what is being done is basically iterating over the entire board, looking for anything that is not a NullPiece.
testing to do automation.
https://github.com/Guilherme-Vasconcelos/js-crazychess-lib/projects/1
Right now, the FEN support is still very basic. It only supports setting up pieces, but not castling / en passant / counting moves, etc.
For example, in a complete FEN (e.g. rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1) you can see the w KQkq in the end. This indicates that it's white to play (w), white has castling rights on both sides (KQ) and black has castling rights on both sides (kq). At the moment, the library completely ignores everything after the first space.
Castling
Determine whose turn is it
Threefold / fifty moves draw
En passant
When calculating the King's legal squares, the rules that must be taken into consideration for castling are:
If conditions above are fulfilled, the king can castle by:
For the moment, there is no need to consider pawns promotions and en passant.
The current logic for pawns legal squares works sometimes, but it has a few problems:
The logic for pawns legal squares is located at method Board._updateLegalSquares, case 'P' and case 'p'.
The board must track who should play next.
This can probably be done just with a simple attribute in class Board, the hardest part will be to check for the custom FEN.
Probably with GitHub Actions.
Since I mistakenly commited TDD failing tests to master, probably comment them out (please don't remove them) if you're going to set up CI before implementing the features those tests need.
Also, change Babel stuff to be devDependencies since they are only needed for tests.
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.