This is a simple C# application to simulate chess games using the standard console and Unicode characters.
This is a simple C# application to simulate chess games using the standard console and unicode characters.
When launched, a new game will begin on white’s turn. After a move is made the turns will alternate between black and white until checkmate is achieved.
At this point a new game will start when any key is pressed. The console may not display the chess characters correctly with the default font “consolas”.
It is recommended to change your font to “NSimSun” at size “48” for the best results. Other True Type fonts will work, but not all have been tested.
All the moves in game are described using chessboard positions which are described in the x-axis by a letter (a - h), and
in the y-axis by a number (1 - 8). To make a move a 4-character string must be entered. The first two characters must refer to
a position on the board which holds one of your pieces. The second two characters must refer to a valid position which that
piece can move to.
For example:
There are also two formats of 3-character strings that can be input to retrieve more information about a specific piece.
The first character determines what information you are trying to retrive, whilst the second and third characters represent the position of the piece.
A first character of “m” will show all the valid possible moves that a piece can make.
A first character of “s” will show if a king is in check and/or checkmate (this only works if a valid position of a king is given)
For example:
Before starting this project, I decided that I wanted to create a chess game without any direct represenation of the board itself. This meant
that I did not use any arrays, lists, vectors etc to represent all the possible spaces on the board. Instead I decided to approach the game
from the pieces perspective. This lead to an object orientated approach, with the “board” being represented as a dictionary where the
keys are strings of board positions and the values are chess piece objects.
In terms of rendering the board it was mostly just the case of building strings for each line of the board and then printing them sequentially.
All of the responsibility of printing to the console is handled by the BoardRender class. I also wanted to be able to draw the board using
a more traditional co-ordinate system, so there are methods available to convert chess positions into x, y co-ordinates and vice verca.
See the image below for a representation of how the chess positions relate to the co-ordinate system.
There are currently 3 known missing features which are part of the standard game of chess. These are listed in order of priority.
It would be nice to add basic online functionality so that two users can play remotely.
It would also be interesting to experiment with chess AI, both more traditional searching approaches (min-max, alpha-beta etc) as well as statistical and
ML approaches (Reinforcement learning, monto carlo etc).
Copyright (c) 2015-2021 Chris Haynes and others
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
“Software”), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.