Command-line chess program written in C++ that supports two human players on a shared terminal. The engine prints an ASCII board after every legal move, enforces movement rules for every piece (including castling), and detects check, checkmate, and stalemate conditions.
- Legal move generation for pawns, knights, bishops, rooks, queens, and kings on an 8x8 ASCII board.
- Castling validation that ensures both king- and queen-side paths are clear and safe.
- Detection of check, checkmate, and stalemate to automatically end a game.
- Simple algebraic-style coordinate input (
e2 e4) with case-insensitive file parsing. - Minimal dependencies: relies only on the C++ standard library for portability.
- C++17-compatible compiler (
g++,clang++, MSVC, etc.). - A terminal or shell capable of reading standard input and printing ASCII text.
g++ -std=c++17 chess.cpp -o chessThe command above compiles chess.cpp into an executable named chess. Adjust the compiler invocation if you prefer warnings or optimizations (for example, add -Wall -Wextra -O2).
./chessThe program initializes the standard chess starting position, greets the players, and prints the board. White moves first. Type exit (either in the from or to prompt) to quit early.
- Use coordinates in
file-rankformat, where files are lettersathroughhand ranks are digits1through8. - Supply moves as two space-separated coordinates:
from_square to_square. - Examples:
e2 e4,g1 f3,c7 c5. - Moves are case-insensitive (
E2 E4works). - Illegal moves trigger a warning and do not toggle the active player.
$ ./chess
hello world! Welcome to my chess arena....
8 r n b q k b n r
7 p p p p p p p p
6 . . . . . . . .
5 . . . . . . . .
4 . . . . . . . .
3 . . . . . . . .
2 P P P P P P P P
1 R N B Q K B N R
a b c d e f g h
White's move: e2 e4
8 r n b q k b n r
7 p p p p p p p p
6 . . . . . . . .
5 . . . . . . . .
4 . . . . P . . .
3 . . . . . . . .
2 P P P P . P P P
1 R N B Q K B N R
a b c d e f g h
Black's move: e7 e5
- No support yet for en passant captures or pawn promotion selection (pawns remain queens by default in future improvements).
- No move history, PGN export, or undo functionality.
- Future enhancements could include AI-driven opponent modes, timing controls, or richer command parsing.
chess.cpp— main program containing board initialization, move generation, and game loop.chess— optional compiled binary created after running the build command.Readme.md— this guide.