0% found this document useful (0 votes)
463 views21 pages

Data Report of Tic Tac Toe Game

The document summarizes a project report on developing a Tic-Tac-Toe game for Android. It describes the game of Tic-Tac-Toe and algorithms used for the computer player. The project was completed by Geetanjali Gupta for their BCA degree under the guidance of Kewal Dewangan. It includes certificates of approval, evaluation, and acknowledgments. The technologies used were Android SDK, Java, and XML for the Android interface.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
463 views21 pages

Data Report of Tic Tac Toe Game

The document summarizes a project report on developing a Tic-Tac-Toe game for Android. It describes the game of Tic-Tac-Toe and algorithms used for the computer player. The project was completed by Geetanjali Gupta for their BCA degree under the guidance of Kewal Dewangan. It includes certificates of approval, evaluation, and acknowledgments. The technologies used were Android SDK, Java, and XML for the Android interface.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

A

PROJECT Report
OF
TIC-TAC-TOE GAME
Bachelor of Computer Application
From
Govt. Digvijay Automous PG College Rajnandgaon(C.G.)

Year:-2020-21

Guided by Submitted by

KEWAL DEWANGAN GEETANJALI GUPTA


SUBMITTED TO

Hemchand Yadav Vishwavidyalaya,Durg (C.G.)


CERTIFICATE OF APPROVAL

This is certify that this project entitled “TIC-TAC-TOE GAME” is

carried out by Geetanjali Gupta, a student of BCA-III year at Govt.

digvijay Automous PG college is hereby approved as a credible work in

the discipline of computer Science & Information of Technology for the

award of degree of Bachelor of Computer Application during the year

2019-2020 from Hemchand Yadav Vishwavidyalaya, Durg(CG).

HOD (CS Department)


Certificate

This is to certify that the project work entitled “TIC-TAC-TOE GAME”

submitted to the Govt. digvijay Automous PG college by Geetanjali

Gupta Roll no. , in partial fulfillment for the requirement relating to

nature and standard of the award of Bachelor of Computer Application

degree by Hemchand Yadav Vishwavidyalaya, Durg(CG) for the

adamic year 2019-2020.

This project work has been carried out under my guidance.

Guide Name
KEWAL DEWANGAN
Certificate of evaluation

This is to certify that the project report entitled “TIC-TAC-TOE

GAME” is carried out by Geetanjali gupta , a student of BCA-III

year at Govt. Digvijay Automous PG College Rajnandgaon(C.G.), after

proper evalution and examination, is hereby approved as a credible work

in the discipline of Computer Science & Information Technology and is

done in a satisfactory manner for its acceptance as a requsite for the

award of degree of Bachelor of Computer Application durning the year

2019-2020 from Hemchand Yadav Vishwavidyalaya, Durg(CG)

INTERNAL EXAMINER EXTERNAL EXAMINER


SELF CERTIFICATE

This is to certify that this project entitled “TIC-TAC-TOE

GAME” is done by me is an authentic work carried out for the partial

fulfillment of the requirements for the award of the degree of BCA

(Final Year) under the guidance of “KEWAL DEWANGAN”. The

matter embodied in this project work has not been submitted earlier for

award of any degree or diploma to the best of my knowledge and belief.

Name:- Geetanjali Gupta

Roll No:
ACKNOWLEDGEMENT

I feel very privileged to express our profound sense of our respect

and gratitude to our project guide “KEWAL DEWANGAN”for my

project report on “TIC-TAC-TOE GAME”.

All faculty incredible help and valuable suggestion efforts and

constructive guidance made the project an interesting task, their

optimistic attitude, guidance of appreciation was such as to give impetus

to our thoughts and understanding making us believe that all that was of

our own efforts for which for we well ever our remain indebted to them.

Finally I would like to thank my friends for their cooperation to

complete this project.

SUBMITTED BY

Geetanjali gupta
What is AI?

• It is an field of study which studies the goal of creating intelligence.


• The central problems (or goals) of AI research include reasoning,
knowledge, planning, learning nat ural language processing
(communication) and the ability to move and manipulate objects.
• There are a large number of tools used in AI, including versions of
search and mathematical optimization, logic, method based on
probability and economics, and many others.

Fields in which AI is used


• Medical diagnosis
• Speech recognition
• Stock trading
• Robot control law
• Remote sensing
• Scientific discovery
• Games like tic tac toe and chess

Tic Tac Toe Board-(Noughts and Crosses or X’s and O’s)

• It is two players, X and O, game who take turns marking the


spaces in a 3×3 grid. The player who succeeds in placing three
respective marks in a horizontal, vertical, or diagonal row wins the
game.

About the game


• Naive counting leads to 19,683 possible board layouts (39since
each of the nine spaces can be X, O or blank), and 362,880 (i.e. 9!)
possible games (different sequences for placing the Xs and Os on
the board).
• The game ends when three-in-a-row is obtained.
• The number of Xs is always either equal to or exactly 1 more
than the number of Os (if X starts).

Strategy

• Win: If the player has two in a row, they can place a third to get
three in a row.
• Block: If the opponent has two in a row, the player must play
the third themselves to block the opponent.
• Fork: Create an opportunity where the player has two threats to
win (two non-blocked lines of 2)

Strategy : Rule Based For Tic-tac-toe, the rules, in the order


of importance, are:

• Rule 1: If I have a winning move, take it.


• Rule 2: If the opponent has a winning move, block it
• Rule 3: If I can create a fork (two winning ways) after this move,
do it.
• Rule 4: Do not let the opponent creating a fork after my move.
(Opponent may block your winning move and create a fork.)
• Rule 5: Place in the position such as I may win in the most
number of possible ways.
• Rule 1 and 2 can be programmed easily. Rule 3 is harder. Rule
4 is even harder because you need to lookahead one opponent
move, after your move. For rule 5, you need to count the number
of possible winning ways.

Algorithm Data Structure Board A nine-element vector


representing the board, as shown below. But instead of using the
numbers 0, 1 or 2 in each element, we store 2 (indicating blank),
3(indicating X) or 5(indicating O). Turn An integer indicating which
move of the game is about to be played; 1 indicates the first move,
9 the last. 1 2 3 4 5 6 7 8 9

Algorithm The main algorithm uses three sub procedures:

• Make 2: Return O if the center square of the board is blank, that


is, if Board[5]= 2.otherwise, this function return blank non-corner
square(2,4,6 or 8).
• Posswin(p) :Return O if player p cannot win on his next move;
otherwise, it returns the number of square that constitutes a
winning move. This function will enable the program both the win
and to block the opponent’s win. Posswin operates by checking,
one at a time, each of rows, columns and diagonals. Because of
the way values a number it can test a entire row,(column or
diagonal) to see if it is a possible win by multiplying the value of its
squares. If the product is 18(3x3x2), then X can win. If the product
is 50(5x5x2), then O can win. If we find a winning row we
determine which element is blank and return the number of that
square.
• Go(n) : Makes a move in square n. This procedure sets board[n]
to 3 if turn is odd, or 5 if turn is even. It also increments turn by 1.

Algorithm

• The algorithm has built in strategy for each move it may have to
make. It makes the odd numbered moves if it is playing X, the
even numbered moves if it is playing O. The strategy for each turn
is as follows:
• Turn 1 Go(1)(under left corner).
• Turn 2 If Board[5] is blank, Go(5),else Go(1).
• Turn 3 If Board[5] is blank, Go(9),else Go(3).
• Turn 4 If Posswin(X) is not 0, then Go(Posswin(X))[i.e.,block
opponent’s win], else Go(Make2).
• Turn 5 If Posswin(X) is not 0, then Go(Posswin(X))[i.e.,win] else
if Posswin(O) is not 0, then Go(Posswin(O)) [i.e.,win], else if
Board[7] is blank, then Go(7), else Go(3). • [Here the program is
trying to make fork.]
• Turn 6 If Posswin(O) is not 0, then Go(Posswin(O)), else if
Posswin(X) is not 0,then Go(Posswin(X)),else Go(Make2).
• Turn 7 If Posswin(X) is not 0, then Go(Posswin(X)), else if
Posswin(O) is not 0,then Go(Posswin(O)),else go anywhere that is
blank.
• Turn 8 If Posswin(O) is not O, then Go(Posswin(O)), else if
Posswin(X) is not 0,then Go(Posswin(X)),else go anywhere that is
blank.
• Turn 9 Same as Turn 7.

Block Diagram for Single Player game Main Menu One Player
Two Player Start Game Exit game Exit Game Players Turn
Computer’s Turn Get player moves Get Android moves Check if
player 1 won Check if player 2 won If it’s a tie New/End Game Yes
Yes No No Yes

Technologies Used

• Platform: Android OS • IDE : Eclipse with ADT v23.2.1 (Android


Development kit)
• Server Side : Java(jdk 1.8)
• Client side :Android xml
• Project Build Target: Android 5.0.1 (API 21)
Android Application Development

• Android is a mobile operating system (OS) based on the Linux


kernel and currently developed by Google. With a user interface
based on direct manipulation.
• Android is made up of several necessary and dependent parts
including the following:
• A hardware reference design that describes the capabilities
required of a mobile device in order to support the software stack.
• A Linux operating system kernel that provides the low-level
interface with the hardware, memory management, and process
control, all optimized for mobile devices.
• Open source libraries for application development including
SQLite, WebKit, OpenGL, and a media manager.
• A run time used to execute and host Android applications,
including the Dalvik virtual machine and the core libraries that
provide Android specific functionality. The run time is designed to
be small and efficient for use on mobile devices.

Android software development kit (SDK) includes Android APIs,


Development Tools, Android Emulator, full documentation, sample
code, online support.
• A user interface framework used to host and launch applications.
• Preinstalled applications shipped as part of the stack. Android
Application Development

What makes an Android App?


1. Activities :Your Applications presentations layer.The UI of your
application is built around one or more extensions of the Activity
class.
2. Services: “Working in the background”.Services components
run without a UI,updating your data sources and Activities.
3. Content Poviders: manage and persisit data and typically
interact with SQL database.
4. Intents: message pass framework,work for the joining of 2
Activities.
5.Android Manifest.xml

• All the android applications will have an AndroidManifest.xml file


in the root directory. This file will contain essential information
about the application to the Android system.
• This control file describes the nature of the application and each
of its components.
• Permissions to services are granted through Android Manifest
file.
• Ex : Services like Network Services.

Setting the Android Project

Libraries

• appcompat v7 : used for the ActionBar APIs in the support library.


• Google play services : Google Play services provides you with
easy access to Google services and is tightly integrated with the
Android OS.

UI:setting the 3x3 board with buttons

• Table row under table layout is used to arrange childrens


(Buttons)horizontally.
• Push Button widgets are used under <tablerow >to perform an
action and are customised further.

UI:setting up the text view


• Text View:Displays text to the user and optionally allows them to
edit it
• 4 text views used
• Score: shows who’s turn it is ,user or computer,and also shows
the final result.
• Human,tie and android text views show the no. games won by
each

User Interface A table row that consists of 3x3 grid of multiple


customised Buttons Internal Options Menu Text View for Score
card Text view which shows current status Activity Bar
Setting Up a Internal Menu

•Setting up the menu resource defines an application menu


(Options Menu, Context Menu, or submenu) that can be inflated
with MenuInflater.
• Two options :
1. New Game : which starts a new game for the user,however
previous results are recorded.
2. Exit Game : Which exits the user from the game activity to main
menu activity.
• FILE LOCATION:res/menu/filename.xml The filename will be
used as the resource ID.
• RESOURCE REFERENCE:In Java: R.menu.filename In XML:
@[package:]menu.filename

Setting Up a Internal Menu…contd.

• Xml syntax: <menu


xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/newGame"
android:showAsAction="ifRoom“/> </menu>

Internal Options Menu

• To set up working of options menu Menu Inflator class is


imported in the Activity.java
• This class is used to instantiate menu XML files into Menu
objects.
• When the user selects an item from the options menu (including
action items in the action bar), the system calls your activity's
onOptionsItemSelected() method.
• This method passes the MenuItem selected. You can identify
the item by calling getItemId(), which returns the unique ID for the
menu item • You can match this ID against known menu items to
perform the appropriate action. public boolean
onOptionsItemSelected(MenuItem item) { switch (item.getItemId())
{ case R.id.new_game: newGame(); return true;

Block Diagram

for Two Player game Main Menu One Player Two Player New
Game Exit game Exit Game Get player 1 moves Get player2
moves Check if player 1 won Check if player 2 won If it’s a tie
New/End Game Player 1 Turn Player 2 Turn Yes Yes No No Ye
ADMINISTRATION

Provides authentication

GAME

Play with user

PLAYER
Responds to computer

SELECTION
USER USER
PROCESS

Select request for input

Give input WORKING output


PROCESS
New
Game

Player 1

Player 1
moves

Player 2
moves

Player 2

Check for
Display
win
winner
Setting the Two player game: User Interface String in this text
views updates the turn of each player and in the end shows the
result Score Board 3X3 board of buttons

Difference from the single player game!

• In game Activity java file we change the variables from user to


Player_One and Android to Player_two.
• Two more text views are declared in the TictactoeActivity java
file for count of the score.
• The game player_1 and player_2 within a series.
• Rest of the code is nearly the same as the single player game
had.

Setting Up the Main Menu

• Make a new xml file (main_menu.xml) under reslayout folder.


• Drag 3 buttons from widgets section onto the Activity screen and
arrange them vertically.
• 3 butons will be of one player,two player and exit game.

How menu buttons work?

• Create a java file (MainMenuScreen.java)for working of buttons


in main menu under srcpackage folder.
• Set up a MainMenuScreen class which extends Activity class. •
Activities interact with the user, so the Activity class takes care of
creating a window for you in which you can place your UI with
setContentView(R.id.mainmenu); under onCreate(Bundle)
method( where you initialize your activity).
How Menu Buttons Work?..... ((Button)

findViewById(R.id.one_player)).setOnClickListener(new
OnClickListener(){ public void onClick(View V) { Log.d("DEBUG",
"One Player Button Pressed!"); Intent intent = new
Intent(MainMenuScreen.this, TicTacToeTutorialActivity.class);
intent.putExtra("gameType", true); startActivityForResult(intent,
0); } });
1. Interface definition for a callback to be invoked when a view is
clicked
2. Log class ensures that the button was clicked and Log.d sends
the debug output.
3. An Intent provides a facility for performing late runtime binding
between the code in different applications. Its most significant use
is in the launching of activities, where it can be thought of as the
glue between activities.
4. start another activity and receive a result back. To receive a
result, call startActivityForResult()

How the App is Different?

• The player(s) can compete in a series of games and the record


of games are kept under the text views in Android Application.
• The application maintains the scoreboard which keeps the
record of winning record of each player( human player or
computer) and also keeps the record of the number of ties in the
series of games.
What did we learn? Technically

• First of all we gained additional skills in the Java programming


language that was difficult for us before. we learned also how to
use a lot of the components in Eclipse IDE such as the debugger.
I also learned a new language that is XML, a language I didn't
know at all earlier. Finally, this project allowed me to use my logic
development and logic programming skills acquired during my
studies.

Future Work

• In future in Android application development we would like to


learn the OpenGl 2D graphics which can be implements in the
application which will improve the working and presentation of the
application.
• Also we would like to implement a 4x4 board game.

Conclusion

• In the end we would like to conclude that my aim to make this


project was to research in the field of Android Application
development and implementation of Artificial Intelligence by
developing the logic for the game. Some scope of improvements
are also there in the project which will rectified in the future
advancements of the project. We would like to thank all those who
have helped us and contributed in making of this project.

You might also like