## Introduction

One of the problems of artificial intelligence is to solve tortuous games (MAZE). It defines the state space has to solve in a variety of ways. To solve this problem and to explain the rules of the game, I will explain the solution.

#### Rules of the Problem

- This game can be defined in a finite space so that a space is used for the main board.
- In this paper, we consider the N * N array of boards.
- The array of rows and columns to rows and columns around the board to be considered.
- The board can only have a unique path from the beginning to the end boards.
- Just move forward and down is allowed.
- A starting point has to be considered.
- A point-to-end path is considered.
- Back on track in this algorithm is not allowed.
- In each case, only one of two moves are allowed.
- The output rows and columns are allowed to be displayed in the path traveled.

## Algorithmic Problem Solving

- In this algorithm, before the first row and the column next will be checked.
- If not, depending on the amount of rows and columns are added to the stack.
- If the row was closed, the column is checked.
- If the route was closed in the design of this board game has not been met and wrong. So no solution.
- If the path was open to the current row and column stored in the stack and the algorithm examines the first level.
- With each repeat the entire course of the algorithm is checked.
- The output is stored in the stack are shown.

In this method, the breadth first search (BFS) is used to traverse the route. Due to the nature of the problem space of this algorithm is informed. Pseudo code solution is as follows:

Do
If next row is 0 add row
Else
If next column is 0 add column
Else
If row and col is final element Return true
Else
Return not solve

Algorithm for solving tortuous path is provided. This algorithm is one of the simplest algorithms to ensure if there is any output. In the later stages of the algorithm to return the issues that raised a few out there. To find the shortest path algorithm can also be raised.

The algorithm is based on all the issues presented in this article. The program flowchart is presented.

## Analysis of Code

It is composed of two layers:

- Presentation layer
- Business layer

Most orders are delivered in the output layer. To observe the rules as a single Business object, layer data (Abstraction) has been created. The program for keeping track of a stack data structure is used. The rule also hides the data from the user perspective is fully respected. To access individual elements of the array access (accessor) is used.

The definition of a project and define a class called `Mazebusiness`

. The following code defines variables needed by the stack is maintained. The row and column maintenance variable and is defined as the top of each stack. Home-range storage array is also defined.

int SIZE = 20;
int max = 6;
int min = 0;
int[] stack1 = new int[20];
int[] stack2 = new int[20];
int tos1, tos2, col, row;
int[,] array = new int[6, 6];

### Constructor

This class defines the initial value of zero in the constructor for the main board. Later with another method to define the elements to a desired result. The values of both arrays keep the stack is zero. Each stack is too high a value of zero. The rows and columns are defined as zero.

public MazeBusiness()
{
for (int i = 0; i < 5; i++)
for (int j = 0; j < 5; j++)
array[i, j] = 0;
for (int i = 0; i <= SIZE - 1; i++)
{
stack1[i] = 0;
stack2[i] = 0;
}
tos1 = 0;
tos2 = 0;
col = 0;
row = 0;
}

### CreateBoard()

The function of the elements that are not a major route changes. This path can be easily detected.

public void CreateBoard()
{
for (int i = 0; i < 5; i++)
{
array[0, i] = 1;
array[i, 0] = 1;
array[5, i] = 1;
array[i, 5] = 1;
}
for (int i = 2; i < 5; i++)
array[1, i] = 1;
for (int i = 2; i < 5; i++)
array[2, i] = 1;
for (int i = 1; i < 4; i++)
array[4, i] = 1;
}

### PrintBoard()

This function displays the original array. The output is a function of the original array to display the presentation layer can be prepared.

public string PrintBoard()
{
string Temp = string.Empty;
for (int i = 1; i < 5; i++)
{
for (int j = 1; j < 5; j++)
Temp += " " + array[i, j];
Temp += "\r\n";
}
return Temp;
}

### Pushr()

This function takes a numeric value of the input and the value stored in the stack holding the row.

public void pushr(int cha)
{
if (tos1 == SIZE)
{
return;
}
stack1[tos1] = cha;
tos1++;
}

### popr()

This function returns the value stored in stack row.

public int popr()
{
if (tos1 == 0)
{
return -1;
}
tos1--;
return stack1[tos1];
}

### Pushc()

This function takes a numeric value and the value gained in the stack will store the holder.

public void pushc(int chb)
{
if (tos2 == SIZE)
{
return;
}
stack2[tos2] = chb;
tos2++;
}

### popc()

This function returns the value stored in stack row.

public int popc()
{
if (tos2 == 0)
{
return -1;
}
tos2--;
return stack2[tos2];
}

### cpopr()

This function returns the first row stack.

public int cpopr()
{
return stack1[tos1];
}

### cpopc()

This function returns the first column stack.

public int cpopc()
{
return stack2[tos2];
}

### set()

The function of the row and column array is initialized to the starting point.

public void set()
{
row = 1;
col = 1;
pushr(row);
pushc(col);
}

### Addr()

This function increases the value of the row.

public void addr()
{
row++;
}

### Addc()

This function increases the value of the column.

public void addc()
{
col++;
}

### minr()

This function reduces the amount of the row.

public void minr()
{
row--;
}

### minc()

This function reduces the amount of the column.

public void minc()
{
col--;
}

### checker()

This function checks the value of the next row. If the value was zero, then there is a path. The main board is also much lower than the marginal row columns.

public int checkar()
{
int a = 0;
a = row;
a++;
if ((array[a, col] == 0) && (a < max))
return 1;
else
return 0;
}

### checkac()

This function checks the next column. If the value was zero, then there is a path. It should also be much less than the row and column margins of the main board.

public int checkac()
{
int a = 0;
a = col;
a++;
if ((array[row, a] == 0) && (a < max))
return 1;
else
return 0;
}

### retr()

This function returns the row.

public int retr()
{
return row;
}

### retc()

This function returns the column value.

public int retc()
{
return col;
}

### printoutput()

This function returns the stack as the path traveled by the algorithm.

public string printOutPut()
{
string Temp = string.Empty;
for (int i = 0; tos1 != 0; i++)
Temp += popr() + " , " + popc() + "\r\n";
return Temp;
}

## Presentation Layer

This layer of rows and columns in the program decide the appropriate type of output data table is provided. In the first example of a Business and build on this prototype implements all operations. The variables are defined as needed.

The method `CreateBoard()`

and `set()`

for the main board and the amount of rows and columns is called. Two variables to keep track of the movements come in and out of the flag were created.

MazeBusiness maze = new MazeBusiness();
maze.CreateBoard();
lblOutPut3.Text = maze.PrintBoard();
maze.set();
int exit = 0, counter = 0;

In the next section a while - do we have to traverse the route. In this Loop according to the requirements stated in the first article examines the way there or not? Continue to stack rows and columns in the holder route and the route was not an appropriate message displays.

do
{
counter++;
if (maze.checkar() == 1)
{
maze.addr();
maze.pushr(maze.retr());
maze.pushc(maze.retc());
}
else
if (maze.checkac() == 1)
{
maze.addc();
maze.pushr(maze.retr());
maze.pushc(maze.retc());
}
else
if (maze.retr() == 4 && maze.retc() == 4)
{
exit = 1;
lblIsSolution.Text = "Resolved";
}
else
{
exit = 1;
lblIsSolution.Text = "Not resolved";
}
} while (maze.retr() != 5 && maze.retc() != 5 && exit == 0);
lblOutPut.Text = maze.printOutPut();
lblOutPut2.Text = counter.ToString();

Output at the end of the path traveled by the first display. Also traveled in the direction of motion can be solved and whether the route is displayed. The output is as shown below: