Skip to content

royojeda/chess

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Chess


Description

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.


Table of Contents


Installation

There are a couple of ways to run the software:

  1. The first one is to visit the online live preview. Once there, simply click the Play icon or the Run button.

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


Usage

Loading a save file

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.

Turns

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.

Saving the game

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.


Features

Aside from those shown above, here are some other things that the application can handle:

  • Castling.

  • En passant.

  • Promotion.

  • User error

    1. Player input is not in a valid format.

    2. A player tries to move an empty square.

    3. A player tries to move an opponent's piece.

    4. A player tries to move a piece to an invalid destination.

      1. The piece's characteristic moves don't include the destination.

      2. The destination contains an allied piece and/or, for pawns, an enemy piece.

      3. Except for knights, the way to the destination is blocked by another piece.

      4. For pawns, a normal diagonal capture move doesn't capture an enemy piece.

      5. For en passant, the required conditions are not met.

      6. For castling, the required conditions are not met.

      7. Moving to the destination leaves the player's king in check.

  • Checkmate

  • Stalemate

  • Highlighting the opponent's previous move

Tests

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.


Reflections

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.