Kibor Bot Autoclicker » Kibor - Integrated development environment for bots » About Kibor » Version 5.25 Finding the shortest path in the labyrinth

Страниц (1): [1]
 

1. Kibor - 24 Июля, 2018 - 04:06:57 - перейти к сообщению
In this version there is a function that allows you to find the shortest path in the labyrinth.

findpath (# labirint [0] [0], #pyt [0] [0], sizeX, sizeY)
The first parameter is a pointer to a two-dimensional array int in which a labyrinth is written in the form:
0 - free pass
1 - wall
2 - start
3 - finish

The second parameter is a pointer to a two-dimensional array int in which the shortest path is written in the form of a numbering from 0 (start) to the finish position inclusive:
0 1 2 3 4 5 and so on.
-1 is the rest of the labyrinth field

The third is the size of the labyrinth in X
The fourth is the size of the labyrinth by Y

The allocated memory for the first and second parameter can be larger than the size of the labyrinth.

Returns the function number of steps.
-1 if the size of the maze is more than allocated to the memory in the arrays.
0 - if there is no path.

========================

The arrays of the labyrinth and result are filled in correspondence:
First index X
Second Y.
Zero index is in the upper left corner of the labyrinth



Example:
There is this labyrinth. They are written in our file in this form:
 Цитата:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 0 0 0 0 0 1 1 1 0 0 3 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 0 0 1 1 1 1 1 1 1 0 1 0 1 1 0 1 0 0 0 0 0 0 1 1 1 0 1 1 1 1 1
1 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 0 1 1 1 1 1
1 1 2 1 1 1 1 1 1 1 1 0 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 0 1 1 0 0 0
1 1 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0
1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 0 0 0 1 1 1 1 1 0 1 1 1 1 1
1 1 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1
1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1
1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1


The code reading the file of the labyrinth and finding the shortest path:
CODE:
int labirint [330] [11];
int pyt [330] [11];
int sizeX=33;
int sizeY=11;


if (fopen ("D:\map.txt", "r")!=0) // open the file for reading "r"
{// if opened
for (int y=0; y <sizeY; y ++)
{
for (int x=0; x <sizeX; x ++)
{
fread (labirint [x] [y]);
}
}
fclose (); // close the file
}


int k=findpath (#labirint [0] [0], #pyt [0] [0], sizeX, sizeY);
messagebox (k);

int xx=200, yy=200;
int n=0;
if (k> 0)
{

for (y=0; y <sizeY; y ++)
{
xx=200;
for (x=0; x <sizeX; x ++)
{
textout (n, xx, yy, format (pyt [x] [y]), 0);
n ++;
xx=xx + 25;
}
yy=yy + 25;
}
loop () sleep (10);
}



================================================== ===

Video demo analysis of the labyrinth of the picture, posk and drawing in a patch on it the shortest path.