A command line application written in C# for playing Chess.
Figure 1: Main menu
Figure 2: Chess match rendered using default theme
Figure 3: Chess match rendered using unicode piece theme with start menu opened.
-
Navigate to the cloned project directory in your command line. The project can be built using by running
dotnet publish -c Release -r {RUNTIME_IDENTIFIER}
(see documentation). For example, if you wish to build for OSX 10.15, you could usedotnet publish -c Release -r osx.10.15-x64
. -
The built executable should be available in
SharpChess/SharpChess/bin/Release/netcoreapp{version}/{RUNTIME_IDENTIFIER}/publish
(e.g.,SharpChess/SharpChess/bin/Release/netcoreapp3.1/osx.10.15-x64/publish
). -
On mac, the executable can be run from the
publish directory
in the terminal from./SharpChess
.
The control scheme is described below. Type any of the following characters to send input to the application.
w
- Move cursor up.d
- Move cursor right.s
- Move cursor down.a
- Move cursor left.- space - Enter/select element currently highlighted by cursor.
q
- Opens the match menu when pressed during a match. The match menu can be used to save a match in the middle of a game.t
- Toggles the board theme when pressed in the middle of a match.f
- Flips the board about the horizontal axis passing between rows 4 and 5.u
- Undo the previous turn when pressed during a match. This will decrement the displayed turn number, return the piece moved in the last turn to its previous location, move the cursor to the previous destination, and toggle the current user. This command does nothing on turn 1. After loading a saved game, you cannot undo turns that were played before saving.r
- Redo an undone turn. Reverses all changes from the last undo command. Note: The redo cache will be cleared if you undo a command, then set a new space prior to redo.
While playing a match, the user can select the “Save” option in the start match menu to save a game. Then, selecting the “Load” option in the main menu will start the saved match. The game is saved by serializing the match to a text format and writing the result to a text file. An example of a serialized match is the following:
r:b,k:b,b:b,Q:b,K:b,b:b, : ,r:b,
p:b,p:b,p:b,p:b,p:b,p:b,p:b,p:b,
: , : , : , : , : , : , : ,k:b,
: , : , : , : , : , : , : , : ,
: , : , : , : , : , : , : , : ,
: , : , : , : , : , : , : ,k:w,
p:w,p:w,p:w,p:w,p:w,p:w,p:w,p:w,
r:w,k:w,b:w,Q:w,K:w,b:w, : ,r:w,
turn:2
The first eight rows in the file correspond to the row of the board, while the last row records the current turn number as turn:{current turn number}
. The first eight rows contain piece tokens of the format {piece type token}:{piece color token}. Each piece token is delimited by a comma. Mappings of the piece type token to piece type and piece color token to piece color are shown in figures 4 and 5, respectively.
Piece type token | Piece type |
---|---|
K | King |
Q | Queen |
r | Rook |
b | Bishop |
k | knight |
p | Pawn |
Null piece |
Figure 4: Map of piece type tokens to piece types.
Piece color token | Piece color |
---|---|
b | Black |
w | White |
Null piece color |
Figure 5: Map of piece color tokens to piece colors.
This history feature (undo and redo commands which are accessible during a match) utilize the well-known memento pattern, where the Board
class (see SharpChess/SharpChess/Domain/Board.cs
) acts last the originator, the BoardMemento
class (see SharpChess/SharpChess/Domain/BoardMemento.cs
) acts as the memento, and the History
class (see SharpChess/SharpChess/Domain/History.cs
) acts as the caretaker.