}

Home computer. Labyrinth

1986/10/01 Lizaso, Pili - Informatika SailaElhuyar Fundazioa Iturria: Elhuyar aldizkaria

This time, we will make a program that will help xagua to look for the exit to the labyrinth.

This time, we will make a program that will help xagua to look for the exit to the labyrinth. This program is written for Tele video, but can also be written for spectrum.

We will point out the labyrinth using an array. The obstacles will be indicated with a "1" and the free cells with a "Ø".

The entrance to the labyrinth (1.1) will be inert and the exit (m, n) will be the inert dimension, m and n. In this case we will use m=n=8.

The mouse will be defined with its position, that is, with the coordinates of the point or stack that is in the moment. Take note of what will always be in a Ø stack. In addition, it is necessary to define the possible guidelines that the handkerchief can have. The possible addresses are eight in all cells, except those on the edge. So for the behavior of xagua to be egalitarian everywhere, we will surround the labyrinth of obstacles. See how:

The change of coordinates for each direction is shown in the NORANTZA table (8.2):

Modifying the column coordinate to follow direction I NORANTZA (I,1)

Modification of the line coordinate to follow NORANTZA (I,2) I

Xagua will leave the entrance pile and pass from one point to another fleeing obstacles. When you cannot move forward, you will have to go back. Therefore, the path along the path leads us through the BIDEA table (64.3).

In each of the fields in this table will be saved:

    Coordinates of a pile that makes up the road
  • Sense of passage from this stack to another

When Xagua is in a pile of water, sobriety should be analyzed for a "good point." To make a stack a "good point" you must meet the following requirements:

    No obstacles (marked with Øen in the LAB table).
  • That the xagua does not pass through this pile (that the MARK is marked with Øen the table).

If you find between the eight points of the zone a point that meets these conditions, the coordinates of the current stack and the direction you should follow will be saved to move to the new point and will be passed to the new point. Here the same process will follow.

On the contrary, if after analyzing the eight points of the area you do not see the possibility of going to any point, you must go back, going to the first stack (the last stack introduced in the table BIDEA) and from here try another way. The process is repetitive. It will remain until one of these two situations:

    Departure location
  • Not back

In the first case, the path will appear marked in red. In the second, the message will be:

"There is no way!!"

As you may have seen, we have also mentioned the table called BRAND. In the following table we will be marking with a "1" to know which room the mocha has passed as we move it. If this is not done, it can be put into an endless softening.

An example will help you understand better: Suppose the modest (3.7) is in the inert, that the first "good point" that begins to study and find the cells of the area is the north (3.6). (3,7,2 north) is saved in the BIDEA table and passed to the point (3,6). Here you will do the same, but if after reviewing the adjacent cells you cannot move, you will have to go back, i.e. go back to point (3.7) and try the following address (norantza 3, northeast). Go on like this when you can go ahead and you cannot go back to the exit or check that there is no way.

Gai honi buruzko eduki gehiago

Elhuyarrek garatutako teknologia