

With the above rules, two humans can play a game, but we want to play against the computer, so let’s get to the heart of the matter. Note that this rule is largely accepted by the Chess community. I also implemented another rule to avoid never-ending games: if there has been neither pawn move, nor a capture within the last 50 moves, the game is a draw. Both kings are alone on the board (or with insufficient material to win).Both players repeat the 3 same moves in a row or.There is no possible move but your king is not in check ( stalemate) or.Now how does the game finish? There are two scenarios: either a player wins, or neither win (draw).Īs already mentioned, you lose when your king is in check and that there is no possible move to escape being in check. Both kings always being spaced a square apart.Detection of whether a king is in check, and when there is no way to escape from this, determining that the king is checkmate (game lost).It is out of scope to explain every single rule here but I tried to implement most of the constraints, among others: Now that we can move pieces, we must take into account the rules of the game: there are things that can be done, as well as things that must be done (typically, escaping check). I finally added them on the sides of my board, and here is the result, a simple 10x10 grid:Ĭolored borders around squares for a better view of moves Rules If you are familiar with Chess you probably know that the board grid has a coordinate system made of letters (horizontal axis, or files) and digits (vertical axis, ranks) which is used for game notation, i.e. I started with the definition of the dark and light backgrounds, where each square is a label containing either an empty value or the Unicode symbol of a piece. Fortunately, I discovered that each symbol is part of the Unicode: a basic text label is thus sufficient to draw a piece! Perfect, I was already able to print the board in the console logs to visualize it: ♜ ♞ ♝ ♛ ♚ ♝ ♞ ♜ ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♟ ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♙ ♖ ♘ ♗ ♕ ♔ ♗ ♘ ♖įunny, but not as good-looking as what I had in mind, so I decided to create a basic GUI: the board is a single frame, with a grid layout, driven by a MVC architecture. But that would force me to manage pictures, which was not desirable for quick development.
Stockfish chess move calculator free#
When I thought about drawing the pieces, I first started considering free graphic resources. Now is the time for a visual representation of that board. two-dimensional array), alternating dark and light backgrounds. The board is a squared grid of 8x8 cases (i.e.

A range of pawns in front of the other pieces, the royal couple in the center, then symmetrically come the bishops, knights, and finally rooks.

Then for each side, there are the following pieces:Īt the beginning of the game, the initial position is always the same, strictly defined. Chess is played by two opponents, one color for each, white and black pieces.
