You are on page 1of 30

Acknowledgement

We would like to acknowledge the contributions of various individuals and resources to the
development of our chess game application for Android:

We extend our appreciation to our dedicated development team for their hard work in creating
a user-friendly and engaging chess game experience. Their expertise and commitment have
been instrumental in bringing this project to fruition.

We are grateful for the support and resources provided by Android Studio and the Android
Developer community, which have enabled us to build and optimize the application for a
seamless user experience on Android devices.

Our gratitude also goes to open source chess engines like Stockfish and Crafty, whose powerful
algorithms and functionalities have enhanced the game's AI capabilities, providing challenging
gameplay for our users.

We would like to thank the online chess communities and forums for their valuable feedback
and suggestions during the testing phase, helping us identify areas for improvement and refine
the application.

Last but not least, we appreciate our users' enthusiasm and feedback, which have been
essential in shaping the direction of the application and driving continuous improvement
through regular updates.
ABSTRACTWe proposed to build an online chess game for single-player as well as multiplayer
in nodejs and deploy it on Heroku. An online chess game is developed incompliance with
Human-Machine Interaction principles. The web app has a simpleand attractive design. The
theme of the game can also be customised by the player.The chessboard's background may be
changed to suit the user's preferences. Userscan play against other players in multiplayer
mode, which features a chatbox forreal-time conversation between players. Aside from that,
chosen blocks will behighlighted for easier sight, and a sound will be heard after each move to
confirmthe move. While playing, the user learns about the potential movement of thepieces.
The browser will notify you if an opponent leaves the game in the middle of a round in multiple
player mode.
Introduction

1.1 Brief description of the project

The project “Online Chess Game” implements a classic version of Chess with a 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. It is played on an 8x8 checkerboard, with a dark
square in each player's lower-left corner. The website was developed using Nodejs and
deployed on Heroku. This is an online chess game that users from remote locations can play
and discuss on the website through the chat window. The user can play in single mode and
multiplayer mode as well. There is also an option to change the layout of thechessboard as the
player would like. While playing, the player gets to know abouthis current position and the
other position in which he can move his pieces.

1.2 What is a chess game?Chess is a game for 2 players each of whom moves 16 pieces
according to fixed rules across a checkerboard and tries to checkmate the opponent's king. Our
project implements the chess game with a graphical user interface. The chess game follows the
basic rules of chess and all the chess pieces only move according to valid moves for that piece.

1.3 What Are The Chess Pieces?The chess pieces are what you move on a chessboard when
playing a game of chess. There are six different types of chess pieces. Each side starts with 16
pieces: eight pawns, two bishops, two knights, two rooks, one queen, and one king.

The PawnWhen a game begins, each side starts with eight pawns. White's pawns are located in
the second rank, while Black's pawns are located in the seventh rank. The pawn is the least
powerful piece and is worth one point. If it is a pawn's first move, it can move forward one or
two squares. If a pawn has already moved, then it can move forward just one square at a time.
It attacks (or captures) each squarediagonally to the left or right. In the following diagram, the
pawn has just moved from the e2-square to the e4-square and attacks the squares d5 and f5.
The BishopEach side starts with two bishops, one on a light square and one on a dark square.
When a game begins, White's bishops are located on c1 and f1, while Black's bishops are
located on c8 and f8. The bishop is considered a minor piece (like a knight) and is worth three
points. A bishop can move diagonally as many squares as it likes, as long as it is not blocked by
its own pieces or an occupied square. An easy way to remember how a bishop can move is that
it moves like an "X" shape. It can capture an enemy piece by moving to the occupied square
wherethe piece is located.

The KnightEach side starts with two knights—a king's knight and a queen's knight. When a
game starts, White's knights are located on b1 and g1, while Black's knights are located on b8
and g8. The knight is considered a minor piece (like bishop) and is worth three points. The
knight is the only piece in chess that can jump over another piece! It moves one square left or
right horizontally and then two squares up or down vertically, OR it moves two squares left or
right horizontally and then one square up or down vertically—in other words, the knight moves
in an "L-shape." The knight can capture only what it lands on, not what it jumps over!The
RookEach side starts with two rooks, one on the queenside and one on the kingside. All four
rooks are located in the corners of the board. White's rooks start the game on a1 and h1, while
Black's rooks are located on a8 and h8. The rook is considered a major piece (like the queen)
and is worth five points. It can move as many squares as it likes left or right horizontally, or as
many squares as it likes up or down vertically (as long as it isn't blocked by other pieces).

The QueenThe queen is the most powerful chess piece! When a game begins, each side starts
with one queen. The white queen is located on d1, while the black queen is located on d8. The
queen is considered a major piece (like a rook) and is worth nine points. It can move as many
squares as it likes left or right horizontally, or as many squares as it likes up or down vertically
(like a rook). The queen can also move as many squares as it likes diagonally (like a bishop).

The KingThe king is the most important chess piece. The goal of a game of chess is to
checkmate the king. When a game starts, each side has one king. White's king is located on e1,
while Black's king starts on e8. The king is not a very powerful piece, as it can only move (or
capture) one square in any direction. When a king is attacked, it is called a "check."
PROBLEM STATEMENT
Chess is a game where the battle of minds takes place between two people. It is a game of
strategy where two people play with each other’s minds. It’s a board game that requires
patience, concentration, intuition, perseverance, etc. Chess is a mind game that involves a lot of
thinking and time. It requires prediction and problem-solving skills. We are living in a world that
is connected despite being in different locations. So we have the ability to play and challenge
other people with games. The project focuses on a chess game that anyone can play online with
someone or by themselves. The main goal is to allow the gamer to have a good experience of
the play but also connect with the opponent player and learn and discuss chess moves.

OBJECTIVE
Firstly, the goal is to create an engaging and user-friendly platform that allows players to enjoy
the timeless game of chess conveniently on their Android devices. This involves developing a
visually appealing and intuitive interface that enhances the overall gaming experience.

The application aims to cater to a diverse audience, including chess enthusiasts looking for
challenging gameplay against AI opponents at varying difficulty levels. It also provides an
opportunity for beginners to learn and improve their chess skills through tutorials, puzzles, and
interactive features that explain strategies and rules.

Moreover, the chess game application in Android Studio is designed to promote social
interaction by enabling multiplayer functionality, allowing users to play against friends or other
players online. This fosters a sense of community and competition among players, enhancing
the overall gaming experience.

In terms of technical objectives, the application strives for bug-free performance and smooth
functionality across different Android devices, screen sizes, and orientations. Regular updates
and improvements are implemented to address any issues, enhance AI algorithms, introduce
new features, and optimize the user experience based on user feedback.
CODE IMPLEMENTATION:-
Mainactivity.java

package jwtc.android.chess;

import jwtc.android.chess.activities.StartBaseActivity;

import jwtc.chess.JNI;

import android.content.ActivityNotFoundException;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import androidx.core.view.MenuItemCompat;

import android.util.Log;

import android.view.Menu;

import android.view.MenuItem;

import android.view.View;

import android.widget.Button;

import java.io.IOException;

import java.util.Timer;

import java.util.TimerTask;

import androidx.mediarouter.app.MediaRouteActionProvider;

import androidx.mediarouter.media.MediaRouteSelector;

import androidx.mediarouter.media.MediaRouter;

import androidx.mediarouter.media.MediaRouter.RouteInfo;

import com.google.android.gms.cast.ApplicationMetadata;

import com.google.android.gms.cast.Cast;
import com.google.android.gms.cast.CastDevice;

import com.google.android.gms.cast.CastMediaControlIntent;

import com.google.android.gms.common.ConnectionResult;

import com.google.android.gms.common.api.GoogleApiClient;

import com.google.android.gms.common.api.ResultCallback;

import com.google.android.gms.common.api.Status;

public class start extends StartBaseActivity {

public static final String TAG = "start";

private MediaRouter mMediaRouter;

private MediaRouteSelector mMediaRouteSelector;

private MediaRouter.Callback mMediaRouterCallback;

private CastDevice mSelectedDevice;

private GoogleApiClient mApiClient;

private Cast.Listener mCastListener;

private ConnectionCallbacks mConnectionCallbacks;

private ConnectionFailedListener mConnectionFailedListener;

private ChessChannel mChessChannel;

private boolean mApplicationStarted;

private boolean mWaitingForReconnect;

private String mSessionId;

private JNI _jni;

private Timer _timer;

private String _lastMessage;

/** * Called when the activity is first created.


*/

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

_jni = JNI.getInstance();

_lastMessage = "";

_timer = new Timer(true);

_timer.schedule(new TimerTask() {

@Override

public void run() {

sendMessage(_jni.toFEN());

}, 1000, 500);

// Configure Cast device discovery

mMediaRouter = MediaRouter.getInstance(getApplicationContext());

mMediaRouteSelector = new MediaRouteSelector.Builder()

.addControlCategory(CastMediaControlIntent.categoryForCast("05EB93 C6")).build();

mMediaRouterCallback = new MyMediaRouterCallback();

final String packageName = "jwtc.android.chess";

Button buttonShare = findViewById(R.id.ButtonShare);

if (buttonShare != null) {

buttonShare.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {


Intent i = new Intent(Intent.ACTION_SEND);

i.setType("text/plain");

i.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name));

i.putExtra(Intent.EXTRA_TEXT, "https://play.google.com/store/apps/details?id=" +
packageName);

startActivity(Intent.createChooser(i, "Share"));

});

@Override

protected void onStart() {

super.onStart();

// Start media router discovery

mMediaRouter.addCallback(mMediaRouteSelector, mMediaRouterCallback,

MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY);

@Override

protected void onStop() {

// End media router discovery

mMediaRouter.removeCallback(mMediaRouterCallback);

super.onStop();

@Override
public void onDestroy() {

Log.d(TAG, "onDestroy");

teardown(true);

super.onDestroy();

@Override

public boolean onCreateOptionsMenu(Menu menu) {

super.onCreateOptionsMenu(menu);

getMenuInflater().inflate(R.menu.start_topmenu, menu);

MenuItem mediaRouteMenuItem = menu.findItem(R.id.media_route_menu_item);

MediaRouteActionProvider mediaRouteActionProvider

= (MediaRouteActionProvider) MenuItemCompat

.getActionProvider(mediaRouteMenuItem);

// Set the MediaRouteActionProvider selector for device discovery.

mediaRouteActionProvider.setRouteSelector(mMediaRouteSelector);

return true;

/**

* Send a text message to the receiver

*/

private void sendMessage(final String message) {

if (mApiClient != null && mChessChannel != null && message != null) {

try {

if (!_lastMessage.equals(message)) {
//Log.i(TAG, "Try to send " + message);

Cast.CastApi.sendMessage(mApiClient,

mChessChannel.getNamespace(), message).setResultCallback(

new ResultCallback<Status>() {

@Override

public void onResult(Status result) {

if (result.isSuccess()) {

_lastMessage = message;

} else {

Log.e(TAG, "Sending message failed");

});

} catch (Exception e) {

Log.e(TAG, "Exception while sending message", e);

/**

* Callback for MediaRouter events

*/

private class MyMediaRouterCallback extends MediaRouter.Callback {

@Override
public void onRouteSelected(MediaRouter router, RouteInfo info) {

Log.d(TAG, "onRouteSelected");

// Handle the user route selection.

mSelectedDevice = CastDevice.getFromBundle(info.getExtras());

launchReceiver();

@Override

public void onRouteUnselected(MediaRouter router, RouteInfo info) {

Log.d(TAG, "onRouteUnselected: info=" + info);

teardown(false);

mSelectedDevice = null;

/**

* Google Play services callbacks

*/

private class ConnectionCallbacks implements

GoogleApiClient.ConnectionCallbacks {

@Override

public void onConnected(Bundle connectionHint) {

Log.d(TAG, "onConnected");

if (mApiClient == null) {

// We got disconnected while this runnable was pending


// execution.

return;

try {

if (mWaitingForReconnect) {

mWaitingForReconnect = false;

// Check if the receiver app is still running

if ((connectionHint != null)

&& connectionHint.getBoolean(Cast.EXTRA_APP_NO_LONGER_RUNNING)) {

Log.d(TAG, "App is no longer running");

teardown(true);

} else {

// Re-create the custom message channel

try {

Cast.CastApi.setMessageReceivedCallbacks(

mApiClient,

mChessChannel.getNamespace(),

mChessChannel);

} catch (IOException e) {

Log.e(TAG, "Exception while creating channel", e);

} else {
// Launch the receiver app

Cast.CastApi.launchApplication(mApiClient, "05EB93C6", false)

.setResultCallback(

new ResultCallback<Cast.ApplicationConnectionResult>() {

@Override

public void onResult(

Cast.ApplicationConnectionResult result) {

Status status = result.getStatus();

Log.d(TAG,

"ApplicationConnectionResultCallback.onResult:"

+ status.getStatusCode());

if (status.isSuccess()) {

ApplicationMetadata applicationMetadata = result

.getApplicationMetadata();

mSessionId = result.getSessionId();

String applicationStatus = result

.getApplicationStatus();

boolean wasLaunched = result.getWasLaunched();

Log.d(TAG, "application name: "

+ applicationMetadata.getName()

+ ", status: " + applicationStatus

+ ", sessionId: " + mSessionId

+ ", wasLaunched: " + wasLaunched);

mApplicationStarted = true;
// Create the custom message

// channel

mChessChannel = new ChessChannel();

try {

Cast.CastApi.setMessageReceivedCallbacks(

mApiClient,

mChessChannel.getNamespace(),

mChessChannel);

} catch (IOException e) {

Log.e(TAG, "Exception while creating channel",

e);

} else {

Log.e(TAG, "application could not launch");

teardown(true);

});

} catch (Exception e) {

Log.e(TAG, "Failed to launch application", e);

@Override
public void onConnectionSuspended(int cause) {

Log.d(TAG, "onConnectionSuspended");

mWaitingForReconnect = true;

/**

* Google Play services callbacks

*/

private class ConnectionFailedListener implements

GoogleApiClient.OnConnectionFailedListener {

@Override

public void onConnectionFailed(ConnectionResult result) {

Log.e(TAG, "onConnectionFailed ");

teardown(false);

/**

* Start the receiver app

*/

private void launchReceiver() {

try {

mCastListener = new Cast.Listener() {

@Override

public void onApplicationDisconnected(int errorCode) {


Log.d(TAG, "application has stopped");

teardown(true);

};

// Connect to Google Play services

mConnectionCallbacks = new ConnectionCallbacks();

mConnectionFailedListener = new ConnectionFailedListener();

Cast.CastOptions.Builder apiOptionsBuilder = Cast.CastOptions

.builder(mSelectedDevice, mCastListener);

mApiClient = new GoogleApiClient.Builder(this)

.addApi(Cast.API, apiOptionsBuilder.build())

.addConnectionCallbacks(mConnectionCallbacks)

.addOnConnectionFailedListener(mConnectionFailedListener)

.build();

mApiClient.connect();

} catch (Exception e) {

Log.e(TAG, "Failed launchReceiver", e);

/**

* Custom message channel

*/

class ChessChannel implements Cast.MessageReceivedCallback {

/**
* @return custom namespace

*/

public String getNamespace() {

return "urn:x-cast:nl.jwtc.chess.channel";

/*

* Receive message from the receiver app

*/

@Override

public void onMessageReceived(CastDevice castDevice, String namespace,

String message) {

//Log.d(TAG, "onMessageReceived: " + message);

/**

* Tear down the connection to the receiver

*/

private void teardown(boolean selectDefaultRoute) {

Log.d(TAG, "teardown");

if (mApiClient != null) {

if (mApplicationStarted) {

if (mApiClient.isConnected() || mApiClient.isConnecting()) {

try {

Cast.CastApi.stopApplication(mApiClient, mSessionId);
if (mChessChannel != null) {

Cast.CastApi.removeMessageReceivedCallbacks(

mApiClient,

mChessChannel.getNamespace());

mChessChannel = null;

} catch (IOException e) {

Log.e(TAG, "Exception while removing channel", e);

mApiClient.disconnect();

mApplicationStarted = false;

mApiClient = null;

if (selectDefaultRoute) {

mMediaRouter.selectRoute(mMediaRouter.getDefaultRoute());

mSelectedDevice = null;

mWaitingForReconnect = false; mSessionId = null; }}

OUTPUT
ADVENTAGES

1. **Wide User Base:** Android is a widely used mobile operating system, providing access to a
large user base globally. Developing a chess game for Android allows you to reach a broad
audience of potential players.

2. **Market Opportunity:** Chess is a popular and timeless game with a dedicated following.
Creating a chess game application for Android presents a market opportunity to attract players
who enjoy strategic and intellectual gameplay.

3. **Flexibility and Customization:** Android Studio offers flexibility in designing and


customizing the user interface, gameplay mechanics, and features of the chess game
application according to your vision and target audience preferences.

4. **Integration with Android Ecosystem:** The chess game application can leverage various
Android features such as notifications, sharing functionalities, cloud storage, and multiplayer
capabilities, enhancing the overall user experience and engagement.

5. **Monetization Options:** Android provides multiple monetization options for your chess
game application, including in-app purchases, ads, premium features, subscriptions, or a
combination of these strategies to generate revenue.

6. **Community and Support:** Android development benefits from a large and active
community of developers, forums, and resources. This community support can be valuable for
troubleshooting, sharing knowledge, and staying updated with the latest trends and
technologies.
7. **Cross-Platform Compatibility:** Depending on your development approach, you may have
the option to make your chess game application compatible with other platforms such as iOS or
web, further expanding your reach and potential user base.

8. **Continuous Improvement:** Android Studio provides tools for performance monitoring,


analytics, and user feedback integration, allowing you to gather insights and continuously
improve the chess game application based on user preferences and behavior.

9. **Scalability:** As your chess game gains popularity and success, Android Studio offers
scalability options to handle increased user traffic, implement new features, and support
ongoing maintenance and updates effectively.

DISADVANTAGES

1. Device Fragmentation: Ensuring consistent performance across various Android devices can
be challenging due to hardware and software differences.

2. Market Competition: The Google Play Store is saturated with chess game applications,
making it harder to stand out and attract users.

3. Monetization Complexity: Effectively monetizing the app through ads or in-app purchases
requires a well-thought-out strategy.
4. Security Risks: Android's open nature can lead to potential security vulnerabilities if not
handled properly.

CONCLUSION
Through the proposed system, we can draw the conclusion that the online chess game is
designed by keeping in mind the Human-Machine Interaction principles. The web application is
simple and allows the user to play chess. Two modes are available: the first one is single-player
and the second one is multiplayer. In the case of multiplayer, the user can communicate with
the opponent through a chat window. The design of the website is classic and elegant with
fewer colours and objects on it and the goal is very clear to the user: playing chess. The user has
the choice to change the theme of the game as well. While playing, the user gets to know about
the possible movement of the pieces. For multiple player mode, if the opponent leaves the
game in the middle, the browser notifies that the opponent has left the game. The user is well
informed of everything that is happening and cantake decisions without thinking too much.The
web application developed using Nodejs was deployed on the Herokuplatform and can be
accessed by everyone. Furthermore, for future work, we can add more features and also make
a tutorial portal for new beginners with tips on how to play.

Reference
1. https://www.chess.com/terms/chess-pieces

2. https://nodejs.org/en/docs

3. https://devcenter.heroku.com/categories/reference

4. https://devcenter.heroku.com/articles/getting-started-with-nodejs

You might also like