Skip to content

ParthPore10/Chess-engine

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Readme.md

Chess Engine

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.

Features

  • 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.

Requirements

  • C++17-compatible compiler (g++, clang++, MSVC, etc.).
  • A terminal or shell capable of reading standard input and printing ASCII text.

Build

g++ -std=c++17 chess.cpp -o chess

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

Run

./chess

The 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.

Move Entry

  • Use coordinates in file-rank format, where files are letters a through h and ranks are digits 1 through 8.
  • Supply moves as two space-separated coordinates: from_square to_square.
  • Examples: e2 e4, g1 f3, c7 c5.
  • Moves are case-insensitive (E2 E4 works).
  • Illegal moves trigger a warning and do not toggle the active player.

Sample Session

$ ./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

Limitations and Ideas

  • 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.

Repository Layout

  • 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.

About

Its a chess engine developed using CPP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages