SlideShare uma empresa Scribd logo
1 de 37
Android Application
TIC -TAC-TOE
Made By:-
Sarthak Srivastava
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
Yes
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.
How to set up Ads in an Application?
• Add Google Play Services Sdk in
your Project
• Create an Admob account.
• Get a publisher ID.
• Select the ad format you want in
your app
1. Horizontal Banner Ads
2. Interstitial Ads.
• The Ad unit id will be
generated.
• Add the Ad unit ID to your xml
file.
Banner Ad
Single Player Game:Human vs Android
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.
Download On…

Mais conteúdo relacionado

Mais procurados (20)

Adversarial search
Adversarial searchAdversarial search
Adversarial search
 
Tic tac toe
Tic tac toeTic tac toe
Tic tac toe
 
Tic tac toe simple ai game
Tic tac toe simple ai gameTic tac toe simple ai game
Tic tac toe simple ai game
 
Tic Tac Toe
Tic Tac ToeTic Tac Toe
Tic Tac Toe
 
Game Tree ( Oyun Ağaçları )
Game Tree ( Oyun Ağaçları )Game Tree ( Oyun Ağaçları )
Game Tree ( Oyun Ağaçları )
 
Tic Tac Toe Project
Tic Tac Toe Project Tic Tac Toe Project
Tic Tac Toe Project
 
Tic toc game presentation
Tic toc game presentationTic toc game presentation
Tic toc game presentation
 
Adversarial Search
Adversarial SearchAdversarial Search
Adversarial Search
 
Minimax
MinimaxMinimax
Minimax
 
Minimax
MinimaxMinimax
Minimax
 
Fragment
Fragment Fragment
Fragment
 
snake game
snake gamesnake game
snake game
 
Tic tac toe on c++ project
Tic tac toe on c++ projectTic tac toe on c++ project
Tic tac toe on c++ project
 
Introduction to ns2
Introduction to ns2Introduction to ns2
Introduction to ns2
 
Adversarial search
Adversarial search Adversarial search
Adversarial search
 
Web Security
Web SecurityWeb Security
Web Security
 
Tic tac toe c++ programing
Tic tac toe c++ programingTic tac toe c++ programing
Tic tac toe c++ programing
 
GamingAnywhere: An Open Cloud Gaming System
GamingAnywhere: An Open Cloud Gaming SystemGamingAnywhere: An Open Cloud Gaming System
GamingAnywhere: An Open Cloud Gaming System
 
Ch 19 Network-layer protocols Section 1
Ch 19  Network-layer protocols Section 1Ch 19  Network-layer protocols Section 1
Ch 19 Network-layer protocols Section 1
 
Hangman game is interesting
Hangman game is interesting Hangman game is interesting
Hangman game is interesting
 

Semelhante a Play Tic-Tac-Toe

AI based Tic Tac Toe game using Minimax Algorithm
AI based Tic Tac Toe game using Minimax AlgorithmAI based Tic Tac Toe game using Minimax Algorithm
AI based Tic Tac Toe game using Minimax AlgorithmKiran Shahi
 
Build tic tac toe with javascript (3:28)
Build tic tac toe with javascript (3:28)Build tic tac toe with javascript (3:28)
Build tic tac toe with javascript (3:28)Thinkful
 
Agent tic tac-toe - an interactive game for computational thinking
Agent tic tac-toe - an interactive game for computational thinkingAgent tic tac-toe - an interactive game for computational thinking
Agent tic tac-toe - an interactive game for computational thinkingLorennRuster
 
Artificial intelligence - python
Artificial intelligence - pythonArtificial intelligence - python
Artificial intelligence - pythonSunjid Hasan
 
#include iostream#include fstream#include Opening.h.docx
#include iostream#include fstream#include Opening.h.docx#include iostream#include fstream#include Opening.h.docx
#include iostream#include fstream#include Opening.h.docxadkinspaige22
 
The Role of Shologuti in Artificial Intelligence Research: A Rural Game of Ba...
The Role of Shologuti in Artificial Intelligence Research: A Rural Game of Ba...The Role of Shologuti in Artificial Intelligence Research: A Rural Game of Ba...
The Role of Shologuti in Artificial Intelligence Research: A Rural Game of Ba...IJCSIS Research Publications
 
98 374 Lesson 06-slides
98 374 Lesson 06-slides98 374 Lesson 06-slides
98 374 Lesson 06-slidesTracie King
 
ma project
ma projectma project
ma projectAisu
 
An analysis of minimax search and endgame databases in evolving awale game pl...
An analysis of minimax search and endgame databases in evolving awale game pl...An analysis of minimax search and endgame databases in evolving awale game pl...
An analysis of minimax search and endgame databases in evolving awale game pl...csandit
 
AN ANALYSIS OF MINIMAX SEARCH AND ENDGAME DATABASES IN EVOLVING AWALE GAME PL...
AN ANALYSIS OF MINIMAX SEARCH AND ENDGAME DATABASES IN EVOLVING AWALE GAME PL...AN ANALYSIS OF MINIMAX SEARCH AND ENDGAME DATABASES IN EVOLVING AWALE GAME PL...
AN ANALYSIS OF MINIMAX SEARCH AND ENDGAME DATABASES IN EVOLVING AWALE GAME PL...cscpconf
 
Intelligent Heuristics for the Game Isolation
Intelligent Heuristics  for the Game IsolationIntelligent Heuristics  for the Game Isolation
Intelligent Heuristics for the Game IsolationKory Becker
 
This is an individual project, to be completed on your own. It i.docx
This is an individual project, to be completed on your own. It i.docxThis is an individual project, to be completed on your own. It i.docx
This is an individual project, to be completed on your own. It i.docxabhi353063
 
Enterprise Tic-Tac-Toe
Enterprise Tic-Tac-ToeEnterprise Tic-Tac-Toe
Enterprise Tic-Tac-ToeScott Wlaschin
 
Python programming
Python programmingPython programming
Python programmingsaroja20
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithmK Hari Shankar
 
Introduction to Alphago Zero
Introduction to Alphago ZeroIntroduction to Alphago Zero
Introduction to Alphago ZeroChia-Ching Lin
 
Build tic tac toe with javascript (4:11 dc)
Build tic tac toe with javascript (4:11 dc)Build tic tac toe with javascript (4:11 dc)
Build tic tac toe with javascript (4:11 dc)Daniel Friedman
 
International journal of engineering issues vol 2015 - no 2 - paper1
International journal of engineering issues   vol 2015 - no 2 - paper1International journal of engineering issues   vol 2015 - no 2 - paper1
International journal of engineering issues vol 2015 - no 2 - paper1sophiabelthome
 
Cse 402 offline b2
Cse 402 offline b2Cse 402 offline b2
Cse 402 offline b2sujoyhnkc
 

Semelhante a Play Tic-Tac-Toe (20)

AI based Tic Tac Toe game using Minimax Algorithm
AI based Tic Tac Toe game using Minimax AlgorithmAI based Tic Tac Toe game using Minimax Algorithm
AI based Tic Tac Toe game using Minimax Algorithm
 
tic-tac-toe: Game playing
 tic-tac-toe: Game playing tic-tac-toe: Game playing
tic-tac-toe: Game playing
 
Build tic tac toe with javascript (3:28)
Build tic tac toe with javascript (3:28)Build tic tac toe with javascript (3:28)
Build tic tac toe with javascript (3:28)
 
Agent tic tac-toe - an interactive game for computational thinking
Agent tic tac-toe - an interactive game for computational thinkingAgent tic tac-toe - an interactive game for computational thinking
Agent tic tac-toe - an interactive game for computational thinking
 
Artificial intelligence - python
Artificial intelligence - pythonArtificial intelligence - python
Artificial intelligence - python
 
#include iostream#include fstream#include Opening.h.docx
#include iostream#include fstream#include Opening.h.docx#include iostream#include fstream#include Opening.h.docx
#include iostream#include fstream#include Opening.h.docx
 
The Role of Shologuti in Artificial Intelligence Research: A Rural Game of Ba...
The Role of Shologuti in Artificial Intelligence Research: A Rural Game of Ba...The Role of Shologuti in Artificial Intelligence Research: A Rural Game of Ba...
The Role of Shologuti in Artificial Intelligence Research: A Rural Game of Ba...
 
98 374 Lesson 06-slides
98 374 Lesson 06-slides98 374 Lesson 06-slides
98 374 Lesson 06-slides
 
ma project
ma projectma project
ma project
 
An analysis of minimax search and endgame databases in evolving awale game pl...
An analysis of minimax search and endgame databases in evolving awale game pl...An analysis of minimax search and endgame databases in evolving awale game pl...
An analysis of minimax search and endgame databases in evolving awale game pl...
 
AN ANALYSIS OF MINIMAX SEARCH AND ENDGAME DATABASES IN EVOLVING AWALE GAME PL...
AN ANALYSIS OF MINIMAX SEARCH AND ENDGAME DATABASES IN EVOLVING AWALE GAME PL...AN ANALYSIS OF MINIMAX SEARCH AND ENDGAME DATABASES IN EVOLVING AWALE GAME PL...
AN ANALYSIS OF MINIMAX SEARCH AND ENDGAME DATABASES IN EVOLVING AWALE GAME PL...
 
Intelligent Heuristics for the Game Isolation
Intelligent Heuristics  for the Game IsolationIntelligent Heuristics  for the Game Isolation
Intelligent Heuristics for the Game Isolation
 
This is an individual project, to be completed on your own. It i.docx
This is an individual project, to be completed on your own. It i.docxThis is an individual project, to be completed on your own. It i.docx
This is an individual project, to be completed on your own. It i.docx
 
Enterprise Tic-Tac-Toe
Enterprise Tic-Tac-ToeEnterprise Tic-Tac-Toe
Enterprise Tic-Tac-Toe
 
Python programming
Python programmingPython programming
Python programming
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithm
 
Introduction to Alphago Zero
Introduction to Alphago ZeroIntroduction to Alphago Zero
Introduction to Alphago Zero
 
Build tic tac toe with javascript (4:11 dc)
Build tic tac toe with javascript (4:11 dc)Build tic tac toe with javascript (4:11 dc)
Build tic tac toe with javascript (4:11 dc)
 
International journal of engineering issues vol 2015 - no 2 - paper1
International journal of engineering issues   vol 2015 - no 2 - paper1International journal of engineering issues   vol 2015 - no 2 - paper1
International journal of engineering issues vol 2015 - no 2 - paper1
 
Cse 402 offline b2
Cse 402 offline b2Cse 402 offline b2
Cse 402 offline b2
 

Último

Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Configuration of IoT devices - Systems managament
Configuration of IoT devices - Systems managamentConfiguration of IoT devices - Systems managament
Configuration of IoT devices - Systems managamentBharaniDharan195623
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
"Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ..."Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ...Erbil Polytechnic University
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Crushers to screens in aggregate production
Crushers to screens in aggregate productionCrushers to screens in aggregate production
Crushers to screens in aggregate productionChinnuNinan
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfRajuKanojiya4
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxVelmuruganTECE
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
BSNL Internship Training presentation.pptx
BSNL Internship Training presentation.pptxBSNL Internship Training presentation.pptx
BSNL Internship Training presentation.pptxNiranjanYadav41
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxRomil Mishra
 
11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdf11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdfHafizMudaserAhmad
 
multiple access in wireless communication
multiple access in wireless communicationmultiple access in wireless communication
multiple access in wireless communicationpanditadesh123
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Autonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.pptAutonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.pptbibisarnayak0
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - GuideGOPINATHS437943
 

Último (20)

Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Configuration of IoT devices - Systems managament
Configuration of IoT devices - Systems managamentConfiguration of IoT devices - Systems managament
Configuration of IoT devices - Systems managament
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
"Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ..."Exploring the Essential Functions and Design Considerations of Spillways in ...
"Exploring the Essential Functions and Design Considerations of Spillways in ...
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
Crushers to screens in aggregate production
Crushers to screens in aggregate productionCrushers to screens in aggregate production
Crushers to screens in aggregate production
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdf
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptx
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
BSNL Internship Training presentation.pptx
BSNL Internship Training presentation.pptxBSNL Internship Training presentation.pptx
BSNL Internship Training presentation.pptx
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
 
11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdf11. Properties of Liquid Fuels in Energy Engineering.pdf
11. Properties of Liquid Fuels in Energy Engineering.pdf
 
multiple access in wireless communication
multiple access in wireless communicationmultiple access in wireless communication
multiple access in wireless communication
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Autonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.pptAutonomous emergency braking system (aeb) ppt.ppt
Autonomous emergency braking system (aeb) ppt.ppt
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Designing pile caps according to ACI 318-19.pptx
Designing pile caps according to ACI 318-19.pptxDesigning pile caps according to ACI 318-19.pptx
Designing pile caps according to ACI 318-19.pptx
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - Guide
 

Play Tic-Tac-Toe

  • 1. Android Application TIC -TAC-TOE Made By:- Sarthak Srivastava
  • 2. 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.
  • 3. 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
  • 4. 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.
  • 5. 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).
  • 6. 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)
  • 7. 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.
  • 8. 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
  • 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.
  • 10. 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.
  • 11. 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
  • 12. 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)
  • 13. 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.
  • 14. • 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
  • 15. 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.
  • 16. 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.
  • 18. 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.
  • 19. 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.
  • 20. 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
  • 21. 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
  • 22. 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
  • 23. 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>
  • 24. 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;
  • 25. 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 Yes
  • 26. 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
  • 27. 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.
  • 28. 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.
  • 29. 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).
  • 30. 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()
  • 31. 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.
  • 32. How to set up Ads in an Application? • Add Google Play Services Sdk in your Project • Create an Admob account. • Get a publisher ID. • Select the ad format you want in your app 1. Horizontal Banner Ads 2. Interstitial Ads. • The Ad unit id will be generated. • Add the Ad unit ID to your xml file. Banner Ad
  • 34. 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.
  • 35. 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.
  • 36. 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.