Sie sind auf Seite 1von 46

ABSTRACT

The game of Tic-tac-toe is one of the most commonly known games. This game does not allow
one to win all the time and a significant proportion of games played results in a draw. Thus, the
best a player can hope is to not lose the game. This study is aimed at evolving a number of noloss strategies using genetic algorithms and comparing them with existing methodologies. To
efficiently evolve no-loss strategies, we have developed innovative ways of representing and
evaluating a solution, initializing the GA population, developing GA operators including an elite
preserving scheme. Interestingly, our GA implementation is able to find more than 72 thousand
no-loss strategies for
playing the game. Moreover, an analysis of these solutions has given us insights about how to
play the game to not lose it. Based on this experience, we have developed specialized efficient
strategies having a high win-to-draw ratio. The study and its results are interesting and can be
encouraging for the techniques to be applied to other board games for finding efficient strategies.

1 INTRODUCTION
Our project name is Tic-Tac-Toe game. This game is very popular and is
fairly simple by itself. It is actually a two player game. In this game, there is
a board with n x n squares. In our game, it is 3 x 3 squares.
The goal of Tic-Tac-Toe is to be one of the players to get three same
symbols in a row - horizontally, vertically or diagonally - on a 3 x 3 grid..

1.1 PROBLEM STATEMENT


By playing games, the machine intelligence can be
revealed. For knowledge-based methods, the best
move is determined by searching a game tree. For
games such as Checkers, the tree spanning is very
large. Tree searching will be time consuming even

for a few plies. Hence, an efficient searching


algorithm is an important issue. The problems are
solved by forming a possible set of solutions based
on the endgame condition, or searching for the set of
solutions based on the current game condition. The
machine cannot learn to play the games by itself.
Unlike an evolutionary approach was employed to
evolve and to learn for playing Tic-Tac-Toe without
the need of a database. Artificial intelligence (AI) is
the intelligence of machines and the branch
of computer science that aims to create it. Tic-tac-toe
is a pencil-and-paper game for two players, X and O,
who take turns marking the spaces in a 33 grid. The
X player usually goes first. The player who succeeds
in placing three respective marks in a horizontal,
vertical, or diagonal row wins the game

1.2 AIM
Our objective is to evolve several Tic-tac-toe strategies
which never lose (meaning a draw or a win by
the computer). This makes the problem to have a single
objective of minimizing the number of losses. The
evaluation of fitness of any strategy is done by first allowing
it to play all possible games it could play, both
as a first player and as a second player. For example,
note from Figure 5 that there are two possible ways
a game can move for the first player from level 1 to
level 2, depending on whether the opponent made the
left or the right side move . Our
evaluation procedure considers all such intermediate

possibilities an opponent can have and count the total


number of possible games resulting in wins, draws
and losses. This is continued for the above strategy
to be played as the second player. The total number
of games lost in both cases as a first player and
a second player is calculated.

1.3FEASIBILITY STUDY
A feasibility analysis usually involves a thorough assessment of the operational (need), financial
and technical aspects of a proposal. Feasibility study is the test of the system proposal made to
identify whether the user needs may be satisfied using the current software and hardware
technologies, whether the system will be cost effective from a business point of view and
whether it can be developed with the given budgetary constraints. A feasibility study should be
relatively cheap and done at the earliest possible time. Depending on the study, the decision is
made whether to go ahead with a more detailed analysis.
When a new project is proposed, it normally goes through feasibility assessment. Feasibility
study is carried out to determine whether the proposed system is possible to develop with
available resources and what should be the cost consideration. Facts considered in the feasibility
analysis were

Technical Feasibility
Economic Feasibility
Behavioral Feasibility
Technical Feasibility

Technical feasibility includes whether the technology is available in the market for development
and its availability. The assessment of technical feasibility must be based on an outline design of
system requirements in terms of input, output, files, programs and procedures. This can be
qualified in terms of volumes of data, trends, frequency of updating, cycles of activity etc, in
order to give an introduction of technical system. Considering our project it is technical feasible.
Online Recruiting and Online Recruitment Systems, with its emphasis on a more strategic
decision making process is fast gaining ground as a popular outsourced function

Economic Feasibility
This feasibility study present tangible and intangible benefits from the project by comparing the
development and operational cost. The technique of cost benefit analysis is often used as a basis
for assessing economic feasibility. This system needs some more initial investment than the
existing system, but it can be justifiable that it will improve quality of service.
Thus feasibility study should center along the following points:

Improvement resulting over the existing method in terms of accuracy, timeliness.


Cost comparison
Estimate on the life expectancy of the hardware.
Overall objective
Behavioral Feasibility
This analysis involves how it will work when it is installed and the assessment of political and
managerial environment in which it is implemented. People are inherently resistant to change
and computers have been known to facilitate change. The new proposed system is very much
useful to the users and therefore it will accept broad audience from around the world.

2 TECHNOLOGY SURVEY
2.1 Introduction to technology/language
Java is a small, simple, safe, object oriented, interpreted or dynamically optimized, byte coded,
architectural, garbage collected, multithreaded programming language with a strongly typed
exception-handling for writing distributed and dynamically extensible programs.
Java is an object oriented programming language. Java is a high-level, third generation language
like C, FORTRAN, Small talk, Pearl and many others. You can use java to write computer
applications that crunch numbers, process words, play games, store data or do any of the
thousands of other things computer software can do.
Special programs called applets that can be downloaded from the internet and played safely
within a web browser. Java a supports this application and the follow features make it one of the
best programming languages.
It is simple and object oriented
It helps to create user friendly interfaces.
It is very dynamic.
It supports multithreading.
It is platform independent
It is highly secure and robust.
It supports internet programming
Java is a programming language originally developed by Sun Microsystems and released in
1995 as a core component of Sun's Java platform. The language derives much of its syntax from
C and C++ but has a simpler object model and fewer low-level facilities. Java applications are
typically compiled to byte code which can run on any Java virtual machine (JVM) regardless of
computer architecture.

The original and reference implementation Java compilers, virtual machines, and class libraries
were developed by Sun from 1995. As of May 2007, in compliance with the specifications of the
Java Community Process, Sun made available most of their Java technologies as free software
under the GNU General Public License. Others have also developed alternative implementations
of these Sun technologies, such as the GNU Compiler for Java and GNU Class path.
The Java language was created by James Gosling in June 1991 for use in a set top
box project. The language was initially called Oak, after an oak tree that stood outside Gosling's
office - and also went by the name Green - and ended up later being renamed to Java, from a list
of random words. Gosling's goals were to implement a virtual machine and a language that had a
familiar C/C++ style of notation.

Primary goals
There were five primary goals in the creation of the Java language:
1. It should use the object-oriented programming methodology.
2. It should allow the same program to be executed on multiple operating systems.
3. It should contain built-in support for using computer networks.
4. It should be designed to execute code from remote sources securely.
5. It should be easy to use by selecting what were considered the good parts of other objectoriented languages.
The Java platform is the name for a bundle of related programs, or platform, from Sun which
allow for developing and running programs written in the Java programming language. The
platform is not specific to any one processor or operating system, but rather an execution engine
(called a virtual machine) and a compiler with a set of standard libraries which are implemented
for various hardware and operating systems so that Java programs can run identically on all of
them.

Different "editions" of the platform are available, including:

Java ME (Micro Edition): Specifies several different sets of libraries (known as profiles)
for devices which are sufficiently limited that supplying the full set of Java libraries
would take up unacceptably large amounts of storage.

Java SE (Standard Edition): For general purpose use on desktop PCs, servers and similar
devices.

Java EE (Enterprise Edition): Java SE plus various APIs useful for multi-tier client-server
enterprise applications.
The Java Platform consists of several programs, each of which provides a distinct

portion of its overall capabilities. For example, the Java compiler, which converts Java source
code into Java byte code (an intermediate language for the Java Virtual Machine (JVM)), is
provided as part of the Java Development Kit (JDK). The sophisticated Java Runtime
Environment (JRE), complementing the JVM with a just-in-time (JIT) compiler, converts
intermediate byte code into native machine code on the fly. Also supplied are extensive libraries
(pre-compiled into Java byte code) containing reusable code, as well as numerous ways for Java
applications to be deployed, including being embedded in a web page as an applet. There are
several other components, some available only in certain editions.
The essential components in the platform are the Java language compiler, the
libraries, and the runtime environment in which Java intermediate byte code "executes"
according to the rules laid out in the virtual machine specification.

Java Virtual Machine


The heart of the Java Platform is the concept of a "virtual machine" that executes Java byte code
programs. This byte code is the same no matter what hardware or operating system the program
is running under. There is a JIT compiler within the Java Virtual Machine, or JVM. The JIT

compiler translates the Java byte code into native processor instructions at run-time and caches
the native code in memory during execution.
The use of byte code as an intermediate language permits Java programs to
run on any platform that has a virtual machine available. The use of a JIT compiler means that
Java applications, after a short delay during loading and once they have "warmed up" by being
all or mostly JIT-compiled, tend to run about as fast as native programs. Since JRE version 1.2,
Sun's JVM implementation has included a just-in-time compiler instead of an interpreter.
Although Java programs are Platform Independent, the
codes of the Java Virtual Machine (JVM) that execute these programs are not. Every Operating
System has its own JVM.

Class libraries
In most modern operating systems, a large body of reusable code is provided to
simplify the programmer's job. This code is typically provided as a set of dynamically loadable
libraries that applications can call at runtime. Because the Java Platform is not dependent on any
specific operating system, applications cannot rely on any of the existing libraries. Instead, the
Java Platform provides a comprehensive set of standard class libraries, containing much of the
same reusable functions commonly found in modern operating systems.
The Java class libraries serve three purposes within the Java Platform.
Like other standard code libraries, they provide the programmer a well-known set of functions to
perform common tasks, such as maintaining lists of items or performing complex string parsing.
In addition, the class libraries provide an abstract interface to tasks that would normally depend
heavily on the hardware and operating system. Tasks such as network access and file access are
often heavily dependent on the native capabilities of the platform. The Java java.net and java.io
libraries implement the required native code internally, then provide a standard interface for the
Java applications to perform those tasks. Finally, when some underlying platform does not
support all of the features a Java application expects, the class libraries can either emulate those
features using whatever is available, or at least provide a consistent way to check for the
presence of a specific feature.

Platform independence
One characteristic, platform independence, means that programs written in the Java language
must run similarly on any supported hardware/operating-system platform. One should be able to
write a program once, compile it once, and run it anywhere.

Performance
Java's performance has improved substantially since the early versions, and
performance of JIT compilers relative to native compilers has in some tests been shown to be
quite similar. The performance of the compilers does not necessarily indicate the performance of
the compiled code; only careful testing can reveal the true performance issues in any system.

Java Runtime Environment


The Java Runtime Environment, or JRE, is the software required to run any
application deployed on the Java Platform. End-users commonly use a JRE in software packages
and Web browser plugins. Sun also distributes a superset of the JRE called the Java 2 SDK (more
commonly known as the JDK), which includes development tools such as the Java compiler,
Javadoc, Jar and debugger.
One of the unique advantages of the concept of a runtime engine is that errors
(exceptions) should not 'crash' the system. Moreover, in runtime engine environments such as
Java there exist tools that attach to the runtime engine and every time that an exception of
interest occurs they record debugging information that existed in memory at the time the
exception was thrown (stack and heap values). These Automated Exception Handling tools
provide 'root-cause' information for exceptions in Java programs that run in production, testing
or development environments.

3. ANALYSIS AND MODLING


3.1 Analysis
Analysis is detailed study of the various operations performed by a system and their relationship
between within and outside is collected on the available files decision and transaction handled by
the present system. All the logical aspect of the system is conversed in the phase.Analysis is the
most important phase in the system of a system. In analysis phase one has to study the existing
system in detail and also collect necessary information regarding the system to be designed.
Hence in this phase flowchart and DFD are made indicating the data flow in the system, and then
only can a system be made correct otherwise it will be incorrect. Analysis is conducted with the
following objective in mind:

Identify the customer need.

Evaluate the system concept for feasibility.

Perform economic and technical analysis.

3.2 UML Modeling


3.2.1 Sequence Diagram

3.2.2 USE CASE DIAGRAM

3.2.3 Activities diagram

3.3 Data Modeling


3.3.1 Data Flow Diagram

4 System Requirement

4.1 HARDWARE REQUIREMENTS


Minimum System Requirements to Install and Use the software is JVM(java virtual
machine),JRE(java run time enviorment.
The minimum requirements are:
RAM: 256 MB (Recommended)
Processor: Pentium III 450 MHz
Operating System: Windows 2000 or Windows XP
Hard Disk Space: 2 GB (Includes 500 MB free space on disk)
4.2 SOFTWARE REQUIRMENT :
FRONT END : NETBEANS IDE 6.9+

4.3.OTHER
Nonfunctional Requirements
Performance Requirements

5.SYATEM DESIGN
.

5.1 Sub Systems


It is the process of assessing the development organization's ability to construct proposed a
system. Test is made to see whether reliable hardware and software, technical resources capable
of meeting the needs of a proposed system can be acquired or developed by an organization in
the required time. While accessing the technical feasibility, the various issues that are considered
are system performance, system interfaces, development processes, risks, failure immunity and
security.

5.2 Class Diagram

5.3. CORE LOGIC


Core Logic

AI:

There are two core logics in this game when both players are
human, and
when one is computer. Suppose the player use X and the
computer use O .
The logic used for the AI is as follows:

3.1 First move:


a) If the center is free, get the center. (Figure: 3.1)
b) Otherwise, get any of the corners. (Figure: 3.2)

3.2 Second move:


a) Block user from winning. (Figure: 3.3)
b) Option for winning by applying the following logic:
If the center is occupied by user, get any of the corners. (Figure:
3.4)

Otherwise, the following cases happen:

Case 1:

If any situation arises like the figure 3.5 then the computer sets
its symbol
any one of the position among 2, 4, 6 and 8.

Case 2:

If any situation arises like the figure 3.6 or figure 3.7 or figure 3.8
then the
computer sets its symbol at any position among 4 and 6.

Case 3:

If any situation arises like the figure 3.9 or figure 3.10 or figure
3.11 then the
computer sets its symbol at any position among 2 and 8.

Case 4:

If any situation arises like the figure 3.12 or figure 3.13 or figure
3.14 or
3.15 then the computer sets its symbol at any position among 1,
3, 7 and 9.

3.3 Third and fourth move:


a) Option for winning. (Figure: 3.16)
b) Block user from winning. (Figure: 3.17)
c) Randomly play a move. (Figure: 3.18)

Core Logic - Humans:


For each move, check whether any 3 combination is occupied by
any player
and display the winner accordingly.

6.Coding/ Snapshot

6.1 Coding
---Main Class--import javax.swing.JOptionPane;
public class Main {
public static boolean playerturn=true;
public static boolean youwon=false;
public static boolean computerwon=false;
public static Board1 board=new Board1();
public static Board2 board1=new Board2();
public static void main(String arg[]){
m=new MWindow();
m.setVisible(true);
}
public static MWindow m;
public static MWindow getMWindow(){
return m;
}
public static void computermove(){
if(playerturn==false)
if(board.jButton1.getText().equalsIgnoreCase("o")){
if(board.jButton2.getText().equalsIgnoreCase("o")){
if(board.jButton3.getText().equals("")){
board.jButton3.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton1.getText().equalsIgnoreCase("o")){
if(board.jButton3.getText().equalsIgnoreCase("o")){
if(board.jButton2.getText().equals("")){
board.jButton2.setText("o");playerturn=true;
}
}
} if(playerturn==false)
if(board.jButton2.getText().equalsIgnoreCase("o")){
if(board.jButton3.getText().equalsIgnoreCase("o")){

if(board.jButton1.getText().equals("")){
board.jButton1.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton4.getText().equalsIgnoreCase("o")){
if(board.jButton5.getText().equalsIgnoreCase("o")){
if(board.jButton6.getText().equals("")){
board.jButton6.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton4.getText().equalsIgnoreCase("o")){
if(board.jButton6.getText().equalsIgnoreCase("o")){
if(board.jButton5.getText().equals("")){
board.jButton5.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton6.getText().equalsIgnoreCase("o")){
if(board.jButton5.getText().equalsIgnoreCase("o")){
if(board.jButton4.getText().equals("")){
board.jButton4.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton7.getText().equalsIgnoreCase("o")){
if(board.jButton8.getText().equalsIgnoreCase("o")){
if(board.jButton9.getText().equals("")){
board.jButton9.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton7.getText().equalsIgnoreCase("o")){
if(board.jButton9.getText().equalsIgnoreCase("o")){
if(board.jButton8.getText().equals("")){
board.jButton8.setText("o");playerturn=true;
}
}
}if(playerturn==false)

if(board.jButton9.getText().equalsIgnoreCase("o")){
if(board.jButton8.getText().equalsIgnoreCase("o")){
if(board.jButton7.getText().equals("")){
board.jButton7.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton1.getText().equalsIgnoreCase("o")){
if(board.jButton4.getText().equalsIgnoreCase("o")){
if(board.jButton7.getText().equals("")){
board.jButton7.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton1.getText().equalsIgnoreCase("o")){
if(board.jButton7.getText().equalsIgnoreCase("o")){
if(board.jButton4.getText().equals("")){
board.jButton4.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton7.getText().equalsIgnoreCase("o")){
if(board.jButton4.getText().equalsIgnoreCase("o")){
if(board.jButton1.getText().equals("")){
board.jButton1.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton2.getText().equalsIgnoreCase("o")){
if(board.jButton5.getText().equalsIgnoreCase("o")){
if(board.jButton8.getText().equals("")){
board.jButton8.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton2.getText().equalsIgnoreCase("o")){
if(board.jButton8.getText().equalsIgnoreCase("o")){
if(board.jButton5.getText().equals("")){
board.jButton5.setText("o");playerturn=true;
}

}
}if(playerturn==false)
if(board.jButton8.getText().equalsIgnoreCase("o")){
if(board.jButton5.getText().equalsIgnoreCase("o")){
if(board.jButton2.getText().equals("")){
board.jButton2.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton3.getText().equalsIgnoreCase("o")){
if(board.jButton6.getText().equalsIgnoreCase("o")){
if(board.jButton9.getText().equals("")){
board.jButton9.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton3.getText().equalsIgnoreCase("o")){
if(board.jButton9.getText().equalsIgnoreCase("o")){
if(board.jButton6.getText().equals("")){
board.jButton6.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton9.getText().equalsIgnoreCase("o")){
if(board.jButton6.getText().equalsIgnoreCase("o")){
if(board.jButton3.getText().equals("")){
board.jButton3.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton1.getText().equalsIgnoreCase("o")){
if(board.jButton5.getText().equalsIgnoreCase("o")){
if(board.jButton9.getText().equals("")){
board.jButton9.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton1.getText().equalsIgnoreCase("o")){
if(board.jButton9.getText().equalsIgnoreCase("o")){
if(board.jButton5.getText().equals("")){

board.jButton5.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton9.getText().equalsIgnoreCase("o")){
if(board.jButton5.getText().equalsIgnoreCase("o")){
if(board.jButton1.getText().equals("")){
board.jButton1.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton3.getText().equalsIgnoreCase("o")){
if(board.jButton5.getText().equalsIgnoreCase("o")){
if(board.jButton7.getText().equals("")){
board.jButton7.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton3.getText().equalsIgnoreCase("o")){
if(board.jButton7.getText().equalsIgnoreCase("o")){
if(board.jButton5.getText().equals("")){
board.jButton5.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton7.getText().equalsIgnoreCase("o")){
if(board.jButton5.getText().equalsIgnoreCase("o")){
if(board.jButton3.getText().equals("")){
board.jButton3.setText("o");playerturn=true;
}
}
}
if(playerturn==false)
if(board.jButton1.getText().equalsIgnoreCase("x")){
if(board.jButton2.getText().equalsIgnoreCase("x")){
if(board.jButton3.getText().equals("")){
board.jButton3.setText("o");playerturn=true;
}

}
}if(playerturn==false)
if(board.jButton1.getText().equalsIgnoreCase("x")){
if(board.jButton3.getText().equalsIgnoreCase("x")){
if(board.jButton2.getText().equals("")){
board.jButton2.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton2.getText().equalsIgnoreCase("x")){
if(board.jButton3.getText().equalsIgnoreCase("x")){
if(board.jButton1.getText().equals("")){
board.jButton1.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton4.getText().equalsIgnoreCase("x")){
if(board.jButton5.getText().equalsIgnoreCase("x")){
if(board.jButton6.getText().equals("")){
board.jButton6.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton4.getText().equalsIgnoreCase("x")){
if(board.jButton6.getText().equalsIgnoreCase("x")){
if(board.jButton5.getText().equals("")){
board.jButton5.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton6.getText().equalsIgnoreCase("x")){
if(board.jButton5.getText().equalsIgnoreCase("x")){
if(board.jButton4.getText().equals("")){
board.jButton4.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton7.getText().equalsIgnoreCase("x")){
if(board.jButton8.getText().equalsIgnoreCase("x")){
if(board.jButton9.getText().equals("")){

board.jButton9.setText("o");playerturn=true;
}
}
}
if(playerturn==false)
if(board.jButton7.getText().equalsIgnoreCase("x")){
if(board.jButton9.getText().equalsIgnoreCase("x")){
if(board.jButton8.getText().equals("")){
board.jButton8.setText("o");playerturn=true;
}
}
} if(playerturn==false)
if(board.jButton9.getText().equalsIgnoreCase("x")){
if(board.jButton8.getText().equalsIgnoreCase("x")){
if(board.jButton7.getText().equals("")){
board.jButton7.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton1.getText().equalsIgnoreCase("x")){
if(board.jButton4.getText().equalsIgnoreCase("x")){
if(board.jButton7.getText().equals("")){
board.jButton7.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton1.getText().equalsIgnoreCase("x")){
if(board.jButton7.getText().equalsIgnoreCase("x")){
if(board.jButton4.getText().equals("")){
board.jButton4.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton7.getText().equalsIgnoreCase("x")){
if(board.jButton4.getText().equalsIgnoreCase("x")){
if(board.jButton1.getText().equals("")){
board.jButton1.setText("o");playerturn=true;
}
}
}if(playerturn==false)

if(board.jButton2.getText().equalsIgnoreCase("x")){
if(board.jButton5.getText().equalsIgnoreCase("x")){
if(board.jButton8.getText().equals("")){
board.jButton8.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton2.getText().equalsIgnoreCase("x")){
if(board.jButton8.getText().equalsIgnoreCase("x")){
if(board.jButton5.getText().equals("")){
board.jButton5.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton8.getText().equalsIgnoreCase("x")){
if(board.jButton5.getText().equalsIgnoreCase("x")){
if(board.jButton2.getText().equals("")){
board.jButton2.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton3.getText().equalsIgnoreCase("x")){
if(board.jButton6.getText().equalsIgnoreCase("x")){
if(board.jButton9.getText().equals("")){
board.jButton9.setText("o");playerturn=true;
}
}
} if(playerturn==false)if(board.jButton3.getText().equalsIgnoreCase("x")){
if(board.jButton9.getText().equalsIgnoreCase("x")){
if(board.jButton6.getText().equals("")){
board.jButton6.setText("o");playerturn=true;
}
}
} if(playerturn==false)if(board.jButton9.getText().equalsIgnoreCase("x")){
if(board.jButton6.getText().equalsIgnoreCase("x")){
if(board.jButton3.getText().equals("")){
board.jButton3.setText("o");playerturn=true;
}
}
} if(playerturn==false)if(board.jButton1.getText().equalsIgnoreCase("x")){

if(board.jButton5.getText().equalsIgnoreCase("x")){
if(board.jButton9.getText().equals("")){
board.jButton9.setText("o");playerturn=true;
}
}
} if(playerturn==false)if(board.jButton1.getText().equalsIgnoreCase("x")){
if(board.jButton9.getText().equalsIgnoreCase("x")){
if(board.jButton5.getText().equals("")){
board.jButton5.setText("o");playerturn=true;
}
}
}if(playerturn==false) if(board.jButton9.getText().equalsIgnoreCase("x")){
if(board.jButton5.getText().equalsIgnoreCase("x")){
if(board.jButton1.getText().equals("")){
board.jButton1.setText("o");playerturn=true;
}
}
}if(playerturn==false) if(board.jButton3.getText().equalsIgnoreCase("x")){
if(board.jButton5.getText().equalsIgnoreCase("x")){
if(board.jButton7.getText().equals("")){
board.jButton7.setText("o");playerturn=true;
}
}
}if(playerturn==false)
if(board.jButton3.getText().equalsIgnoreCase("x")){
if(board.jButton7.getText().equalsIgnoreCase("x")){
if(board.jButton5.getText().equals("")){
board.jButton5.setText("o");playerturn=true;
}
}
}if(playerturn==false) if(board.jButton7.getText().equalsIgnoreCase("x")){
if(board.jButton5.getText().equalsIgnoreCase("x")){
if(board.jButton3.getText().equals("")){
board.jButton3.setText("o");playerturn=true;
}
}
}
}
public static void other(){

if(playerturn==false)
if(board.jButton5.getText().equals("")){
board.jButton5.setText("o");playerturn=true;
}
if(playerturn==false)
if(board.jButton1.getText().equals("")){
board.jButton1.setText("o");playerturn=true;
}if(playerturn==false)
if(board.jButton2.getText().equals("")){
board.jButton2.setText("o");playerturn=true;
}if(playerturn==false)
if(board.jButton3.getText().equals("")){
board.jButton3.setText("o");playerturn=true;
}if(playerturn==false)
if(board.jButton4.getText().equals("")){
board.jButton4.setText("o");playerturn=true;
}if(playerturn==false)
if(board.jButton6.getText().equals("")){
board.jButton6.setText("o");playerturn=true;
}if(playerturn==false)
if(board.jButton7.getText().equals("")){
board.jButton7.setText("o");playerturn=true;
}if(playerturn==false)
if(board.jButton8.getText().equals("")){
board.jButton8.setText("o");playerturn=true;
}if(playerturn==false)
if(board.jButton9.getText().equals("")){
board.jButton9.setText("o");playerturn=true;
}
}
public static void checkforwin(){
if(board.jButton1.getText().equalsIgnoreCase("x")){
if(board.jButton2.getText().equalsIgnoreCase("x")){
if(board.jButton3.getText().equalsIgnoreCase("x")){
youwon=true;
computerwon=false;
JOptionPane.showMessageDialog(null, "you won", "",
JOptionPane.DEFAULT_OPTION);

}
}
}
if(board.jButton4.getText().equalsIgnoreCase("x")){
if(board.jButton5.getText().equalsIgnoreCase("x")){
if(board.jButton6.getText().equalsIgnoreCase("x")){
youwon=true;
computerwon=false;
JOptionPane.showMessageDialog(null, "you won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board.jButton7.getText().equalsIgnoreCase("x")){
if(board.jButton8.getText().equalsIgnoreCase("x")){
if(board.jButton9.getText().equalsIgnoreCase("x")){
youwon=true;
computerwon=false;
JOptionPane.showMessageDialog(null, "you won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board.jButton1.getText().equalsIgnoreCase("x")){
if(board.jButton4.getText().equalsIgnoreCase("x")){
if(board.jButton7.getText().equalsIgnoreCase("x")){
youwon=true;
computerwon=false;
JOptionPane.showMessageDialog(null, "you won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board.jButton2.getText().equalsIgnoreCase("x")){
if(board.jButton5.getText().equalsIgnoreCase("x")){
if(board.jButton8.getText().equalsIgnoreCase("x")){

youwon=true;
computerwon=false;
JOptionPane.showMessageDialog(null, "you won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board.jButton3.getText().equalsIgnoreCase("x")){
if(board.jButton6.getText().equalsIgnoreCase("x")){
if(board.jButton9.getText().equalsIgnoreCase("x")){
youwon=true;
computerwon=false;
JOptionPane.showMessageDialog(null, "you won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board.jButton3.getText().equalsIgnoreCase("x")){
if(board.jButton5.getText().equalsIgnoreCase("x")){
if(board.jButton7.getText().equalsIgnoreCase("x")){
youwon=true;
computerwon=false;
JOptionPane.showMessageDialog(null, "you won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board.jButton1.getText().equalsIgnoreCase("x")){
if(board.jButton5.getText().equalsIgnoreCase("x")){
if(board.jButton9.getText().equalsIgnoreCase("x")){
youwon=true;
computerwon=false;
JOptionPane.showMessageDialog(null, "you won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}

if(board.jButton1.getText().equalsIgnoreCase("o")){
if(board.jButton2.getText().equalsIgnoreCase("o")){
if(board.jButton3.getText().equalsIgnoreCase("o")){
computerwon=true;
youwon=false;
JOptionPane.showMessageDialog(null, "computer won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board.jButton4.getText().equalsIgnoreCase("o")){
if(board.jButton5.getText().equalsIgnoreCase("o")){
if(board.jButton6.getText().equalsIgnoreCase("o")){
computerwon=true;
youwon=false;
JOptionPane.showMessageDialog(null, "computer won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board.jButton7.getText().equalsIgnoreCase("o")){
if(board.jButton8.getText().equalsIgnoreCase("o")){
if(board.jButton9.getText().equalsIgnoreCase("o")){
computerwon=true;
youwon=false;
JOptionPane.showMessageDialog(null, "computer won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board.jButton1.getText().equalsIgnoreCase("o")){
if(board.jButton4.getText().equalsIgnoreCase("o")){
if(board.jButton7.getText().equalsIgnoreCase("o")){
computerwon=true;
youwon=false;

JOptionPane.showMessageDialog(null, "computer won", "",


JOptionPane.DEFAULT_OPTION);
}
}
}
if(board.jButton2.getText().equalsIgnoreCase("o")){
if(board.jButton5.getText().equalsIgnoreCase("o")){
if(board.jButton8.getText().equalsIgnoreCase("o")){
computerwon=true;
youwon=false;
JOptionPane.showMessageDialog(null, "computer won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board.jButton3.getText().equalsIgnoreCase("o")){
if(board.jButton6.getText().equalsIgnoreCase("o")){
if(board.jButton9.getText().equalsIgnoreCase("o")){
computerwon=true;
youwon=false;
JOptionPane.showMessageDialog(null, "computer won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board.jButton3.getText().equalsIgnoreCase("o")){
if(board.jButton5.getText().equalsIgnoreCase("o")){
if(board.jButton7.getText().equalsIgnoreCase("o")){
computerwon=true;
youwon=false;
JOptionPane.showMessageDialog(null, "computer won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board.jButton1.getText().equalsIgnoreCase("o")){

if(board.jButton5.getText().equalsIgnoreCase("o")){
if(board.jButton9.getText().equalsIgnoreCase("o")){
computerwon=true;
youwon=false;
JOptionPane.showMessageDialog(null, "computer won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
}
public static void checkfordraw(){
if(computerwon==false)
if(youwon==false)
if(board.jButton1.getText()!="")
if(board.jButton2.getText()!="")
if(board.jButton3.getText()!="")
if(board.jButton4.getText()!="")
if(board.jButton5.getText()!="")
if(board.jButton6.getText()!="")
if(board.jButton7.getText()!="")
if(board.jButton8.getText()!="")
if(board.jButton9.getText()!=""){
JOptionPane.showMessageDialog(null, "Game Draw", "",
JOptionPane.DEFAULT_OPTION);
}
}
public static void checkforwin1(){
if(board1.jButton1.getText().equalsIgnoreCase("x")){
if(board1.jButton2.getText().equalsIgnoreCase("x")){
if(board1.jButton3.getText().equalsIgnoreCase("x")){
youwon=true;
computerwon=false;
JOptionPane.showMessageDialog(null, "player1 won", "",
JOptionPane.DEFAULT_OPTION);

}
}
}
if(board1.jButton4.getText().equalsIgnoreCase("x")){
if(board1.jButton5.getText().equalsIgnoreCase("x")){
if(board1.jButton6.getText().equalsIgnoreCase("x")){
youwon=true;
computerwon=false;
JOptionPane.showMessageDialog(null, "player1 won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board1.jButton7.getText().equalsIgnoreCase("x")){
if(board1.jButton8.getText().equalsIgnoreCase("x")){
if(board1.jButton9.getText().equalsIgnoreCase("x")){
youwon=true;
computerwon=false;
JOptionPane.showMessageDialog(null, "player1 won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board1.jButton1.getText().equalsIgnoreCase("x")){
if(board1.jButton4.getText().equalsIgnoreCase("x")){
if(board1.jButton7.getText().equalsIgnoreCase("x")){
youwon=true;
computerwon=false;
JOptionPane.showMessageDialog(null, "player1 won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board1.jButton2.getText().equalsIgnoreCase("x")){
if(board1.jButton5.getText().equalsIgnoreCase("x")){
if(board1.jButton8.getText().equalsIgnoreCase("x")){

youwon=true;
computerwon=false;
JOptionPane.showMessageDialog(null, "player1 won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board1.jButton3.getText().equalsIgnoreCase("x")){
if(board1.jButton6.getText().equalsIgnoreCase("x")){
if(board1.jButton9.getText().equalsIgnoreCase("x")){
youwon=true;
computerwon=false;
JOptionPane.showMessageDialog(null, "player1 won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board1.jButton3.getText().equalsIgnoreCase("x")){
if(board1.jButton5.getText().equalsIgnoreCase("x")){
if(board1.jButton7.getText().equalsIgnoreCase("x")){
youwon=true;
computerwon=false;
JOptionPane.showMessageDialog(null, "player1 won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board1.jButton1.getText().equalsIgnoreCase("x")){
if(board1.jButton5.getText().equalsIgnoreCase("x")){
if(board1.jButton9.getText().equalsIgnoreCase("x")){
youwon=true;
computerwon=false;
JOptionPane.showMessageDialog(null, "player1 won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}

if(board1.jButton1.getText().equalsIgnoreCase("o")){
if(board1.jButton2.getText().equalsIgnoreCase("o")){
if(board1.jButton3.getText().equalsIgnoreCase("o")){
computerwon=true;
youwon=false;
JOptionPane.showMessageDialog(null, "player2 won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board1.jButton4.getText().equalsIgnoreCase("o")){
if(board1.jButton5.getText().equalsIgnoreCase("o")){
if(board1.jButton6.getText().equalsIgnoreCase("o")){
computerwon=true;
youwon=false;
JOptionPane.showMessageDialog(null, "player2 won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board1.jButton7.getText().equalsIgnoreCase("o")){
if(board1.jButton8.getText().equalsIgnoreCase("o")){
if(board1.jButton9.getText().equalsIgnoreCase("o")){
computerwon=true;
youwon=false;
JOptionPane.showMessageDialog(null, "player2 won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board1.jButton1.getText().equalsIgnoreCase("o")){
if(board1.jButton4.getText().equalsIgnoreCase("o")){
if(board1.jButton7.getText().equalsIgnoreCase("o")){
computerwon=true;
youwon=false;

JOptionPane.showMessageDialog(null, "player2 won", "",


JOptionPane.DEFAULT_OPTION);
}
}
}
if(board1.jButton2.getText().equalsIgnoreCase("o")){
if(board1.jButton5.getText().equalsIgnoreCase("o")){
if(board1.jButton8.getText().equalsIgnoreCase("o")){
computerwon=true;
youwon=false;
JOptionPane.showMessageDialog(null, "player2 won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board1.jButton3.getText().equalsIgnoreCase("o")){
if(board1.jButton6.getText().equalsIgnoreCase("o")){
if(board1.jButton9.getText().equalsIgnoreCase("o")){
computerwon=true;
youwon=false;
JOptionPane.showMessageDialog(null, "player2 won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board1.jButton3.getText().equalsIgnoreCase("o")){
if(board1.jButton5.getText().equalsIgnoreCase("o")){
if(board1.jButton7.getText().equalsIgnoreCase("o")){
computerwon=true;
youwon=false;
JOptionPane.showMessageDialog(null, "player2 won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}
if(board1.jButton1.getText().equalsIgnoreCase("o")){

if(board1.jButton5.getText().equalsIgnoreCase("o")){
if(board1.jButton9.getText().equalsIgnoreCase("o")){
computerwon=true;
youwon=false;
JOptionPane.showMessageDialog(null, "player2 won", "",
JOptionPane.DEFAULT_OPTION);
}
}
}}}

6.2 Snapshot
spalshpanel

Mainwindow

Empty board

Playing Board

7.Testing
7.1 Software testing

Is the process used to assess the quality of computer software. Software testing is an empirical
technical investigation conducted to provide stakeholders with information about the quality of
the product or service under test, with respect to the context in which it is intended to operate.
This includes, but is not limited to, the process of executing a program or application with the
intent of finding software bugs. Quality is not an absolute; it is value to some person. With that in
mind, testing can never completely establish the correctness of arbitrary computer software;
testing furnishes a criticism or comparison that compares the state and behavior of the product
against a specification. An important point is that software testing should be distinguished from
the separate discipline of Software Quality Assurance (S.Q.A.), which encompasses all business
process areas, not just testing. Over its existence, computer software has continued to grow in
complexity and size. Every software product has a target audience. For example, a video game
software has its audience completely different from banking software. Therefore, when an
organization develops or otherwise invests in a software product, it presumably must assess
whether the software product will be acceptable to its end users, its target audience, its
purchasers, and other stakeholders. Software testing is the process of attempting to make this
assessmentSoftware testing methods are traditionally divided into black box testing and white
box testing. These two approaches are used to describe the point of view that a test engineer
takes when designing test cases.
7.2 Black box testing
Treats the software as a black-box without any understanding of internal behavior. It aims to test
the functionality according to the requirements. Thus, the tester inputs data and only sees the
output from the test object. This level of testing usually requires thorough test cases to be
provided to the tester who then can simply verify that for a given input, the output value (or
behavior), is the same as the expected value specified in the test case. Black box testing methods
include: equivalence partitioning, boundary value analysis, all-pairs testing, fuzz testing, modelbased testing, traceability matrix etc.
7.3 White box testing
However, is when the tester has access to the internal data structures, code, and algorithms. White
box testing methods include creating tests to satisfy some code coverage criteria. For example,
the test designer can create tests to cause all statements in the program to be executed at least

once. Other examples of white box testing are mutation testing and fault injection methods. White
box testing includes all static testing.White box testing methods can also be used to evaluate the
completeness of a test suite that was created with black box testing methods. This allows the
software team to examine parts of a system that are rarely tested and ensures that the most
important function points have been tested. Two common forms of code coverage are function
coverage, which reports on functions executed and statement coverage, which reports on the
number of lines executed to complete the test. They both return a coverage metric, measured as a
percentage.
Testing can be done on the following levels:

Unit testing tests the minimal software component, or module. Each unit (basic
component) of the software is tested to verify that the detailed design for the unit has
been correctly implemented. In an object-oriented environment, this is usually at the class
level, and the minimal unit tests include the constructors and destructors.

Integration testing exposes defects in the interfaces and interaction between integrated
components (modules). Progressively larger groups of tested software components
corresponding to elements of the architectural design are integrated and tested until the
software works as a system.

System testing tests a completely integrated system to verify that it meets its
requirements.

System integration testing verifies that a system is integrated to any external or third
party systems defined in the system requirementsBefore shipping the final version of
software, alpha and beta testing are often done additionally:

7.4 Alpha testing


Is simulated or actual operational testing by potential users/customers or an independent test
team at the developers' site. Alpha testing is often employed for off-the-shelf software as a form
of internal acceptance testing, before the software goes to beta testing.
7.5Beta testing

comes after alpha testing. Versions of the software, known as beta versions, are released to a
limited audience outside of the programming team. The software is released to groups of people
so that further testing can ensure the product has few faults or bugs. Sometimes, beta versions are
made available to the open public to increase the feedback field to a maximal number of future
users
Finally, acceptance testing can be conducted by the end-user, customer, or client
validate whether or not to accept the product. Acceptance testing may

to
be

performed as part of the hand-off process between any two phases of development.

8. Conclusion
have done my best to make the complicated process of TIC TAC TOE GAME as simple as
possible using Structured & Modular technique & Menu oriented interface. I have tried to design
the software in such a way that user may not have any difficulty in using this package & further
expansion is possible without much effort. Even though I cannot claim that this work to be
entirely exhaustive. As every game has some limitations so my project is not exceptional, but I
will try to short out them very shortly and deliver a defective less product to client.
I am confident that this software package can be readily used by non-programming personal
avoiding human handled chance of error.

9.References.
Books

Programming in Java 2nd Edition, E. Balaguruswamy TMH Publications.


Head first 2nd Edition

Das könnte Ihnen auch gefallen