G
G
Garenka2022-04-02 15:45:48
Python
Garenka, 2022-04-02 15:45:48

How to solve a logical problem with the movement of the robot?

Hello, dear forum users! The bottom line is this: You need to solve the problem with the movement of the robot by sequentially attaching blocks with commands (see photo).
624844d85ecfd784474323.png
624844e041cb4999277516.png
624844e7480be529933456.png
Here is the condition of the problem: "The rover is somewhere in the maze. This is a rectangle in which there are only horizontal walls with passages. The rover needs to be in the upper left cell and paint it (and only it) - this is a signal that he has passed the maze. "
The solution should be universal for any similar task. Here are two options for the maze (see photo)
62484522b5694493831088.png
6248452cdc6f9518035195.png
I have some sketches, but sometimes they just don't work without explanation. Help me please

Answer the question

In order to leave comments, you need to log in

3 answer(s)
W
Wataru, 2022-04-02
@Garenka

You need to somehow understand that the rover is already in the top row. Since the coordinates on the field, judging by the condition, cannot be obtained, you can use the fact that the top row is the only one that does not have a passage to the top.
You need to drive the rover to the right until it hits the wall, then drive it to the left and try to go up until it hits the wall on the left. As soon as you find a passage up, you need to go there and start over. If the robot rested against the wall on the left, then this is the end.
Something like this

while (no wall_from_right) {
  move_right;
}
while (no wall_from_left or no wall_from_up) {
  if (no wall_from_up) {
   move_up;
   while (no wall_from_right)
     move_right;
  } else {
   move_left;
  }
}
fill;

Large cycle invariant - all cells to the right of the robot have a wall up. That is why before the cycle it is necessary to walk to the right until it stops. In the cycle, the robot either goes to the next cell on the left, or goes up and goes to the right until it stops. If the robot hits the wall on the left and it is impossible to go up, then the current row is the top one and you can paint the cage.
You can implement the function Go_right_to_stop. It can take out a repeating cycle with steps to the right.

A
alexbprofit, 2022-04-02
@alexbprofit

i would look towards
https://github.com/pystage/pystage

I
Ivan Chetchasov, 2022-04-02
@TalismanChet

perhaps something like this:

начало

кон = ложь

пока не кон:
    для напр из {ЛЕВО, ПРАВО, ВЕРХ, НИЗ}:
        если путь(напр):
            двиг(напр)
            закончить
    если позиция = цель:
        кон = истина
закрасить

конец.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question