0% found this document useful (0 votes)
28 views86 pages

REPORT

report

Uploaded by

raman1610kaushik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views86 pages

REPORT

report

Uploaded by

raman1610kaushik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 86

ACKNOWLEDGEMENT

I would like to express my profound gratitude to, of Institute of Technology


Management, Murthal (Sonipat) for their contributions to the completion of my
project titled CHESS GAME. I would also like to thanks our Councler, HOD and all
the staff member of the College. There useful advice and suggestions were really
helpful to us during the project’s completion. In this aspect, I am eternally grateful
to them.

I would like to express my special thanks to our Guide/Mentor Ms. Jyoti


Antil ,Asst. Professor for his time and efforts he provided throughout the
semester. His useful advice and suggestions were really helpful to us during the
project’s completion. I would like to acknowledge that this project was completed
entirely by me and not by someone else.

Signature

Name

University Roll No.

1
DECLARATION

I hear by declare that the project report entitled CHESS GAME.submitted by me


to Institute of Technology and Management, Murthal(Sonipat) in the partial
fulfilment and of BCA degree prescribed by the college.
I also declared that this project is the outcome of my own effort, that it has not
been submitted to any other university for the award of any degree.

Signature

Name

University Roll No.

2
Certificate

This is to certify that student name Ramandeep roll no. 22015041112 developed
the project CHESS GAME. under my guidance and supervision.

Signature of Project Guide


Asst. Professor

3
TABLE OF CONTENTS
S.NO. TITLE PAGE NO.
ABSTRACT v

LIST OF FIGURES viii


1. CHAPTER 1: INTRODUCTION

1.1 INTRODUCTION 1

1.2 RESEARCH AND SIGNIFICANCE 1


2. CHAPTER 2: LITERATURE SURVEY 2

3. CHAPTER 3: AIM AND SCOPE


3.1 AIM 3

3.2 SCOPE 3
4. CHAPTER 4: SYSTEM DESIGN AND METHODOLOGY

4.1 PROPOSED SYSTEM 4

4.2 REQUIREMENT SPECIFICATION 4

4.2.1 SOFTWARE REQUIREMENTS 4

4.2.2 HARDWARE REQUIREMENTS 5

4.3 EXISTING SYSTEM 5

5. CHAPTER 5: SYSTEM DEVELOPMENT METHOLOGY


5.1 SYSTEM ARCHITECTURE 6

6. CHAPTER 6: RESULTS AND DISCUSSIONS


6.1 MODULE DESCRIPTION 8
6.1.1 Game Intro Module 8
9
6.1.2 User Input module
6.1.3 Step Validation module 10
6.1.4 Game Updation module 14

6.1.5 Winner declaration module 14


7. 15
CHAPTER 7: CONCLUSION
16
REFERENCES
APPENDIX
1. ACCPAPEREPTANCE MAIL 17

2. PLAGARISM REPORT 18

3. SOURCE CODE 19
4. PAPER ACCEPTANCE 31

4
LIST OF FIGURES

FIGUR FIGURE NAME PAGE No.


E
No.
5.1 CHESS ARCHITECTURE 6
6.1 GAME BOARD 8
6.2 GAME INTRO MODULE 9
6.3 USER INPUT MODULE 9
6.4.1 SIGNAL 0 10
6.4.2 SIGNAL 1 11
6.4.3 SIGNAL 11 12
6.4.4 SIGNAL 22 13
6.4.6 WINNER DECLARATION MODULE 14

5
CHAPTER 1 INTRODUCTION
1.1 INTRODUCTION

Overview: Based upon the game chess. Here the requirements


are quiet simple, just a HTML,CSS & JAVASCRIPT compiler is
enough to program this CHESS game. This game contains as
generally a chess game has, all pieces are named in the format
of (Piece name.colour). The „random‟ package is used in this
game, which is used to randomized our chances or player turns
to play. We have to enter the inputs to play the game are 1.
piece name 2. initial a, 1values 3. destination a,1 values.

So the key of the game is purely based upon the co-


ordinates of a 1. And firstly this game is k-sensitive. And a
single mistake of entering piece name will not let us to do it
again. And the output is presented by printable named function
which also represents the chess board along with the value
update. And the rules of each piece is the only time taking and
also hardest part the game, cause for example piece „rook‟
‟have to move only either the up-side, down-side, right-side or
left-side, so in the co-ordinates of a and 1either a value should
vary or 1value should vary. And here the problem is if in
between the initial and destination point if any same side of the
player‟s piece contain then castle should stop in possible front
of the piece. So that every step is must and should counted to
check whether any piece contains or not. And the further
information is detailed in the introduction part of the game.

6
1.2 RESEARCH AND SIGNIFICANCE

The main aim of this application I.e. to create a own and


customizable chess engine, which is easy to understand and
code. And also to provide a user friendly interface for the user
while playing.

CHAPTER 2 LITERATURE SURVEY

Literature survey is that the most significant step in code


development method. Before developing the tool it's necessary
to see the time issue, economy and company strength. Once
these items are happy, then consecutive step is to see that OS
and language may be used for developing the tool.

Once the programmers begin building the tool the


programmers need ton of external support. This support are
obtained from senior programmers, from book or from
websites.
Before building the system the on prime of thought unit
taken into thought for developing the planned system. the main
half of the project development sector considers and totally
survey all the desired desires for developing the project. for
each project Literature survey is that the most significant

7
sector in code development method.
Before developing the tools and therefore the associated
coming up with it's necessary to work out and survey the time
issue, resource demand, man power, economy, and company
strength.
Once these items area unit glad and absolutely surveyed,
then consecutive step is to see concerning the software
package specifications within the individual system like what
form of software system the project would need, and what area
unit all the required software package area unit required to
proceed with consecutive step like developing the tools, and
also the associated operations.

CHAPTER 3 AIM AND SCOPE


3.1 AIM

The objective of this project is to create a own Chess engine


which is user friendly and also to make user comfortable. And
this project is a two player game. And prediction for game
winner is to display for every move.

8
3.2 SCOPE

The scope of the project is as follows:

Scope of this project is to make a own chess engine which is


customizable like to implement the rules like castling in the
game. And to make game is for entertainment purpose. To
provide a friendly environment where user can improve game
skills with more interest.

9
CHAPTER 4

SYSTEM DESIGN AND METHODOLOGY

4.1 PROPOSED SYSTEM

This system is proposed with certain features which makes user to


feel comfortable.

The proposed system is a engine which can detect whether the


present move is right or wrong.

Checks the each and every move is going to be the part of


winning prediction of the player.

Notifications like player moves and taken opponent‟s


chess piece is displayed. Illegal moves are not considered
and given chance to make a perfect move.
Understandable code for everyone because of co-ordinates
geometry concept.

4.2 REQUIREMENT SPECIFICATION

This proposed software runs effectively on a computing


system that has the minimum requirements. Undertaking all the
equipment necessities are not satisfied but rather exist in their
systems administration between the user‟s machines alread1.
So, the main need is to introduce appropriate equipment for the
product. The requirements are split into two categories, namely:
4.2.1 SOFTWARE REQUIREMENTS

The basic software requirements to run the program are:

1. Windows 10

2. HARDWARE REQUIREMENTS

The basic hardware required to run the program are:

3. Hard disk of 5 GB

4. System memory (RAM) of 512 MB

5. I3 processor-based computer or higher.

4.3 EXISTING SYSTEM

In the present scenario, html,css & javascript has its module


called chess which can do all the operations on the chess
moves. But graphically its not. And it is the most used module
for the chess game and for chess stud1 purpose.
CHAPTER 5
SOFTWARE DEVELOPMENT METHODOLOGY

5.1 SYSTEM ARCHITECTURE

The project is implemented by a combination of html,css &


javascript. It contains many files separate folder for images to
represent the pieces and its movements, and another for the
source code. The code follows CHESS architecture. Below in
Figure 5.1 the architecture diagram is shown.

Figure 5.1: CHESS ARCHITECTURE


CHESS game is done by based on 2-Dimensional array. I took
a[8][8] array to have 8*8 square box or to represent the board.
And placing is done by referencing a normal chess board,
pieces like castle, bishop, knight, king, queen and pawn are
their entire different rules. And win flag is applied to declare the
winner. Finally who kills the king he‟ll be the winner of the game
and announced at last.
KEYS:

CASTLE - The movement of the castle must be either in


straight line or horizontal Line like [a1][1] is to
move.
KNIGHT - The movement of the knight must be in shape of „L‟
moving two squares vertically or horizontally, then
makling a “turn”left or right and moving one more square.
BISHOP - The movement of the bishop must be in diagonal in
any direction and remains on square of one colour.
QUEEN - The movement of queen is a combination of castle
and bishop. A queen moves any number of squares
in a straight line, in any direction.
KING - The movement of king must have to move one step
in any direction.
CHAPTER 6
RESULTS AND DISCUSSION

FIGURE 6.1 GAME BOARD

MODULE DESCRIPTION:

 Game Intro Module

 User Input module

 Step Validation module

 Game Updation module

 Winner deaclaration module


User Input module:

User Input module is used to ensure the event of every mouse


is not for the chess piece movement. And it captures the
coordinates whenever it selects on the chess board and sends
the coordinates for the validation, to check whether it‟s a legal
move or not. And this project is made with window size of (512
px,512 px).

FIGURE 6.3 USER INPUT MODULE


Step Validation module:

This module provides signal whether the move is valid/legal or


not. And in this module there are multiple signals given for the
input move. There are totally 4 types of signals
/ flags . They are :-

1. Signal 0:

This signal is for to indicate the input move / step is not


valid / legal. And also if the player unwantedly selects the
opponent‟s chess piece it generates a signal 0 and displays the
message that “wrong move”.

FIGURE 6.4.1 SIGNAL 0


2. Signal 1:

This signal is for the chess piece whether it can move to


its destination with no interaction of any chess piece in its way.
If it can made the destination, then signal is generated and
message is generated that it made a safe move.

FIGURE 6.4.2 SIGNAL 1


3. Signal 11:

This signal is for chess piece whether the player1 piece


captured or taken the opponents piece. If this condition is true
then system generates a message like “ [player1 piece] killed
[player2 piece]”.

FIGURE 6.4.3 SIGNAL 11


4. Signal 22:

This signal is for chess piece whether the player1 piece


is perfectly captured the opponent‟s king. If it is done it returns
a signal 22. Finally winner declaration will be done and game
will be over.

FIGURE 6.4.4 SIGNAL 22

And after completion of checking these validations it goes to


the chess board for the next step updation of the chess board.
So that it can move chess piece in the code and display over
the window.
Game Updation Module:

This module is used update the chess board which is used to


display current state of board for every move. There will be
done two things.

 Either to swap the piece with empty square.

 Or two replace the opponents piece with the players piece.

Winner declaration module:

This module is used to fetch the game all the time to check
whether the opponent‟s king is been captured or not. If yes,
then game is closed and displays the message like “[winning
player‟s name] win”
CHAPTER 7

CONCLUSION

By checking all the possible cases to run the chess engine.


This project running successfully without any flaws. And also
can be done in advanced way.

It is a chess game with more benefits. Firstly, its more


benefitable for the ones who wants and tries to stud1 the code
and logic behind the code. And its GUI programming of the
pygame is more flexible than the “Ktinker module” for gaming
interface.
REFERENCES

[1] Co-ordinates concept in geometry.

[2] Mathematical logics on co-ordinates.

[3]
SOURCE CODE (HTML)

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Chess Game || Web Mentor</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div id="game">
<!-- row eight -->
<div class="cellprefix">8</div>
<div class="gamecell" id="1_8"></div>
<div class="gamecell grey" id="2_8"></div>
<div class="gamecell" id="3_8"></div>
<div class="gamecell grey" id="4_8"></div>
<div class="gamecell" id="5_8"></div>
<div class="gamecell grey" id="6_8"></div>
<div class="gamecell" id="7_8"></div>
<div class="gamecell grey" id="8_8"></div>
<!-- row seven -->
<div class="cellprefix">7</div>
<div class="gamecell grey" id="1_7"></div>
<div class="gamecell" id="2_7"></div>
<div class="gamecell grey" id="3_7"></div>
<div class="gamecell" id="4_7"></div>
<div class="gamecell grey" id="5_7"></div>
<div class="gamecell" id="6_7"></div>
<div class="gamecell grey" id="7_7"></div>
<div class="gamecell" id="8_7"></div>
<!-- row six -->
<div class="cellprefix">6</div>
<div class="gamecell" id="1_6"></div>
<div class="gamecell grey" id="2_6"></div>
<div class="gamecell" id="3_6"></div>
<div class="gamecell grey" id="4_6"></div>
<div class="gamecell" id="5_6"></div>
<div class="gamecell grey" id="6_6"></div>
<div class="gamecell" id="7_6"></div>
<div class="gamecell grey" id="8_6"></div>
<!-- row five -->
<div class="cellprefix">5</div>
<div class="gamecell grey" id="1_5"></div>
<div class="gamecell" id="2_5"></div>
<div class="gamecell grey" id="3_5"></div>
<div class="gamecell" id="4_5"></div>
<div class="gamecell grey" id="5_5"></div>
<div class="gamecell" id="6_5"></div>
<div class="gamecell grey" id="7_5"></div>
<div class="gamecell" id="8_5"></div>
<!-- row four -->
<div class="cellprefix">4</div>
<div class="gamecell" id="1_4"></div>
<div class="gamecell grey" id="2_4"></div>
<div class="gamecell" id="3_4"></div>
<div class="gamecell grey" id="4_4"></div>
<div class="gamecell" id="5_4"></div>
<div class="gamecell grey" id="6_4"></div>
<div class="gamecell" id="7_4"></div>
<div class="gamecell grey" id="8_4"></div>
<!-- row three -->
<div class="cellprefix">3</div>
<div class="gamecell grey" id="1_3"></div>
<div class="gamecell" id="2_3"></div>
<div class="gamecell grey" id="3_3"></div>
<div class="gamecell" id="4_3"></div>
<div class="gamecell grey" id="5_3"></div>
<div class="gamecell" id="6_3"></div>
<div class="gamecell grey" id="7_3"></div>
<div class="gamecell" id="8_3"></div>
<!-- row two -->
<div class="cellprefix">2</div>
<div class="gamecell" id="1_2"></div>
<div class="gamecell grey" id="2_2"></div>
<div class="gamecell" id="3_2"></div>
<div class="gamecell grey" id="4_2"></div>
<div class="gamecell" id="5_2"></div>
<div class="gamecell grey" id="6_2"></div>
<div class="gamecell" id="7_2"></div>
<div class="gamecell grey" id="8_2"></div>
<!-- row one -->
<div class="cellprefix">1</div>
<div class="gamecell grey" id="1_1"></div>
<div class="gamecell" id="2_1"></div>
<div class="gamecell grey" id="3_1"></div>
<div class="gamecell" id="4_1"></div>
<div class="gamecell grey" id="5_1"></div>
<div class="gamecell" id="6_1"></div>
<div class="gamecell grey" id="7_1"></div>
<div class="gamecell" id="8_1"></div>
<div class="cellprefix"></div>
<div class="cellprefix">a</div>
<div class="cellprefix">b</div>
<div class="cellprefix">c</div>
<div class="cellprefix">d</div>
<div class="cellprefix">e</div>
<div class="cellprefix">f</div>
<div class="cellprefix">g</div>
<div class="cellprefix">h</div>
<div id="turn">It's White's Turn</div>
</div>

<script
src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jque
ry.min.js'></script>
<script src="script.js"></script>
</body>
</html>
CSS
html,
body {
width: 100%;
height: 100%;
padding: 0;
margin: 0;
font-family: sans-serif;
}

div * {
padding: 0;
margin: 0;
box-sizing: border-box;
}

#turn {
max-width: 451px;
max-height: 30px;
width: 100%;
height: 100%;
position: relative;
float: right;
border-radius: 5px;
border: 1px solid rgb(0, 0, 0);
border-style: inset;
text-align: center;
padding: 5px 0 0 0;
background: #fff;
transition: .85s linear;
}

.turnhighlight {
background: #5cb85c !important;
color: #fff;
}

#game {
max-width: 504px;
max-height: 504px;
width: 100%;
height: 100%;
position: relative;
margin: 20px auto;
}

.cellprefix {
width: 100%;
height: 100%;
max-width: 50px;
max-height: 50px;
float: left;
margin: 3px;
padding: 15px 0 0 20px;
}

.gamecell {
border: 1px solid #000;
width: 100%;
height: 100%;
max-width: 50px;
max-height: 50px;
float: left;
margin: 3px;
transition: all 0.5s ease-in-out;
border-radius: 5px;
font-size: 30pt;
padding: 0 0 0 6px;
cursor: pointer;
z-index: 1;
}

.gamecell:hover {
color: #fff;
background: rgba(37, 88, 228, 0.712);
z-index: 2;
transform: translate(10px, -10px);
animation: neonBlueText 1.5s ease-in-out infinite
alternate;
}
.grey {
background: rgba(128, 128, 128, 0.801);
}

.green {
/*background: green !important;*/
background: rgb(65, 161, 73) !important;
}

.neonblue_txt {
animation: neonBlueText 1.5s ease-in-out infinite
alternate;
}

.neonorange_txt {
animation: neonOrangeText 1.5s ease-in-out infinite
alternate;
}

.neongreen_txt {
animation: neonGreenText 1.5s ease-in-out infinite
alternate;
}

/* --- N E O N T E X T --- */
@keyframes neonBlueText {
from {
text-shadow: 0 0 10px #fff, 0 0 20px #fff, 0 0 30px #fff,
0 0 40px #228dff,
0 0 70px #228dff, 0 0 80px #228dff, 0 0 100px #228dff,
0 0 150px #228dff;
}
to {
text-shadow: 0 0 5px #fff, 0 0 10px #fff, 0 0 15px #fff,
0 0 20px #228dff,
0 0 35px #228dff, 0 0 40px #228dff, 0 0 50px #228dff, 0
0 75px #228dff;
}
}

@keyframes neonOrangeText {
from {
text-shadow: 0 0 10px #fff, 0 0 20px #fff, 0 0 30px #fff,
0 0 40px #ff9900,
0 0 70px #ff9900, 0 0 80px #ff9900, 0 0 100px #ff9900,
0 0 150px #ff9900;
}
to {
text-shadow: 0 0 5px #fff, 0 0 10px #fff, 0 0 15px #fff,
0 0 20px #ff9900,
0 0 35px #ff9900, 0 0 40px #ff9900, 0 0 50px #ff9900, 0
0 75px #ff9900;
}
}

@keyframes neonGreenText {
from {
text-shadow: 0 0 10px #fff, 0 0 20px #fff, 0 0 30px #fff,
0 0 40px #b6ff00,
0 0 70px #b6ff00, 0 0 80px #b6ff00, 0 0 100px #b6ff00,
0 0 150px #b6ff00;
}
to {
text-shadow: 0 0 5px #fff, 0 0 10px #fff, 0 0 15px #fff,
0 0 20px #b6ff00,
0 0 35px #b6ff00, 0 0 40px #b6ff00, 0 0 50px #b6ff00, 0
0 75px #b6ff00;
}
}
/* --- N E O N --- */

/* animation: neon 1.5s ease-in-out infinite alternate; */

@keyframes neonBlue {
from {
box-shadow: 0 0 10px #fff, 0 0 20px #fff, 0 0 30px #fff,
0 0 40px #228dff,
0 0 70px #228dff, 0 0 80px #228dff, 0 0 100px #228dff,
0 0 150px #228dff;
}
to {
box-shadow: 0 0 5px #fff, 0 0 10px #fff, 0 0 15px #fff, 0
0 20px #228dff,
0 0 35px #228dff, 0 0 40px #228dff, 0 0 50px #228dff, 0
0 75px #228dff;
}
}

/*! * * * * * * * * * * * * * * * * * * * *\
CSShake :: shake-little
v1.5.0
CSS classes to move your DOM
(c) 2015 @elrumordelaluz
http://elrumordelaluz.github.io/csshake/
Licensed under MIT
\* * * * * * * * * * * * * * * * * * * * */
.shake-little {
display: inline-block;
transform-origin: center center; }

.shake-freeze,
.shake-constant.shake-constant--hover:hover,
.shake-trigger:hover .shake-constant.shake-constant--hover {
animation-play-state: paused; }

.shake-freeze:hover,
.shake-trigger:hover .shake-freeze, .shake-little:hover,
.shake-trigger:hover .shake-little {
animation-play-state: running; }

@keyframes shake-little {
2% {
transform: translate(1px, 0px) rotate(0.5deg); }
4% {
transform: translate(1px, 0px) rotate(0.5deg); }
6% {
transform: translate(1px, 1px) rotate(0.5deg); }
8% {
transform: translate(0px, 0px) rotate(0.5deg); }
10% {
transform: translate(1px, 0px) rotate(0.5deg); }
12% {
transform: translate(0px, 0px) rotate(0.5deg); }
14% {
transform: translate(1px, 1px) rotate(0.5deg); }
16% {
transform: translate(0px, 1px) rotate(0.5deg); }
18% {
transform: translate(1px, 0px) rotate(0.5deg); }
20% {
transform: translate(0px, 1px) rotate(0.5deg); }
22% {
transform: translate(0px, 0px) rotate(0.5deg); }
24% {
transform: translate(0px, 0px) rotate(0.5deg); }
26% {
transform: translate(1px, 1px) rotate(0.5deg); }
28% {
transform: translate(0px, 1px) rotate(0.5deg); }
30% {
transform: translate(0px, 0px) rotate(0.5deg); }
32% {
transform: translate(1px, 1px) rotate(0.5deg); }
34% {
transform: translate(0px, 1px) rotate(0.5deg); }
36% {
transform: translate(0px, 1px) rotate(0.5deg); }
38% {
transform: translate(0px, 0px) rotate(0.5deg); }
40% {
transform: translate(1px, 0px) rotate(0.5deg); }
42% {
transform: translate(0px, 1px) rotate(0.5deg); }
44% {
transform: translate(0px, 1px) rotate(0.5deg); }
46% {
transform: translate(0px, 0px) rotate(0.5deg); }
48% {
transform: translate(1px, 0px) rotate(0.5deg); }
50% {
transform: translate(1px, 1px) rotate(0.5deg); }
52% {
transform: translate(0px, 0px) rotate(0.5deg); }
54% {
transform: translate(1px, 1px) rotate(0.5deg); }
56% {
transform: translate(0px, 1px) rotate(0.5deg); }
58% {
transform: translate(1px, 0px) rotate(0.5deg); }
60% {
transform: translate(1px, 1px) rotate(0.5deg); }
62% {
transform: translate(0px, 1px) rotate(0.5deg); }
64% {
transform: translate(0px, 0px) rotate(0.5deg); }
66% {
transform: translate(1px, 0px) rotate(0.5deg); }
68% {
transform: translate(0px, 0px) rotate(0.5deg); }
70% {
transform: translate(1px, 0px) rotate(0.5deg); }
72% {
transform: translate(1px, 1px) rotate(0.5deg); }
74% {
transform: translate(1px, 1px) rotate(0.5deg); }
76% {
transform: translate(0px, 0px) rotate(0.5deg); }
78% {
transform: translate(0px, 0px) rotate(0.5deg); }
80% {
transform: translate(1px, 0px) rotate(0.5deg); }
82% {
transform: translate(1px, 1px) rotate(0.5deg); }
84% {
transform: translate(0px, 1px) rotate(0.5deg); }
86% {
transform: translate(1px, 1px) rotate(0.5deg); }
88% {
transform: translate(1px, 1px) rotate(0.5deg); }
90% {
transform: translate(0px, 1px) rotate(0.5deg); }
92% {
transform: translate(1px, 0px) rotate(0.5deg); }
94% {
transform: translate(1px, 0px) rotate(0.5deg); }
96% {
transform: translate(1px, 0px) rotate(0.5deg); }
98% {
transform: translate(1px, 1px) rotate(0.5deg); }
0%, 100% {
transform: translate(0, 0) rotate(0); } }

.shake-little:hover,
.shake-trigger:hover .shake-little, .shake-little.shake-
freeze, .shake-little.shake-constant {
animation-name: shake-little;
animation-duration: 100ms;
animation-timing-function: ease-in-out;
animation-iteration-count: infinite; }
JAVASCRIPT
let main = {

variables: {
turn: 'w',
selectedpiece: '',
highlighted: [],
pieces: {
w_king: {
position: '5_1',
img: '&#9812;',
captured: false,
moved: false,
type: 'w_king'

},
w_queen: {
position: '4_1',
img: '&#9813;',
captured: false,
moved: false,
type: 'w_queen'
},
w_bishop1: {
position: '3_1',
img: '&#9815;',
captured: false,
moved: false,
type: 'w_bishop'
},
w_bishop2: {
position: '6_1',
img: '&#9815;',
captured: false,
moved: false,
type: 'w_bishop'
},
w_knight1: {
position: '2_1',
img: '&#9816;',
captured: false,
moved: false,
type: 'w_knight'
},
w_knight2: {
position: '7_1',
img: '&#9816;',
captured: false,
moved: false,
type: 'w_knight'
},
w_rook1: {
position: '1_1',
img: '&#9814;',
captured: false,
moved: false,
type: 'w_rook'
},
w_rook2: {
position: '8_1',
img: '&#9814;',
captured: false,
moved: false,
type: 'w_rook'
},
w_pawn1: {
position: '1_2',
img: '&#9817;',
captured: false,
type: 'w_pawn',
moved: false
},
w_pawn2: {
position: '2_2',
img: '&#9817;',
captured: false,
type: 'w_pawn',
moved: false
},
w_pawn3: {
position: '3_2',
img: '&#9817;',
captured: false,
type: 'w_pawn',
moved: false
},
w_pawn4: {
position: '4_2',
img: '&#9817;',
captured: false,
type: 'w_pawn',
moved: false
},
w_pawn5: {
position: '5_2',
img: '&#9817;',
captured: false,
type: 'w_pawn',
moved: false
},
w_pawn6: {
position: '6_2',
img: '&#9817;',
captured: false,
type: 'w_pawn',
moved: false
},
w_pawn7: {
position: '7_2',
img: '&#9817;',
captured: false,
type: 'w_pawn',
moved: false
},
w_pawn8: {
position: '8_2',
img: '&#9817;',
captured: false,
type: 'w_pawn',
moved: false
},

b_king: {
position: '5_8',
img: '&#9818;',
captured: false,
moved: false,
type: 'b_king'
},
b_queen: {
position: '4_8',
img: '&#9819;',
captured: false,
moved: false,
type: 'b_queen'
},
b_bishop1: {
position: '3_8',
img: '&#9821;',
captured: false,
moved: false,
type: 'b_bishop'
},
b_bishop2: {
position: '6_8',
img: '&#9821;',
captured: false,
moved: false,
type: 'b_bishop'
},
b_knight1: {
position: '2_8',
img: '&#9822;',
captured: false,
moved: false,
type: 'b_knight'
},
b_knight2: {
position: '7_8',
img: '&#9822;',
captured: false,
moved: false,
type: 'b_knight'
},
b_rook1: {
position: '1_8',
img: '&#9820;',
captured: false,
moved: false,
type: 'b_rook'
},
b_rook2: {
position: '8_8',
img: '&#9820;',
captured: false,
moved: false,
type: 'b_rook'
},
b_pawn1: {
position: '1_7',
img: '&#9823;',
captured: false,
type: 'b_pawn',
moved: false
},
b_pawn2: {
position: '2_7',
img: '&#9823;',
captured: false,
type: 'b_pawn',
moved: false
},
b_pawn3: {
position: '3_7',
img: '&#9823;',
captured: false,
type: 'b_pawn',
moved: false
},
b_pawn4: {
position: '4_7',
img: '&#9823;',
captured: false,
type: 'b_pawn',
moved: false
},
b_pawn5: {
position: '5_7',
img: '&#9823;',
captured: false,
type: 'b_pawn',
moved: false
},
b_pawn6: {
position: '6_7',
img: '&#9823;',
captured: false,
type: 'b_pawn',
moved: false
},
b_pawn7: {
position: '7_7',
img: '&#9823;',
captured: false,
type: 'b_pawn',
moved: false
},
b_pawn8: {
position: '8_7',
img: '&#9823;',
captured: false,
type: 'b_pawn',
moved: false
}

}
},

methods: {
gamesetup: function() {
$('.gamecell').attr('chess', 'null');
for (let gamepiece in main.variables.pieces) {
$('#' +
main.variables.pieces[gamepiece].position).html(main.variable
s.pieces[gamepiece].img);
$('#' +
main.variables.pieces[gamepiece].position).attr('chess',
gamepiece);
}
},
moveoptions: function(selectedpiece) {

let position = { x: '', y: '' };


position.x =
main.variables.pieces[selectedpiece].position.split('_')[0];
position.y =
main.variables.pieces[selectedpiece].position.split('_')[1];

// these options need to be var instead of let


var options = [];
var coordinates = [];
var startpoint =
main.variables.pieces[selectedpiece].position;
var c1,c2,c3,c4,c5,c6,c7,c8;

if (main.variables.highlighted.length != 0) {

main.methods.togglehighlight(main.variables.highlighted);
}

switch (main.variables.pieces[selectedpiece].type) {
case 'w_king':

if ($('#6_1').attr('chess') == 'null' && $


('#7_1').attr('chess') == 'null' &&
main.variables.pieces['w_king'].moved == false &&
main.variables.pieces['w_rook2'].moved == false) {
coordinates = [{ x: 1, y: 1 },{ x: 1, y: 0 },{ x: 1,
y: -1 },{ x: 0, y: -1 },{ x: -1, y: -1 },{ x: -1, y: 0 },{ x:
-1, y: 1 },{ x: 0, y: 1 },{x: 2, y: 0}].map(function(val){
return (parseInt(position.x) + parseInt(val.x)) +
'_' + (parseInt(position.y) + parseInt(val.y));
});
} else {
coordinates = [{ x: 1, y: 1 },{ x: 1, y: 0 },{ x: 1,
y: -1 },{ x: 0, y: -1 },{ x: -1, y: -1 },{ x: -1, y: 0 },{ x:
-1, y: 1 },{ x: 0, y: 1 }].map(function(val){
return (parseInt(position.x) + parseInt(val.x)) +
'_' + (parseInt(position.y) + parseInt(val.y));
});
}

options = (main.methods.options(startpoint,
coordinates,
main.variables.pieces[selectedpiece].type)).slice(0);
main.variables.highlighted = options.slice(0);
main.methods.togglehighlight(options);

break;
case 'b_king':

if ($('#6_8').attr('chess') == 'null' && $


('#7_8').attr('chess') == 'null' &&
main.variables.pieces['b_king'].moved == false &&
main.variables.pieces['b_rook2'].moved == false) {
coordinates = [{ x: 1, y: 1 },{ x: 1, y: 0 },{ x: 1,
y: -1 },{ x: 0, y: -1 },{ x: -1, y: -1 },{ x: -1, y: 0 },{ x:
-1, y: 1 },{ x: 0, y: 1 },{x: 2, y: 0}].map(function(val){
return (parseInt(position.x) + parseInt(val.x)) + '_'
+ (parseInt(position.y) + parseInt(val.y));
});
} else {
coordinates = [{ x: 1, y: 1 },{ x: 1, y: 0 },{ x: 1,
y: -1 },{ x: 0, y: -1 },{ x: -1, y: -1 },{ x: -1, y: 0 },{ x:
-1, y: 1 },{ x: 0, y: 1 }].map(function(val){
return (parseInt(position.x) + parseInt(val.x)) + '_'
+ (parseInt(position.y) + parseInt(val.y));
});
}
/*
coordinates = [{ x: 1, y: 1 },{ x: 1, y: 0 },{ x: 1,
y: -1 },{ x: 0, y: -1 },{ x: -1, y: -1 },{ x: -1, y: 0 },{ x:
-1, y: 1 },{ x: 0, y: 1 }].map(function(val){
return (parseInt(position.x) + parseInt(val.x)) + '_'
+ (parseInt(position.y) + parseInt(val.y));
});
*/
options = (main.methods.options(startpoint,
coordinates,
main.variables.pieces[selectedpiece].type)).slice(0);
main.variables.highlighted = options.slice(0);
main.methods.togglehighlight(options);

break;
case 'w_queen':

c1 = main.methods.w_options(position,[{x: 1, y: 1},{x:
2, y: 2},{x: 3, y: 3},{x: 4, y: 4},{x: 5, y: 5},{x: 6, y: 6},
{x: 7, y: 7}]);
c2 = main.methods.w_options(position,[{x: 1, y: -1},
{x: 2, y: -2},{x: 3, y: -3},{x: 4, y: -4},{x: 5, y: -5},{x:
6, y: -6},{x: 7, y: -7}]);
c3 = main.methods.w_options(position,[{x: -1, y: 1},
{x: -2, y: 2},{x: -3, y: 3},{x: -4, y: 4},{x: -5, y: 5},{x: -
6, y: 6},{x: -7, y: 7}]);
c4 = main.methods.w_options(position,[{x: -1, y: -1},
{x: -2, y: -2},{x: -3, y: -3},{x: -4, y: -4},{x: -5, y: -5},
{x: -6, y: -6},{x: -7, y: -7}]);
c5 = main.methods.w_options(position,[{x: 1, y: 0},{x:
2, y: 0},{x: 3, y: 0},{x: 4, y: 0},{x: 5, y: 0},{x: 6, y: 0},
{x: 7, y: 0}]);
c6 = main.methods.w_options(position,[{x: 0, y: 1},{x:
0, y: 2},{x: 0, y: 3},{x: 0, y: 4},{x: 0, y: 5},{x: 0, y: 6},
{x: 0, y: 7}]);
c7 = main.methods.w_options(position,[{x: -1, y: 0},
{x: -2, y: 0},{x: -3, y: 0},{x: -4, y: 0},{x: -5, y: 0},{x: -
6, y: 0},{x: -7, y: 0}]);
c8 = main.methods.w_options(position,[{x: 0, y: -1},
{x: 0, y: -2},{x: 0, y: -3},{x: 0, y: -4},{x: 0, y: -5},{x:
0, y: -6},{x: 0, y: -7}]);

coordinates =
c1.concat(c2).concat(c3).concat(c4).concat(c5).concat(c6).con
cat(c7).concat(c8);

options = coordinates.slice(0);
main.variables.highlighted = options.slice(0);
main.methods.togglehighlight(options);

break;
case 'b_queen':

c1 = main.methods.b_options(position,[{x: 1, y: 1},
{x: 2, y: 2},{x: 3, y: 3},{x: 4, y: 4},{x: 5, y: 5},{x: 6, y:
6},{x: 7, y: 7}]);
c2 = main.methods.b_options(position,[{x: 1, y: -1},
{x: 2, y: -2},{x: 3, y: -3},{x: 4, y: -4},{x: 5, y: -5},{x:
6, y: -6},{x: 7, y: -7}]);
c3 = main.methods.b_options(position,[{x: -1, y: 1},
{x: -2, y: 2},{x: -3, y: 3},{x: -4, y: 4},{x: -5, y: 5},{x: -
6, y: 6},{x: -7, y: 7}]);
c4 = main.methods.b_options(position,[{x: -1, y: -1},
{x: -2, y: -2},{x: -3, y: -3},{x: -4, y: -4},{x: -5, y: -5},
{x: -6, y: -6},{x: -7, y: -7}]);
c5 = main.methods.b_options(position,[{x: 1, y: 0},
{x: 2, y: 0},{x: 3, y: 0},{x: 4, y: 0},{x: 5, y: 0},{x: 6, y:
0},{x: 7, y: 0}]);
c6 = main.methods.b_options(position,[{x: 0, y: 1},
{x: 0, y: 2},{x: 0, y: 3},{x: 0, y: 4},{x: 0, y: 5},{x: 0, y:
6},{x: 0, y: 7}]);
c7 = main.methods.b_options(position,[{x: -1, y: 0},
{x: -2, y: 0},{x: -3, y: 0},{x: -4, y: 0},{x: -5, y: 0},{x: -
6, y: 0},{x: -7, y: 0}]);
c8 = main.methods.b_options(position,[{x: 0, y: -1},
{x: 0, y: -2},{x: 0, y: -3},{x: 0, y: -4},{x: 0, y: -5},{x:
0, y: -6},{x: 0, y: -7}]);

coordinates =
c1.concat(c2).concat(c3).concat(c4).concat(c5).concat(c6).con
cat(c7).concat(c8);

options = coordinates.slice(0);
main.variables.highlighted = options.slice(0);
main.methods.togglehighlight(options);

break;

case 'w_bishop':

c1 = main.methods.w_options(position,[{x: 1, y: 1},{x:
2, y: 2},{x: 3, y: 3},{x: 4, y: 4},{x: 5, y: 5},{x: 6, y: 6},
{x: 7, y: 7}]);
c2 = main.methods.w_options(position,[{x: 1, y: -1},
{x: 2, y: -2},{x: 3, y: -3},{x: 4, y: -4},{x: 5, y: -5},{x:
6, y: -6},{x: 7, y: -7}]);
c3 = main.methods.w_options(position,[{x: -1, y: 1},
{x: -2, y: 2},{x: -3, y: 3},{x: -4, y: 4},{x: -5, y: 5},{x: -
6, y: 6},{x: -7, y: 7}]);
c4 = main.methods.w_options(position,[{x: -1, y: -1},
{x: -2, y: -2},{x: -3, y: -3},{x: -4, y: -4},{x: -5, y: -5},
{x: -6, y: -6},{x: -7, y: -7}]);

coordinates = c1.concat(c2).concat(c3).concat(c4);

options = coordinates.slice(0);
main.variables.highlighted = options.slice(0);
main.methods.togglehighlight(options);

break;

case 'b_bishop':

c1 = main.methods.b_options(position,[{x: 1, y: 1},{x:
2, y: 2},{x: 3, y: 3},{x: 4, y: 4},{x: 5, y: 5},{x: 6, y: 6},
{x: 7, y: 7}]);
c2 = main.methods.b_options(position,[{x: 1, y: -1},
{x: 2, y: -2},{x: 3, y: -3},{x: 4, y: -4},{x: 5, y: -5},{x:
6, y: -6},{x: 7, y: -7}]);
c3 = main.methods.b_options(position,[{x: -1, y: 1},
{x: -2, y: 2},{x: -3, y: 3},{x: -4, y: 4},{x: -5, y: 5},{x: -
6, y: 6},{x: -7, y: 7}]);
c4 = main.methods.b_options(position,[{x: -1, y: -1},
{x: -2, y: -2},{x: -3, y: -3},{x: -4, y: -4},{x: -5, y: -5},
{x: -6, y: -6},{x: -7, y: -7}]);

coordinates = c1.concat(c2).concat(c3).concat(c4);
options = coordinates.slice(0);
main.variables.highlighted = options.slice(0);
main.methods.togglehighlight(options);
break;
case 'w_knight':

coordinates = [{ x: -1, y: 2 },{ x: 1, y: 2 },{ x: 1,


y: -2 },{ x: -1, y: -2 },{ x: 2, y: 1 },{ x: 2, y: -1 },{ x:
-2, y: -1 },{ x: -2, y: 1 }].map(function(val){
return (parseInt(position.x) + parseInt(val.x)) + '_'
+ (parseInt(position.y) + parseInt(val.y));
});

options = (main.methods.options(startpoint,
coordinates,
main.variables.pieces[selectedpiece].type)).slice(0);
main.variables.highlighted = options.slice(0);
main.methods.togglehighlight(options);

break;
case 'b_knight':

coordinates = [{ x: -1, y: 2 },{ x: 1, y: 2 },{ x: 1,


y: -2 },{ x: -1, y: -2 },{ x: 2, y: 1 },{ x: 2, y: -1 },{ x:
-2, y: -1 },{ x: -2, y: 1 }].map(function(val){
return (parseInt(position.x) + parseInt(val.x)) + '_'
+ (parseInt(position.y) + parseInt(val.y));
});

options = (main.methods.options(startpoint,
coordinates,
main.variables.pieces[selectedpiece].type)).slice(0);
main.variables.highlighted = options.slice(0);
main.methods.togglehighlight(options);

break;
case 'w_rook':

c1 = main.methods.w_options(position,[{x: 1, y: 0},{x:
2, y: 0},{x: 3, y: 0},{x: 4, y: 0},{x: 5, y: 0},{x: 6, y: 0},
{x: 7, y: 0}]);
c2 = main.methods.w_options(position,[{x: 0, y: 1},{x:
0, y: 2},{x: 0, y: 3},{x: 0, y: 4},{x: 0, y: 5},{x: 0, y: 6},
{x: 0, y: 7}]);
c3 = main.methods.w_options(position,[{x: -1, y: 0},
{x: -2, y: 0},{x: -3, y: 0},{x: -4, y: 0},{x: -5, y: 0},{x: -
6, y: 0},{x: -7, y: 0}]);
c4 = main.methods.w_options(position,[{x: 0, y: -1},
{x: 0, y: -2},{x: 0, y: -3},{x: 0, y: -4},{x: 0, y: -5},{x:
0, y: -6},{x: 0, y: -7}]);

coordinates = c1.concat(c2).concat(c3).concat(c4);

options = coordinates.slice(0);
main.variables.highlighted = options.slice(0);
main.methods.togglehighlight(options);

break;
case 'b_rook':

c1 = main.methods.b_options(position,[{x: 1, y: 0},{x:
2, y: 0},{x: 3, y: 0},{x: 4, y: 0},{x: 5, y: 0},{x: 6, y: 0},
{x: 7, y: 0}]);
c2 = main.methods.b_options(position,[{x: 0, y: 1},{x:
0, y: 2},{x: 0, y: 3},{x: 0, y: 4},{x: 0, y: 5},{x: 0, y: 6},
{x: 0, y: 7}]);
c3 = main.methods.b_options(position,[{x: -1, y: 0},
{x: -2, y: 0},{x: -3, y: 0},{x: -4, y: 0},{x: -5, y: 0},{x: -
6, y: 0},{x: -7, y: 0}]);
c4 = main.methods.b_options(position,[{x: 0, y: -1},
{x: 0, y: -2},{x: 0, y: -3},{x: 0, y: -4},{x: 0, y: -5},{x:
0, y: -6},{x: 0, y: -7}]);

coordinates = c1.concat(c2).concat(c3).concat(c4);

options = coordinates.slice(0);
main.variables.highlighted = options.slice(0);
main.methods.togglehighlight(options);

break;
case 'w_pawn':

if (main.variables.pieces[selectedpiece].moved ==
false) {

coordinates = [{ x: 0, y: 1 },{ x: 0, y: 2 },{ x: 1,


y: 1 },{ x: -1, y: 1 }].map(function(val){
return (parseInt(position.x) + parseInt(val.x)) +
'_' + (parseInt(position.y) + parseInt(val.y));
});

}
else if (main.variables.pieces[selectedpiece].moved ==
true) {

coordinates = [{ x: 0, y: 1 },{ x: 1, y: 1 },{ x: -1,


y: 1 }].map(function(val){
return (parseInt(position.x) + parseInt(val.x)) +
'_' + (parseInt(position.y) + parseInt(val.y));
});

options = (main.methods.options(startpoint,
coordinates,
main.variables.pieces[selectedpiece].type)).slice(0);
main.variables.highlighted = options.slice(0);
main.methods.togglehighlight(options);

break;
case 'b_pawn':

// calculate pawn options


if (main.variables.pieces[selectedpiece].moved ==
false) {

coordinates = [{ x: 0, y: -1 },{ x: 0, y: -2 },{ x:


1, y: -1 },{ x: -1, y: -1 }].map(function(val){
return (parseInt(position.x) + parseInt(val.x)) +
'_' + (parseInt(position.y) + parseInt(val.y));
});

}
else if (main.variables.pieces[selectedpiece].moved ==
true) {

coordinates = [{ x: 0, y: -1 },{ x: 1, y: -1 },{ x: -


1, y: -1 }].map(function(val){
return (parseInt(position.x) + parseInt(val.x)) +
'_' + (parseInt(position.y) + parseInt(val.y));
});

options = (main.methods.options(startpoint,
coordinates,
main.variables.pieces[selectedpiece].type)).slice(0);
main.variables.highlighted = options.slice(0);
main.methods.togglehighlight(options);

break;

}
},

options: function(startpoint, coordinates, piecetype) {


// first check if any of the possible coordinates is out of
bounds;

coordinates = coordinates.filter(val => {


let pos = { x: 0, y: 0 };
pos.x = parseInt(val.split('_')[0]);
pos.y = parseInt(val.split('_')[1]);

if (!(pos.x < 1) && !(pos.x > 8) && !(pos.y < 1) && !


(pos.y > 8)) { // if it is not out of bounds, return the
coordinate;
return val;
}
});

switch (piecetype) {

case 'w_king':

coordinates = coordinates.filter(val => {


return ($('#' + val).attr('chess') == 'null' || ($
('#' + val).attr('chess')).slice(0,1) == 'b');
});

break;
case 'b_king':

coordinates = coordinates.filter(val => {


return ($('#' + val).attr('chess') == 'null' || ($
('#' + val).attr('chess')).slice(0,1) == 'w');
});

break;
case 'w_knight':

coordinates = coordinates.filter(val => {


return ($('#' + val).attr('chess') == 'null' || ($
('#' + val).attr('chess')).slice(0,1) == 'b');
});

break;

case 'b_knight':

coordinates = coordinates.filter(val => {


return ($('#' + val).attr('chess') == 'null' || ($
('#' + val).attr('chess')).slice(0,1) == 'w');
});
break;

case 'w_pawn':

coordinates = coordinates.filter(val => {


let sp = { x: 0, y: 0 };
let coordinate = val.split('_');

sp.x = startpoint.split('_')[0];
sp.y = startpoint.split('_')[1];

if (coordinate[0] < sp.x || coordinate[0] > sp.x){


// if the coordinate is on either side of the center, check
if it has an opponent piece on it;
return ($('#' + val).attr('chess') != 'null' && ($
('#' + val).attr('chess')).slice(0,1) == 'b'); // return
coordinates with opponent pieces on them
} else { // else if the coordinate is in the center;
if (coordinate[1] == (parseInt(sp.y) + 2) && $('#'
+ sp.x + '_' + (parseInt(sp.y) + 1)).attr('chess') != 'null')
{
// do nothing if this is the pawns first move, and
there is a piece in front of the 2nd coordinate;
} else {
return ($('#' + val).attr('chess') == 'null'); //
otherwise return the coordinate if there is no chess piece on
it;
}
}

});

break;

case 'b_pawn':

coordinates = coordinates.filter(val => {


let sp = { x: 0, y: 0 };
let coordinate = val.split('_');

sp.x = startpoint.split('_')[0];
sp.y = startpoint.split('_')[1];

if (coordinate[0] < sp.x || coordinate[0] > sp.x){ //


if the coordinate is on either side of the center, check if
it has an opponent piece on it;
return ($('#' + val).attr('chess') != 'null' && ($
('#' + val).attr('chess')).slice(0,1) == 'w'); // return
coordinates with opponent pieces on them
} else { // else if the coordinate is in the center;
if (coordinate[1] == (parseInt(sp.y) - 2) && $('#' +
sp.x + '_' + (parseInt(sp.y) - 1)).attr('chess') != 'null'){
// do nothing if this is the pawns first move, and
there is a piece in front of the 2nd coordinate;
} else {
return ($('#' + val).attr('chess') == 'null'); //
otherwise return the coordinate if there is no chess piece on
it;
}
}
});

break;
}

return coordinates;
},

w_options: function (position,coordinates) {

let flag = false;

coordinates = coordinates.map(function(val){ // convert


the x,y into actual grid id coordinates;
return (parseInt(position.x) + parseInt(val.x)) + '_'
+ (parseInt(position.y) + parseInt(val.y));
}).filter(val => {
let pos = { x: 0, y: 0 };
pos.x = parseInt(val.split('_')[0]);
pos.y = parseInt(val.split('_')[1]);

if (!(pos.x < 1) && !(pos.x > 8) && !(pos.y < 1) && !


(pos.y > 8)) { // if it is not out of bounds, return the
coordinate;
return val;
}
}).filter(val => { // algorithm to determine line-of-
sight movement options for bishop/rook/queen;
if (flag == false){
if ($('#' + val).attr('chess') == 'null'){
console.log(val)
return val;
} else if (($('#' + val).attr('chess')).slice(0,1) ==
'b') {
flag = true;
console.log(val)
return val;
} else if (($('#' + val).attr('chess')).slice(0,1) ==
'w') {
console.log(val+'-3')
flag = true;
}
}
});

return coordinates;

},

b_options: function (position,coordinates) {


let flag = false;

coordinates = coordinates.map(function(val){ // convert


the x,y into actual grid id coordinates;
return (parseInt(position.x) + parseInt(val.x)) + '_'
+ (parseInt(position.y) + parseInt(val.y));
}).filter(val => {
let pos = { x: 0, y: 0 };
pos.x = parseInt(val.split('_')[0]);
pos.y = parseInt(val.split('_')[1]);

if (!(pos.x < 1) && !(pos.x > 8) && !(pos.y < 1) && !


(pos.y > 8)) { // if it is not out of bounds, return the
coordinate;
return val;
}
}).filter(val => { // algorithm to determine line-of-
sight movement options for bishop/rook/queen;
if (flag == false){
if ($('#' + val).attr('chess') == 'null'){
return val;
} else if (($('#' + val).attr('chess')).slice(0,1) ==
'w') {
flag = true;
return val;
} else if (($('#' + val).attr('chess')).slice(0,1) ==
'b') {
flag = true;
}
}
});

return coordinates;

},

capture: function (target) {


let selectedpiece = {
name: $('#' +
main.variables.selectedpiece).attr('chess'),
id: main.variables.selectedpiece
};

//new cell
$('#' +
target.id).html(main.variables.pieces[selectedpiece.name].img
);
$('#' + target.id).attr('chess',selectedpiece.name);
//old cell
$('#' + selectedpiece.id).html('');
$('#' + selectedpiece.id).attr('chess','null');
//moved piece
main.variables.pieces[selectedpiece.name].position =
target.id;
main.variables.pieces[selectedpiece.name].moved = true;
// captured piece
main.variables.pieces[target.name].captured = true;
/*
// toggle highlighted coordinates

main.methods.togglehighlight(main.variables.highlighted);
main.variables.highlighted.length = 0;
// set the selected piece to '' again
main.variables.selectedpiece = '';
*/

},

move: function (target) {

let selectedpiece = $('#' +


main.variables.selectedpiece).attr('chess');

// new cell
$('#' +
target.id).html(main.variables.pieces[selectedpiece].img);
$('#' + target.id).attr('chess',selectedpiece);
// old cell
$('#' + main.variables.selectedpiece).html('');
$('#' +
main.variables.selectedpiece).attr('chess','null');
main.variables.pieces[selectedpiece].position =
target.id;
main.variables.pieces[selectedpiece].moved = true;

/*
// toggle highlighted coordinates

main.methods.togglehighlight(main.variables.highlighted);
main.variables.highlighted.length = 0;
// set the selected piece to '' again
main.variables.selectedpiece = '';
*/
},

endturn: function(){

if (main.variables.turn == 'w') {
main.variables.turn = 'b';

// toggle highlighted coordinates

main.methods.togglehighlight(main.variables.highlighted);
main.variables.highlighted.length = 0;
// set the selected piece to '' again
main.variables.selectedpiece = '';

$('#turn').html("It's Blacks Turn");

$('#turn').addClass('turnhighlight');
window.setTimeout(function(){
$('#turn').removeClass('turnhighlight');
}, 1500);

} else if (main.variables.turn = 'b'){


main.variables.turn = 'w';

// toggle highlighted coordinates

main.methods.togglehighlight(main.variables.highlighted);
main.variables.highlighted.length = 0;
// set the selected piece to '' again
main.variables.selectedpiece = '';

$('#turn').html("It's Whites Turn");

$('#turn').addClass('turnhighlight');
window.setTimeout(function(){
$('#turn').removeClass('turnhighlight');
}, 1500);

},

togglehighlight: function(options) {
options.forEach(function(element, index, array) {
$('#' + element).toggleClass("green shake-little
neongreen_txt");
});
},

}
};

$(document).ready(function() {
main.methods.gamesetup();

$('.gamecell').click(function(e) {

var selectedpiece = {
name: '',
id: main.variables.selectedpiece
};

if (main.variables.selectedpiece == ''){
selectedpiece.name = $('#' + e.target.id).attr('chess');
} else {
selectedpiece.name = $('#' +
main.variables.selectedpiece).attr('chess');
}

var target = {
name: $(this).attr('chess'),
id: e.target.id
};
if (main.variables.selectedpiece == '' &&
target.name.slice(0,1) == main.variables.turn) { // show
options

// moveoptions
main.variables.selectedpiece = e.target.id;
main.methods.moveoptions($(this).attr('chess'));

} else if (main.variables.selectedpiece !='' &&


target.name == 'null') { // move selected piece piece

if (selectedpiece.name == 'w_king' || selectedpiece.name


== 'b_king'){

let t0 = (selectedpiece.name = 'w_king');


let t1 = (selectedpiece.name = 'b_king');
let t2 =
(main.variables.pieces[selectedpiece.name].moved == false);
let t3 = (main.variables.pieces['b_rook2'].moved ==
false);
let t4 = (main.variables.pieces['w_rook2'].moved ==
false);
let t5 = (target.id == '7_8');
let t6 = (target.id == '7_1');

if (t0 && t2 && t4 &&t6){ // castle w_king

let k_position = '5_1';


let k_target = '7_1';
let r_position = '8_1';
let r_target = '6_1';

main.variables.pieces['w_king'].position = '7_1';
main.variables.pieces['w_king'].moved = true;
$('#'+k_position).html('');
$('#'+k_position).attr('chess','null');
$
('#'+k_target).html(main.variables.pieces['w_king'].img);
$('#'+k_target).attr('chess','w_king');

main.variables.pieces['w_rook2'].position = '6_1';
main.variables.pieces['w_rook2'].moved = true;
$('#'+r_position).html('');
$('#'+r_position).attr('chess','null');
$
('#'+r_target).html(main.variables.pieces['w_rook2'].img);
$('#'+r_target).attr('chess','w_rook2');

main.methods.endturn();

} else if (t1 && t2 && t3 && t5){ // castle b_king

let k_position = '5_8';


let k_target = '7_8';
let r_position = '8_8';
let r_target = '6_8';
// w_king
main.variables.pieces['b_king'].position = '7_8';
main.variables.pieces['b_king'].moved = true;
$('#'+k_position).html('');
$('#'+k_position).attr('chess','null');
$
('#'+k_target).html(main.variables.pieces['b_king'].img);
$('#'+k_target).attr('chess','b_king');

main.variables.pieces['b_rook2'].position = '6_8';
main.variables.pieces['b_rook2'].moved = true;
$('#'+r_position).html('');
$('#'+r_position).attr('chess','null');
$
('#'+r_target).html(main.variables.pieces['b_rook2'].img);
$('#'+r_target).attr('chess','b_rook2');

main.methods.endturn();

} else { // move selectedpiece


main.methods.move(target);
main.methods.endturn();
}

} else { // else if selecedpiece.name is not white/black


king than move
main.methods.move(target);
main.methods.endturn();

} else if (main.variables.selectedpiece !='' &&


target.name != 'null' && target.id != selectedpiece.id &&
selectedpiece.name.slice(0,1) != target.name.slice(0,1)){ //
capture a piece

if (selectedpiece.id != target.id &&


main.variables.highlighted.indexOf(target.id) != (-1)) { //
if it's not trying to capture pieces not in its movement
range

// capture
main.methods.capture(target)
main.methods.endturn();

} else if (main.variables.selectedpiece !='' &&


target.name != 'null' && target.id != selectedpiece.id &&
selectedpiece.name.slice(0,1) == target.name.slice(0,1)){ //
toggle move options

// toggle
main.methods.togglehighlight(main.variables.highlighted);
main.variables.highlighted.length = 0;

main.variables.selectedpiece = target.id;
main.methods.moveoptions(target.name);

});

$('body').contextmenu(function(e) {
e.preventDefault();
});

});
CHESS GAME
RAMANDEEP

Institute of Technology Management, Murthal (Sonipat)

ABSTRACT- “CHESS GAME” is a game based project on Chess engine.


Generally, chess is a two player game where each player strives to win on
their individual sides. And making with user friendly interface is the ’s
main theme. And implementing the maximum rules for individual chess
piece by mathematical way using co-ordinates concept in geometry.

Keywords: - html,css and javascript

development method.
1. INTRODUCTION: Before developing the tool

The objective of this project is it's necessary to see the

to create a own Chess engine time issue, economy and

which is user friendly and also company strength. Once

to make user comfortable. And these items are happy, then

this project is a two player consecutive step is to see

game. And prediction for game that OS and language may

winner is to display for every be used for developing the

move. tool.
 Once the programmers
begin building the tool the

2. LITERATURE SURVEY: programmers need ton of


external support. This

 Literature survey is that the support are obtained from

most significant step in code senior programmers, from


book or from websites. system the project would
 Before building the system need, and what area unit all
the on prime of thought unit the required software
taken into thought for package area unit required
developing the planned to proceed with consecutive
system. the main half of the step like developing the
project development sector tools, and also the
considers and totally survey associated operations.
all the desired desires for
developing the project. for
each project Literature
survey is that the most
significant sector in code
development method.
 Before developing the tools
and therefore theassociated
coming up with it's necessary
to work out and survey the
time issue, resource demand,
man power, economy, and
company strength.
 Once these items area unit
glad and absolutely surveyed,
then consecutive step is to
see concerning the software
package specifications within
the individual system like
what form of software
2.1 SCOPE OF THE PROJECT: This system is proposed with
certain features which makes
The scope of the project is as follows:
user to feel comfortable.

Scope of this project is to make a  The proposed system is a


own chess engine which is engine whichcandetect
customizable like to implement whether the present move is
the rules like castling in the game. right orwrong.
And to make game is for
 Checks the each and every
entertainment purpose. To
move is going tobe the part of
provide a friendly environment
winning prediction of
where user can improve game
theplayer.
skills with more interest.
 Notifications like player
moves and taken
opponent‟s chess piece is
2.2 EXISTING SYSTEM:
displayed.
In the present scenario, python
 Illegal moves are not
has its module called chess
considered and given chance
which can do all the operations
to make a perfect move.
on the chess moves. But
graphically its not. And it is the  Understandable code for
most used module for the chess everyone becauseofco-
game and for chess stud1 ordinates geometry concept.
purpose.

2.3 PROPOSED SYSTEM:


3. SYSTEM ARCHITECTURE:

Fig 2: System
Architecture

Fig 1: Proposed
System Figure 1

ADVANTAGES OF
PROPOSED SYSTEM:

 User friendly interface.

 Illegal move filteration.

 Winner Prediction for every


step.

 Understandable code for


someone who wants to
stud1 it.

 Winner declaration.
4. MODULE DESCRIPTION: made with window size of (512
px,512 px).
Project Modules:

 Game Intro Module


 User Input module
 Step Validation
module
 Game Updation
module
 Winner deaclaration
module

I. Game Intro Module:


II. Step Validation module:
User Input module is used to
This module provides signal
ensure the event of every
whether the move isvalid/legal
mouse is not for the chess
or not. And in this module
piece movement. And it
there aremultiple signals given
captures the coordinates
for the input move. There are
whenever it selects on the
totally 4 types of signals / flags
chess board and sends the
. They are :-
coordinates for the
validation, to check 5. Signal 0:
whether it‟s a legal move
or not. And this project is This signal is for to indicate
the input move / step is not valid
/ legal. And also if the player
unwantedly selects the
opponent‟s chess piece it
generates a signal 0 and
displays the message that
“wrong move”. This signal is for chess
piece whether the player1
piece captured or taken the
opponents piece. If this
condition is true then system
generates a message like “
[player1 piece] killed [player2
piece]”.

8. Signal 22:

6. Signal 1: This
signal is for
chess piece
whether the
player1 piece
is perfectly
captured the
opponent‟s
king. If it

This interaction of
signal is for any chess
the chess piece in its
piece whether way. If it can
it can move to made the
its destination destination,
with no then signal is
generated 7. Signal 11:
and message
is generated
that it made
a safe move.
board. So that it can move
chess piece in the code and
display over the window.

III. Game Updation Module:

This module is used update the


chess board which is used to
display current state of board
for every move. There will be
done two things.

 Either to swap the


piece withemptysquare.

 Or two replace the


opponents piecewith the
players piece.

IV. Winner declaration module:

This module is used to fetch the


game all the time to check
whether the opponent‟s king is
been captured or not. If yes,
then game is closed and
displays the message like
“[winning player‟s name] win”
5. RESULTS:

By checking all the possible


cases to run the chess engine.
This project running
successfully without any flaws.
And also can be done in
advanced way.

6. CONCLUSION:

is a chess game with more


benefits. Firstly, its more
benefitable for the ones who
wants and tries to stud1 the
code and logic behind the
code. And its GUI programming
of the pygame is more flexible
than the “Ktinker module” for
gaming interface.

REFERENCES:

[1] Co-ordinates concept in geometry.

[2] Mathematical logics on co-ordinates.

You might also like