Text Based Chess Using C
Text Based Chess Using C
C
The project ‘DESIGNING OF TEXT BASED CHESS GAME USING COMPUTER
GRAPHICS’ implements a classic version of Chess with the help of
GRAPHICAL USER INTERFACE(GUI).
The Chess game follows the basic rules of chess, and all the chess
pieces only move according to valid moves for that piece. This project is a “
2D GAME”, it is is programmed using c.
Standard Definitions:
Chess Board: A board you need to play Chess. Have 64 black and white
square.
Pawn(P): One of eight men of one color and of the lowest value usually
moved one square at a time vertically and capturing diagonally.
King(K): The main piece of the game, checkmating this piece is the object of
the game. It can move 1 space in any direction.
Knight(H): This piece can move 1 space vertically and 2 spaces horizontally
or 2 spaces vertically and 1 space horizontally. This piece looks like a horse.
This piece can also jump over other pieces.
Rook(R): one of two pieces of the same color that may be moved any
number squares horizontally or vertically, as long as no other piece blocks
its way.
Bishop(C): one of two pieces of the same color that may be moved any
number squares diagonally, as long as no other piece blocks its way.
The text-based game uses upper and lowercase letters for the chess pieces
for players 1 and 2 respectively. The blank pieces are indicated with a '-' and
there is a number grid provided for easier input of the coordinates of
squares. The player is prompted to input the coordinates of the piece to
be moved, and where to move it. We decided that because chess is a
complicated game with many rules, we would not be able to implement all
its functionality. Starting with testing the simpler functions and gradually
working up to playing chess matches, we tested the text-based version for
functionality. Designing and debugging the text-basedversion was
challenging.
#include <stdio.h>
#include <stdlib.h>
#define SIZE 8
// Representation of pieces
char board[SIZE][SIZE] = {
};
void displayBoard() {
printf("\n 1 2 3 4 5 6 7 8\n");
printf(" 1 2 3 4 5 6 7 8\n");
if (isEmpty(fromRow, fromCol)) {
return 0;
board[toRow][toCol] = piece;
return 1;
if (board[i][j] == king) {
return 1;
return 0;
int checkForCheckmate() {
if (!whiteKingExists) {
return 1;
if (!blackKingExists) {
return 1;
return 0;
}
int main() {
while (1) {
displayBoard();
if (checkForCheckmate()) {
break;
if (turn == 1) {
} else {
fromRow = 8 - fromRow;
return 0;
OUTPUT: