You are on page 1of 21

INTRODUCTION

One representation of artificial intelligence science is a Game. With artificial


intelligence, certain games can be solved through computers. The games that can be
classified into artificial intelligence games are Sudoku. Sudoku is a game that has been
popular since the 1970s. This game is like a number game where the player must fill in
the available empty boxes with random numbers 1-9 (standard Sudoku). The rules of the
Sudoku game are straightforward. It is namely filling in a puzzle with random numbers.
But it seems like not a few who fail and cannot finish this game. That's because there are
more than thousands of solutions offered to solve Sudoku puzzles.

Thus came the idea to create an Android application that can generate puzzles and
solve them. From the exposure, it can be determining the limitations of the problem are as
follows:

 Making this Sudoku game implements the backtracking algorithm on mobile / Android
applications.
 The programming language used is java. Supporting software used to make Sudoku
games is Android studio.
 Sudoku puzzles used are a standard size 9 x 9 boxes.
 The initial element generated consists of a maximum of 36 numbers and a minimum of 27
puzzle numbers that have been filled in with numbers, and each row, column, and block
(3x3) has been filled in at least one box and may not be empty on each of its genera.
Abstraction

Sudoku is a pretty popular number game. The goal of this game is to fill a 9x9 matrix
with unique numbers, and there should not be repeated numbers in each row, column, or
block. This paper proposed a solution to solve Sudoku using the Backtracking Algorithm.
This algorithm is quite efficient because it does not have to check all the possibilities that
exist, but which leads to only the solution that will be processed, namely by pruning
every element that does not lead to the solution. Thus the time required is quite efficient
and suitable for use in reasonably complex numbers games like sudoku. By implementing
the backtracking algorithm in the sudoku game, the complexity of the algorithm can be as
large 𝜽 (n3).

A Sudoku starts with some cells containing numbers and the goal is to solve the
remaking this Sudoku game implements the backtracking algorithm on mobile / Android
applications. Proper Sudoku have one solution. The programming language used is
java. Supporting software used to make Sudoku games is Android studio.

Sudoku puzzles used are a standard size 9 x 9 boxes. The initial element generated
consists of a maximum of 36 numbers and a minimum of 27 puzzle numbers that have
been filled in with numbers, and each row, column, and block (3x3) has been filled in at
least one box and may not be empty on each of its genera. Main cells. One or more
known Sudoku which satisfy or nearly satisfy the characteristic being searched for is used
as a starting point.
Objective

One common method of searching for Sudoku with a particular characteristic is called
neighbour searching. Using this strategy, one or more known Sudoku which satisfy or
nearly satisfy the characteristic being searched for is used as a starting point, and these
Sudoku are then altered to look for other Sudoku with the property being sought. The
alteration can be relocating one or more clue positions, or removing a small number of
clues, and replacing them with a different number of clues.
LITERATURE SURVEY

Existing System

Backtracking Algorithm
D.H. Lehmer was the first to introduce the backtracking algorithm in 1950. The
backtracking algorithm is one of the problem-solving methods included in a strategy
based on searching the solution space, but it does not have to examine all possibilities,
only those that lead to only solutions will be processed. Algorithms backtracking is also
an algorithm that works recursively, where the search process is based on the Depth-First
Search (DFS) algorithm, which is to search for systematic solutions to all possible
solutions and search for answers is done by tracing a tree-shaped structure rooted. There
for this algorithm is quite powerful and very good to be applied in problem-solving and to
provide artificial intelligence in the game. Several types of digital games that are
generally commonly known by the public, such as Chess, Math Maze, Tic Tac Toe, to
Sudoku can be found a solution by implementing the backtracking algorithm.

The backtracking algorithm is an improvement of the brute force algorithm, which is


to find solutions to problems among all possible solutions systematically. Backtracking is
a typical form of recursive algorithm and is based on DFS (Depth-First Search) in finding
the right answer. In another sense, the backtracking algorithm works like experimenting
with several possibilities that lead to the solution until it finds the most appropriate one.
So there is no need to check all possible solutions, but it is enough that only leads to the
solution, namely by sorting pruning the nodes that do not lead to the solution. Thus the
search time can be saved. The difference with the brute force algorithm is the basic
concept, namely, in backtracking, all solutions are made in the form of a solution tree
(tree), and then the tree will be traced in DFS (Depth-First Search) to find the best-desired
solution.
Proposed System

The objectives of the proposed Project is to increase the Thinking Capability. The
Game having all the records which u perform in playing you can Select Easy, hard level
according to your choice. You can make your own Sudoku and at any Step you can go
back to One Step as well as you can see the Solution of it. It is manually a very difficult
job to perform and its need a lot of recalling, reminding and mathematical calculation.
The game of “Sudoku” helps to increase mental thinking, vision etc.
REQUIREMENT SPECIFICATION
Project Requirement Specification

Project requirement are conditions or tasks that must be completed to ensure the
success or completion of the project. They provide a clear picture of the work that needs
to be done. They’re meant to align the project’s resources with the objectives of the
organization.

Software Requirements
 Operating System : windows 7, windows 8, windows 10
 Design : XML
 Tools : Android Emulator Android SDK-ADK-bundle-
windows-x86 Jdk-8u66-windows-x86

Hardware Requirements

 Processor : Pentium core i4 and above


 Hard Disk : Minimum 500GB
 RAM : Minimum 8GB

Languages

 Front end : XML


 Back end : Java
 Scripting Language : Angular JavaScript
SYSTEM DESIGN

Design Decisions
Analysis process is designed to provide an overview of all processes that occur as
well as provide an overview of the parts of the system being designed. In this study, the
process flow shown by a flowchart, which is an algorithm flowchart. The backtracking
algorithm flowchart is a data flow based on an existing algorithm. In this flowchart, the
running algorithm process is explained from the beginning to the end. The backtracking
algorithm's diagram is illustrated in figure 1.

Figure 5.1.1 Algorithms Flowchart


Use Case Diagram

Add Number
New Game

Hint

Show Solution

Complete
player Puzzle

Setup game
board

Create answer Generate new


grid game

Show hint

Show solution

System
Check puzzle

Display time
used
Block Diagram of Sudoku Game
6. IMPLEMENTATION

Implementation Details
The implementation phase of any project is the most important phase as it yields the
final solution, which solves the problem at hand. The implementation phase involves the
actual materialization of the ideas, which are expressed in the analysis document and
developed in the design phase. Implementation should be perfect mapping of the design
document in a suitable programming language in order to achieve the necessary final
product. Often the product is ruined due to incorrect programming language chosen for
implementation or unsuitable method of programming. It is better for the coding phase to
be directly linked to the design phase in the sense if the design is in terms of object
oriented terms then implementation should be preferably carried out in object oriented
way.

Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/wall"
android:orientation="horizontal"
android:padding="85dip">

<LinearLayout
android:layout_width="249dp"
android:layout_height="250dp"
android:layout_gravity="center"
android:orientation="vertical">

<Button
android:id="@+id/new_button"
android:layout_width="200dp"
android:layout_height="55dp"
android:layout_margin="5dip"
android:background="@drawable/button1"
android:text="@string/new_game_label"
android:textAppearance="@android:style/TextAppearance.Material.Large"
android:textStyle="bold" />

<Button
android:id="@+id/about_button"
android:layout_width="200dp"
android:layout_height="55dp"
android:layout_margin="5dip"
android:background="@drawable/button1"
android:text="@string/about_label"
android:textAppearance="@android:style/TextAppearance.Material.Large"
android:textStyle="bold" />

<Button
android:id="@+id/exit_button"
android:layout_width="200dp"
android:layout_height="55dp"
android:layout_margin="5dip"
android:background="@drawable/button1"
android:text="@string/exit_label"
android:textAppearance="@android:style/TextAppearance.Material.Large"
android:textStyle="bold" />

<CheckBox
android:id="@+id/mus"
style="@android:style/Widget.DeviceDefault.Light.CompoundButton.CheckBox"
android:layout_width="200dp"
android:layout_height="40dp"
android:autoText="false"
android:onClick="onClick"
android:text="Music"
android:textAppearance="@android:style/TextAppearance.Material.Large"
android:textColor="#000000"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
5.3.2 Keypad.xml

<?xml version="1.0" encoding="utf-8"?>


<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/keypad"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:stretchColumns="*">
<TableRow>
<Button android:id="@+id/keypad_1"
android:text="1">
</Button>
<Button android:id="@+id/keypad_2"
android:text="2">
</Button>
<Button android:id="@+id/keypad_3"
android:text="3">
</Button>
</TableRow>
<TableRow>
<Button android:id="@+id/keypad_4"
android:text="4">
</Button>
<Button android:id="@+id/keypad_5"
android:text="5">
</Button>
<Button android:id="@+id/keypad_6"
android:text="6">
</Button>
</TableRow>
<TableRow>
<Button android:id="@+id/keypad_7"
android:text="7">
</Button>
<Button android:id="@+id/keypad_8"
android:text="8">
</Button>
<Button android:id="@+id/keypad_9"
android:text="9">
</Button>
</TableRow>
</TableLayout>
Game.java
package org.ace.game;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.text.style.BackgroundColorSpan;
import android.util.Log;
import android.view.Gravity;
import android.widget.Toast;

public class Game extends Activity {


private static final String TAG = "Sudoku";

public static final String KEY_DIFFICULTY =


"org.example.sudoku.difficulty";
public static final int DIFFICULTY_EASY = 0;
public static final int DIFFICULTY_MEDIUM = 1;
public static final int DIFFICULTY_HARD = 2;

private int puzzle[] = new int[9 * 9];

private final String easyPuzzle =


"543921876219687543876354219"+
"987465321321798654654132987"+
"765243198432819765198576000";
private final String mediumPuzzle =
"650000070000506000014000005" +
"007009000002314700000700800" +
"500000630000201000030000097";
private final String hardPuzzle =
"009000000080605020501078000" +
"000000700706040102004000000" +
"000720903090301080000000600";
private PuzzleView puzzleView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "onCreate");

int diff = getIntent().getIntExtra(KEY_DIFFICULTY,


DIFFICULTY_EASY);
puzzle = getPuzzle(diff);
calculateUsedTiles();

puzzleView = new PuzzleView(this);


setContentView(puzzleView);
puzzleView.requestFocus();
}

/** Given a difficulty level, come up with a new puzzle */


private int[] getPuzzle(int diff) {
String puz;
// TODO: Continue last game
switch (diff) {
case DIFFICULTY_HARD:
puz = hardPuzzle;
break;
case DIFFICULTY_MEDIUM:
puz = mediumPuzzle;
break;
case DIFFICULTY_EASY:
default:
puz = easyPuzzle;
break;
}
return fromPuzzleString(puz);
}

/** Convert an array into a puzzle string */


static private String toPuzzleString(int[] puz) {
StringBuilder buf = new StringBuilder();
for (int element : puz) {
buf.append(element);
}
return buf.toString();
}

/** Convert a puzzle string into an array */


static protected int[] fromPuzzleString(String string) {
int[] puz = new int[string.length()];
for (int i = 0; i < puz.length; i++) {
puz[i] = string.charAt(i) - '0';
}
return puz;
}

/** Return the tile at the given coordinates */


private int getTile(int x, int y) {
return puzzle[y * 9 + x];
}

/** Change the tile at the given coordinates */


private void setTile(int x, int y, int value) {
puzzle[y * 9 + x] = value;}
Sudoku Game.java
package org.ace.game;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;

import java.util.Objects;

public class SudokuGame1 extends Activity implements OnClickListener {

private CheckBox mus;


MediaPlayer mySong;

private static final String TAG = "Sukgludflkgfdkhd";


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// Set up click listeners for all the buttons


/* View continueButton = findViewById(R.id.continue_button);
continueButton.setOnClickListener(this);*/
View newButton = findViewById(R.id.new_button);
newButton.setOnClickListener(this);
View aboutButton = findViewById(R.id.about_button);
aboutButton.setOnClickListener(this);
View exitButton = findViewById(R.id.exit_button);
exitButton.setOnClickListener(this);

mus=findViewById(R.id.mus);
mySong = MediaPlayer.create(SudokuGame1.this,R.raw.dash);
mySong.setLooping(true);
}

// ...
public void onClick(View v) {

if(mus.isChecked()){
mySong.start();
}
else {
mySong.pause();
}

switch (v.getId()) {
case R.id.about_button:
Intent i = new Intent(this, About.class);
startActivity(i);
break;
// More buttons go here (if any) ...

case R.id.new_button:
openNewGameDialog();
break;

case R.id.exit_button:
finish();
break;

}
}

protected void onDestroy(){


super.onDestroy();
mySong.stop();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.settings:
startActivity(new Intent(this, Prefs.class));
return true;
// More items go here (if any) ...
}
return false;
}

/** Ask the user what difficulty level they want */


private void openNewGameDialog() {
new AlertDialog.Builder(this)
.setTitle(R.string.new_game_title)
.setItems(R.array.difficulty,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialoginterface,
int i) {
startGame(i);
}
})
.show();
}

/** Start a new game with the given difficulty level */


private void startGame(int i) {
Log.d(TAG, "clicked on " + i);
Intent intent = new Intent(SudokuGame1.this, Game.class);
intent.putExtra(Game.KEY_DIFFICULTY, i);
startActivity(intent);
}
}
SNAP SHOTS

User Interface

You might also like