A demonstration of the shortest stalemate
(https://www.chess.com/forum/view/game-showcase/the-shortest-stalemate)
This is a game of chess that can be played on the terminal by two human players.
The project's development incorporates a large portion of the concepts that I have encountered while studying object-oriented design with Ruby, along with some additional tricks that I have picked up since the beginning of this undertaking.
There are a couple of ways to run the software:
-
The first one is to visit the online live preview. Once there, simply click the
Play
icon or theRun
button. -
The other option is to clone the repository to your computer by running the following command in the command line (you must have Git and Ruby installed):
git clone [email protected]:royojeda/chess.git
and then run:
cd chess
to enter the project directory, and finally, run:
ruby lib/main.rb
to get the application running.
The live preview method is easier, but the local clone method has better performance (i.e., less stuttering).
As you run the application, there will be a prompt to decide whether or not to load a saved game.
A sample save file is included in the repository, but you can also save your game at the start of every turn for later continuation.
If unsure, simply enter n
to start a new game.
As with any standard game of chess, White moves first.
The current player is now asked for the location of the piece that they want to move.
The possible move(s) for that piece are highlighted, and a second prompt asks for a location to which the player wants to move the selected piece.
Finally, the move is executed, and the other player begins their turn.
The locations are expected to be entered in Algebraic Notation.
Instead of selecting a piece, the player can also enter save
at the start of every turn to save the current game conditions to a file that can be loaded in later.
Aside from those shown above, here are some other things that the application can handle:
-
User error
-
Player input is not in a valid format.
-
A player tries to move an empty square.
-
A player tries to move an opponent's piece.
-
A player tries to move a piece to an invalid destination.
-
The piece's characteristic moves don't include the destination.
-
The destination contains an allied piece and/or, for pawns, an enemy piece.
-
Except for knights, the way to the destination is blocked by another piece.
-
For pawns, a normal diagonal capture move doesn't capture an enemy piece.
-
For en passant, the required conditions are not met.
-
For castling, the required conditions are not met.
-
Moving to the destination leaves the player's king in check.
-
-
-
Highlighting the opponent's previous move
The application is not developed in a test-first manner. Nevertheless, I wrote several automated tests afterward, and I can recall at least a couple of instances where a bug was discovered immediately because of these tests.
Run the tests by executing
rspec
in the command line.
This has been one of the most complex pieces of software that I've made. At the time of writing, this is probably my best work yet, although I do know that it's not perfect.
I've decided that any further improvement would not be worthwhile to me at this time. The project specifications are met, along with several additional features that I added just because I think they are essential to my interpretation of a usable chess game. Where or not it's good is subjective, but for now, it's good enough.