A Project Synopsis On Game of Chess: Submitted By: Shiva Chauhan Pankaj Kumar Pal Rahul Kumar Surendra Singh
A Project Synopsis On Game of Chess: Submitted By: Shiva Chauhan Pankaj Kumar Pal Rahul Kumar Surendra Singh
game of chess
Submitted By:
Shiva Chauhan
Rahul Kumar
Surendra Singh
TABLE OF CONTENTS PAGES
DECLARATION II
CERTIFICATE III
ACKNOWELDGEMENTS IV
ABSTRACT V
LIST OF FIGURES VI
LIST OF ABBREVIATIONS VII
CHAPTER 1
Setup of game 5
Moves 6
Special moves 10
Histroy 12
Mathematics and Computers 14
CHAPTER 2
General Specifications 15
Technical Specifications 16
CHAPTER 3
REFERENCES 38
II
DECLARATION
We hereby declare that this project on the “ game of chess “ is our own work and
that to the best part of my knowledge and belief , it contains no material
previously published or written by another person nor material which to a
substantial content have been approved forward of any degree of this or any other
university .
Rahul Kumar
Surendra Singh
Date :07-05-2010
III
CERTIFICATE
This to certify that Project Report entitled “ Game of chess “ which is submitted by Shiva
Chauhan, Pankaj Kumar Pal, Rahul Kumar, Surendra Singh in partial fulfillment of
therequirement for the award of Diploma. in Department of the CSE
of Govt. Polytechnic Kashipur , is a record of the candidate own work carried out by
The matter embodied in this thesis is original and has not been submitted for the
ACKNOWLEDGEMENT
Technology department , who had faith in this project & our technical
I trust with our collective acumen , all programs would run correctly in all
Situations.
We thank our other faculty members for their constant support not only
Carrier.
And finally my heartfelt gratitude to our parents and our friends for
ABSTRACT
This project is on the Game of Chess . Chess a very popular game throughout
the world and this project presents the software for playing the game on the
accordance to the rule of the game . Platform for the development of the project
is JAVA . Since main necessity for the development of this project was a easy to
use and effective GUI , and JAVA provides an excellent GUI through AWT and
Swing . Therefore , JAVA proved to be the perfect platform for the development
of this project .
Regarding the coding for the software , as described earlier all coding is done in
JAVA . There are 15 different modules in the project and all are linked to each
List of Figures
Castling
Special Pawn moves
Snapshots of the project
Data Flow Diagrams
VII
LIST OF ABBREVIATIONS
1
DEVELOPER’S INFORMATION
Duration : 1 Semesters
GAME OF CHESS
Chess is a recreational and competitive game played between two players. The
current form of the game emerged in Southern Europe during the second half of
the 15th century after evolving from similar, much older games of Indian and
Persian origin. Today, chess is one of the world's most popular games, played by
millions of people worldwide at home, in clubs, online, by correspondence, and in
tournaments.
The tradition of organized competitive chess started in the 16th century and has
developed extensively. Chess today is a recognized sport of the International
Olympic Committee. The first official World Chess Champion, Wilhelm Steinitz,
claimed his title in 1886; Viswanathan Anand is the current World Champion.
Theoreticians have developed extensive chess strategies and tactics since the
game's inception. Aspects of art are found in chess composition.
Setup of game
Initial position: first row: rook, knight, bishop, queen, king, bishop, knight, and rook; second
row: pawns
Chess is played on a square board of eight rows (called ranks and denoted with numbers 1 to 8)
and eight columns (called files and denoted with letters a to h) of squares. The colors of the
sixty-four squares alternate and are referred to as "light squares" and "dark squares". The
chessboard is placed with a light square at the right hand end of the rank nearest to each player,
and the pieces are set out as shown in the diagram, with each queen on its own color.
The pieces are divided, by convention, into white and black sets. The players are referred to as
"White" and "Black", and each begins the game with sixteen pieces of the specified color. These
consist of one king, one queen, two rooks, two bishops, two knights and eight pawns.
White always moves first. The players alternate moving one piece at a time (with the exception
of castling, when two pieces are moved simultaneously). Pieces are moved to either an
unoccupied square, or one occupied by an opponent's piece, capturing it and removing it from
6
play. With one exception (en passant), all pieces capture opponent's pieces by moving to the
square that the opponent's piece occupies.
When a king is under immediate attack by one or two of the opponent's pieces, it is said to be in
check. The only permissible responses to a check are to capture the checking piece, interpose a
piece between the checking piece and the king, or move the king to a square where it is not
under attack. Castling is not a permissible response to a check. A move that would place the
moving player's king in check is illegal. The object of the game is to checkmate the opponent;
this occurs when the opponent's king is in check, and there is no way to remove it from attack.
MOVES
Each chess piece has its own style of moving. The Xs mark the squares where the piece can
move if no other pieces (including one's own piece) are on the Xs between the piece's initial
position and its destination. If there is an opponent's piece at the destination square, then the
moving piece can capture the opponent's piece. The only exception is the pawn which can only
capture pieces diagonally forward.
Moves of a king
7
Moves of a rook
Moves of a bishop
8
Moves of a Queen
Moves of a knight
9
Moves of a pawn
Special moves
Castling
10
Once in every game, each king is allowed to make a special move, known as castling. Castling
consists of moving the king two squares towards a rook, then placing the rook immediately on
the far side of the king. Castling is only permissible if all of the following conditions hold:[1]
Neither of the pieces involved in the castling may have been previously moved during the
game;
There must be no pieces between the king and the rook;
The king may not currently be in check, nor may the king pass through squares that are under
attack by enemy pieces. As with any move, castling is illegal if it would place the king in check.
The king and the rook must be on the same rank
En passant
When a pawn advances two squares, if there is an opponent's pawn on an adjacent file next to
its destination square, then the opponent's pawn can capture it and move to the square the pawn
passed over, but only on the next move. For example, if the black pawn has just advanced two
squares from f7 to f5, then the white pawn on e5 can take it via en passant on f6.
10
11
Promotion
When a pawn advances to its eighth rank, it is exchanged for the player's choice of a queen,
rook, bishop, or knight of the same color. Usually, the pawn is chosen to be promoted to a
queen, but in some cases another piece is chosen, called underpromotion. In the diagram on the
right, the pawn on c7 can choose to advance to the eighth rank to promote to a better piece.
Chess games do not have to end in checkmate — either player may resign if the situation looks
hopeless. If it is a timed game a player may run out of time and lose, even with a much superior
position. Games also may end in a draw (tie). A draw can occur in several situations, including
draw by agreement, stalemate, threefold repetition of a position, the fifty-move rule, or a draw
by impossibility of checkmate (usually because of insufficient material to checkmate).
12
History
Predecessors
Chess originated in India during the Gupta empire, where its early form in the 6th century was
known as caturaṅga, which translates as "four divisions [of the military]" – infantry, cavalry,
elephants, and chariotry, represented by the pieces that would evolve into the modern pawn,
knight, bishop, and rook, respectively. Both the Persians and Arabs attribute the game of chess
to the Indians.[17] In Sassanid Persia around 600 the name became shatranj and the rules were
developed further. Shatranj was taken up by the Muslim world after the Islamic conquest of
Persia, with the pieces largely retaining their Persian names. In Spanish "shatranj" was rendered
as ajedrez, in Portuguese as xadrez, and in Greek as zatrikion, but in the rest of Europe it was
replaced by versions of the Persian shāh ("king"), which was familiar as an exclamation and
became our words "check and chess". Murray theorized that this change happened from Muslim
traders coming to European seaports with ornamental chess kings as curios before they brought
the game of chess.
The game reached Western Europe and Russia by at least three routes, the earliest being in the
9th century. By the year 1000 it had spread throughout Europe.Introduced into the Iberian
Peninsula by the Moors in the 10th century, it was described in a famous 13th-century
manuscript covering shatranj, backgammon, and dice named the Libro de los juegos
Birth of Sport
The first modern chess tournament was held in London in 1851 and won, surprisingly, by
German Adolf Anderssen, relatively unknown at the time. Anderssen was hailed as the leading
chess master and his brilliant, energetic attacking style became typical for the time, although it
was later regarded as strategically shallow.Sparkling games like Anderssen's Immortal game or
Morphy's Opera game were regarded as the highest possible summit of the chess art.
Deeper insight into the nature of chess came with two younger players. American Paul Morphy,
an extraordinary chess prodigy, won against all important competitors, including Anderssen,
13
during his short chess career between 1857 and 1863. Morphy's success stemmed from a
combination of brilliant attacks and sound strategy; he intuitively knew how to prepare attacks.
[32]
Prague-born Wilhelm Steinitz later described how to avoid weaknesses in one's own position
and how to create and exploit such weaknesses in the opponent's position. In addition to his
theoretical achievements, Steinitz founded an important tradition: his triumph over the leading
German master Johannes Zukertort in 1886 is regarded as the first official World Chess
Championship. Steinitz lost his crown in 1894 to a much younger German mathematician
Emanuel Lasker, who maintained this title for 27 years, the longest tenure of all World
Champions.
It took a prodigy from Cuba, José Raúl Capablanca (World champion 1921–27), who loved
simple positions and endgames, to end the German-speaking dominance in chess; he was
undefeated in tournament play for eight years until 1924. His successor was Russian-French
Alexander Alekhine, a strong attacking player, who died as the World champion in 1946,
having briefly lost the title to Dutch player Max Euwe in 1935 and regaining it two years later.
Between the world wars, chess was revolutionized by the new theoretical school of so-called
hypermodernists like Aron Nimzowitsch and Richard Réti. They advocated controlling the
center of the board with distant pieces rather than with pawns, inviting opponents to occupy the
center with pawns which become objects of attack.[36]
After the end of the 19th century, the number of annually held master tournaments and matches
quickly grew. Some sources state that in 1914 the title of chess grandmaster was first formally
conferred by Tsar Nicholas II of Russia to Lasker, Capablanca, Alekhine, Tarrasch and
Marshall, but this is a disputed claim.[37] The tradition of awarding such titles was continued by
the World Chess Federation (FIDE), founded in 1924 in Paris. In 1927, Women's World Chess
Championship was established; the first to hold it was Czech-English master Vera Menchik.[38]
14
The number of legal positions in chess is estimated to be between 1043 and 1050, with a game-
tree complexity of approximately 10123. The game-tree complexity of chess was first calculated
by Claude Shannon as 10120, a number known as the Shannon number. Typically an average
position has thirty to forty possible moves, but there may be as few as zero (in the case of
checkmate or stalemate) or as many as 218.
The most important mathematical challenge of chess is the development of algorithms which
can play chess. The idea of creating a chess playing machine dates to the 18th century; around
1769, the chess playing automaton called The Turk became famous before being exposed as a
hoax. Serious trials based on automatons, such as El Ajedrecista, were too complex and limited
to be useful.
Since the advent of the digital computer in the 1950s, chess enthusiasts and computer engineers
have built, with increasing degrees of seriousness and success, chess-playing machines and
computer programs. The groundbreaking paper on computer chess, "Programming a Computer
for Playing Chess", was published in 1950 by Shannon.He wrote:
15
About the project
General Specifications
The game of chess can be played between 2 players.
The game can be played on any operating system.
There is no provision for single player game in the game.
There appears error message for every illegal / wrong step.
There is no provision for a undo to create a more realistic experience.
A congrates message is displayed when a player win.
16
Technical Specifications
Project is Platform Independent.
Project is build up using JDK 1.5.1.
GUI components of the project are provide by AWT , Swings.
To run the project there must be JDK installed .
Steps for running the project :-
I. Open command interpreter
II. Specify the path for the “Chess”
folder
III. Type javac chess.java
IV. Type java chess
17
Abstract Window Toolkit
The Abstract Window Toolkit (AWT) is Java's original platform-independent windowing,
graphics, and user-interface widget toolkit. The AWT is now part of the Java Foundation
Classes (JFC) — the standard API for providing a graphical user interface (GUI) for a Java
program.
AWT is also the GUI toolkit for a number of Java ME profiles. For example, Connected Device
Configuration profiles require Java runtimes on mobile telephones to support AWT.
Architecture
A general interface between Java and the native system, used for windowing, events, layout
managers. This API is at the core of Java GUI programming and is also used by Swing and Java
2D. It contains:
o The interface between the native windowing system and the Java application;
o The core of the GUI event subsystem;
o Several layout managers;
18
o The interface to input devices such as mouse and keyboard; and
o A java.awt.datatransfer package for use with the Clipboard and Drag and Drop.
A basic set of GUI widgets such as buttons, text boxes, and menus. It also provides the AWT
Native Interface, which enables rendering libraries compiled to native code to draw directly to
an AWT Canvas object drawing surface.
AWT also provide some miscellaneous useful utilities, that can also be used by Swing, such as:
Neither AWT nor Swing are inherently thread safe. Therefore, code that updates the GUI or
processes events should execute on the Event dispatching thread. Failure to do so may result in
a deadlock or race condition. To address this problem, a utility class called SwingWorker allows
applications to perform time-consuming tasks following user-interaction events in the event
dispatching thread.
Prior to Java 6 Update 12, mixing Swing components and AWT basic widgets has often resulted
in undesired side effects, with AWT widgets going on top of the Swing widgets regardless of
their defined priorities. This problem was due to the fact that the rendering architecture of the
two widgets toolkit was very different, despite Swing borrowing heavyweight top containers
from AWT.
Since Java 6 Update 12, it is now possible to mix Swing and AWT widgets without having
priorities problems
Window Fundamentals
The AWT defines windows according to a class hierarchy that adds functionality and
specificity with each level. The two most common windows are those derived from
Panel, which is used by applets, and those derived from Frame, which creates a
standard window. Much of the functionality of these windows is derived from their
parent classes. Thus, a description of the class hierarchies relating to these two classes
19
is fundamental to their understanding.
Component
At the top of the AWT hierarchy is the Component class. Component is an abstract
class that encapsulates all of the attributes of a visual component. All user interface
elements that are displayed on the screen and that interact with the user are subclasses
of Component. It defines over a hundred public methods that are responsible for
managing events, such as mouse and keyboard input, positioning and sizing the
window, and repainting. A Component object is responsible for remembering
the current foreground and background colors and the currently selected text font.
Container
The Container class is a subclass of Component. It has additional methods that allow
other Component objects to be nested within it. Other Container objects can be stored
inside of a Container (since they are themselves instances of Component). This makes
for a multileveled containment system.
Panel
The Panel class is a concrete subclass of Container. It doesn’t add any new methods; it
simply implements Container. A Panel may be thought of as a recursively nestable,
concrete screen component. Panel is the superclass for Applet. When screen output is
directed to an applet, it is on the surface of a Panel object. In essence, a Panel is
a window that does not contain a title bar, menu bar, or border. This is why you don’t
see these items when an applet is run inside a browser. When you run an applet using
an applet viewer, the applet viewer provides the title and border.
Other components can be added to a Panel object by its add( ) method (inherited
from Container). Once these components have been added, you can position and resize
them manually using the setLocation( ), setSize( ), or setBounds( ) methods defined by component.
Window
The Window class creates a top-level window. A top-level window is not contained
within any other object; it sits directly on the desktop.
Frame
Frame encapsulates what is commonly thought of as a “window.” It is a subclass of
Window and has a title bar, menu bar, borders, and resizing corners. If you create a
Frame object from within an applet, it will contain a warning message, such as “Java
Applet Window,” to the user that an applet window has been created. This message
warns users that the window they see was started by an applet and not by software
running on their computer. (An applet that could masquerade as a host-based
application could be used to obtain passwords and other sensitive information without
the user’s knowledge.) When a Frame window is created by a program rather than an
applet, a normal window is created.
20
Swing
Swing is a widget toolkit for Java. It is part of Sun Microsystems' Java Foundation Classes
(JFC) — an API for providing a graphical user interface (GUI) for Java programs,
Swing was developed to provide a more sophisticated set of GUI components than the earlier
Abstract Window Toolkit. Swing provides a native look and feel that emulates the look and feel
of several platforms, and also supports a pluggable look and feel that allows applications to
have a look and feel unrelated to the underlying .
Architecture
Foundations
Platform independence
Swing is platform independent both in terms of its expression (Java) and its implementation
(non-native universal rendering of widgets).
Extensibility
Swing is a highly partitioned architecture, which allows for the "plugging" of various custom
implementations of specified framework interfaces: Users can provide their own custom
implementation(s) of these components to override the default implementations. In general,
Swing users can extend the framework by extending existing (framework) classes and/or
providing alternative implementations of core components.
Component Oriented
21
Customizable
Given the programmatic rendering model of the Swing framework, fine control over the details
of rendering of a component is possible in Swing. As a general pattern, the visual representation
of a Swing component is a composition of a standard set of elements, such as a "border",
"inset", decorations, etc. Typically, users will programmatically customize a standard Swing
component (such as a JTable) by assigning specific Borders, Colors, Backgrounds, opacities,
etc., as the properties of that component. The core component will then use these property
(settings) to determine the appropriate renderers to use in painting its various aspects. However,
it is also completely possible to create unique GUI controls with highly customized visual
representation.
Configurable
Swing's heavy reliance on runtime mechanisms and indirect composition patterns allows it to
respond at runtime to fundamental changes in its settings. For example, a Swing-based
application can change its look and feel at runtime. Further, users can provide their own look
and feel implementation, which allows for uniform changes in the look and feel of existing
Swing applications without any programmatic change to the application code.
The JComponent class extends the Container class, which itself extends Component. The
Component class includes everything from providing layout hints to supporting painting and
events. The Container class has support for adding components to the container and laying
them out. This section's API tables summarize the most often used methods of Component and
Container, as well as of JComponent.
22
JComponent Features
Tool tips
Painting and borders
Application-wide pluggable look and feel
Custom properties
Support for layout
Support for accessibility
Support for drag and drop
Double buffering
Key bindings
The JComponent class provides many new methods and inherits many methods from
Component and Container. The following tables summarize the methods we use the most.
Method Purpose
void setBorder(Border) Set or get the border of the component. See How to Use Borders for
Border getBorder() details.
void Set the foreground or background color for the component. The
setForeground(Color) foreground is generally the color used to draw the text in a component.
void The background is (not surprisingly) the color of the background areas
setBackground(Color) of the component, assuming that the component is opaque.
Color getForeground() Get the foreground or background color for the component.
Color getBackground()
void Set or get whether the component is opaque. An opaque component fills
setOpaque(boolean) its background with its background color.
boolean isOpaque()
void setFont(Font) Set or get the component's font. If a font has not been set for the
Font getFont() component, the font of its parent is returned.
void setCursor(Cursor) Set or get the cursor displayed over the component and all components
Cursor getCursor() it contains (except for children that have their own cursor set).
24
Method Purpose
25
Handling Events
Method Purpose
Method Purpose
void repaint() Request that all or part of the component be repainted. The four
void repaint(int, int, int, int) int arguments specify the bounds (x, y, width, height, in that
order) of the rectangle to be painted.
void repaint(Rectangle) Request that the specified area within the component be repainted.
void revalidate() Request that the component and its affected containers be laid out
again. You should not generally need to invoke this method unless
you explicitly change a component's size/alignment hints after it's
visible or change a containment hierarchy after it is visible.
void Paint the component. Override this method to implement painting
paintComponent(Graphics) for custom components.
27
Dealing with the Containment Hierarchy
Method Purpose
Component add(Component) Add the specified component to this
Component add(Component, int) container. The one-argument version
void add(Component, Object) of this method adds the component to
the end of the container.
28
29
Getting Size and Position Information
Method
Purpose
int getWidth() Get the current width or height of the component measured in pixels.
int getHeight()
Get the current x or y coordinate of the component's origin relative to
int getX() the parent's upper left corner measured in pixels.
int getY()
Rectangle getBounds() Get the bounds of the component measured in pixels. The bounds
Rectangle specify the component's width, height, and origin relative to its parent.
getBounds(Rectangle) When using the one-argument version of this method, the caller is
responsible for creating the Rectangle instance in which the result is
returned.
Point getLocation() Gets the current location of the component relative to the parent's
Point getLocation(Point) upper left corner measured in pixels. When using the one-argument
version of getLocation method, the caller is responsible for creating
the Point instance in which the result is returned.
Point Returns the position relative to the upper left corner of the screen.
getLocationOnScreen()
Insets getInsets() Get the size of the component's border.
30
Relationship to AWT
Since early versions of Java, a portion of the Abstract Window Toolkit (AWT) has provided
platform-independent APIs for user interface components. In AWT, each component is
rendered and controlled by a native peer component specific to the underlying windowing
system.
By contrast, Swing components are often described as lightweight because they do not require
allocation of native resources in the operating system's windowing toolkit. The AWT
components are referred to as heavyweight components.
Much of the Swing API is generally a complementary extension of the AWT rather than a direct
replacement. In fact, every Swing lightweight interface ultimately exists within an AWT
heavyweight component because all of the top-level components in Swing (JApplet, JDialog,
JFrame, and JWindow) extend an AWT top-level container.
Hardware Requirements
Pentium Processor II or higher with min. 800 Mhz.
Software Requirement
The system has been developed using JAVA which is platform independent. This
allows the system to be independent of the platform being used to run the system.
Hence, whether a windows operating system is used or a Mac, or Linux operating
system is used the same performance of the system can ba availed of by the user.
Fundamentals of Java
Java developed by Sun
Sun describes Java as:
– Simple, Object-oriented, Distributed, Interpreted, Robust, Secure,
Architecture neutral, Portable, High-performance, Multithreaded, and
Dynamic Language
Kathy Sierra & Bert Bates , “ Head First JAVA 2ND Edition ”
ka