SlideShare ist ein Scribd-Unternehmen logo
1 von 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…

Weitere ähnliche Inhalte

Was ist angesagt?

College Management System project
College Management System projectCollege Management System project
College Management System projectManish Kushwaha
 
Artificial Intelligence Notes Unit 1
Artificial Intelligence Notes Unit 1 Artificial Intelligence Notes Unit 1
Artificial Intelligence Notes Unit 1 DigiGurukul
 
Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.Alamgir Hossain
 
python project ppt.pptx
python project ppt.pptxpython project ppt.pptx
python project ppt.pptxAkshatGoswami3
 
Final project report of a game
Final project report of a gameFinal project report of a game
Final project report of a gameNadia Nahar
 
CSE Final Year Project Presentation on Android Application
CSE Final Year Project Presentation on Android ApplicationCSE Final Year Project Presentation on Android Application
CSE Final Year Project Presentation on Android ApplicationAhammad Karim
 
Variants of Turing Machine
Variants of Turing MachineVariants of Turing Machine
Variants of Turing MachineRajendran
 
Window to viewport transformation
Window to viewport transformationWindow to viewport transformation
Window to viewport transformationAnkit Garg
 
Computer graphics presentation
Computer graphics presentationComputer graphics presentation
Computer graphics presentationLOKENDRA PRAJAPATI
 
Raster scan and random scan
Raster scan and random scanRaster scan and random scan
Raster scan and random scanKABILESH RAMAR
 
Snake project report
Snake project reportSnake project report
Snake project reportManju Rajput
 
Java Guessing Game Number Tutorial
Java Guessing Game Number TutorialJava Guessing Game Number Tutorial
Java Guessing Game Number TutorialOXUS 20
 
Online Food Ordering System
Online Food Ordering SystemOnline Food Ordering System
Online Food Ordering SystemAnkita Jangir
 
Hill climbing algorithm in artificial intelligence
Hill climbing algorithm in artificial intelligenceHill climbing algorithm in artificial intelligence
Hill climbing algorithm in artificial intelligencesandeep54552
 
e-commerce web development project report (Bookz report)
e-commerce web development project report (Bookz report)e-commerce web development project report (Bookz report)
e-commerce web development project report (Bookz report)Mudasir Ahmad Bhat
 

Was ist angesagt? (20)

College Management System project
College Management System projectCollege Management System project
College Management System project
 
Artificial Intelligence Notes Unit 1
Artificial Intelligence Notes Unit 1 Artificial Intelligence Notes Unit 1
Artificial Intelligence Notes Unit 1
 
Tic tac toe simple ai game
Tic tac toe simple ai gameTic tac toe simple ai game
Tic tac toe simple ai game
 
Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.
 
python project ppt.pptx
python project ppt.pptxpython project ppt.pptx
python project ppt.pptx
 
Final project report of a game
Final project report of a gameFinal project report of a game
Final project report of a game
 
Computer graphics color models
Computer graphics    color modelsComputer graphics    color models
Computer graphics color models
 
CSE Final Year Project Presentation on Android Application
CSE Final Year Project Presentation on Android ApplicationCSE Final Year Project Presentation on Android Application
CSE Final Year Project Presentation on Android Application
 
Variants of Turing Machine
Variants of Turing MachineVariants of Turing Machine
Variants of Turing Machine
 
Window to viewport transformation
Window to viewport transformationWindow to viewport transformation
Window to viewport transformation
 
Computer graphics presentation
Computer graphics presentationComputer graphics presentation
Computer graphics presentation
 
AI 5 | Local Search
AI 5 | Local SearchAI 5 | Local Search
AI 5 | Local Search
 
Raster scan and random scan
Raster scan and random scanRaster scan and random scan
Raster scan and random scan
 
Snake project report
Snake project reportSnake project report
Snake project report
 
Java Guessing Game Number Tutorial
Java Guessing Game Number TutorialJava Guessing Game Number Tutorial
Java Guessing Game Number Tutorial
 
8 queen problem
8 queen problem8 queen problem
8 queen problem
 
Online Food Ordering System
Online Food Ordering SystemOnline Food Ordering System
Online Food Ordering System
 
Hill climbing algorithm in artificial intelligence
Hill climbing algorithm in artificial intelligenceHill climbing algorithm in artificial intelligence
Hill climbing algorithm in artificial intelligence
 
Ai lab manual
Ai lab manualAi lab manual
Ai lab manual
 
e-commerce web development project report (Bookz report)
e-commerce web development project report (Bookz report)e-commerce web development project report (Bookz report)
e-commerce web development project report (Bookz report)
 

Ähnlich wie Play Tic-Tac-Toe

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
 
Tic tac toe on c++ project
Tic tac toe on c++ projectTic tac toe on c++ project
Tic tac toe on c++ projectUtkarsh Aggarwal
 
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
 

Ähnlich wie Play Tic-Tac-Toe (20)

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
 
Tic tac toe on c++ project
Tic tac toe on c++ projectTic tac toe on c++ project
Tic tac toe on c++ project
 
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
 

Kürzlich hochgeladen

APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 

Kürzlich hochgeladen (20)

APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 

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.