Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void turnLeft(char *p) { //ПОВОРОТ (РЕГУЛИРУЕТ НАПРАВЛЕНИЕ ВЗГЛЯДА
- if (*p =='u') {
- *p = 'l';
- } else if (*p == 'l') {
- *p = 'd';
- } else if (*p == 'd') {
- *p = 'r';
- } else if (*p == 'r') {
- *p = 'u';
- }
- }
- void turnRight(char *p) { //ПОВОРОТ (РЕГУЛИРУЕТ НАПРАВЛЕНИЕ ВЗГЛЯДА
- if (*p =='u') {
- *p = 'r';
- } else if (*p == 'r') {
- *p = 'd';
- } else if (*p == 'd') {
- *p = 'l';
- } else if (*p == 'l') {
- *p = 'u';
- }
- }
- void go(int *x, int *y, char *d) { //ФУНКЦИЯ ШАГА ПО НАПРАВЛЕНИЮ ВЗГЛЯДА
- if (*d=='u') {
- *y--;
- } else if (*d=='r') {
- *x++;
- } else if (*d=='l') {
- *x--;
- } else if (*d=='d') {
- *y++;
- }
- }
- int main() {
- char a[13][13] = {
- '*','*','*','*','*','*','*','*','*','*','*','*','*',
- '*','*','*','*','*','*','*','!','*','*','*','0','*',
- '*','*','*','*','*','*','*','0','*','*','*','0','*',
- '*','*','*','*','*','0','0','0','*','0','*','0','*',
- '*','0','0','0','0','0','*','*','*','0','0','0','*',
- '*','0','*','*','*','0','*','*','*','0','*','*','*',
- '*','0','*','*','*','0','0','0','0','0','*','*','*', //КАРТА ЛАБИРИНТА!!!
- '*','0','*','0','0','0','*','*','*','*','*','*','*',
- '*','0','*','0','*','*','*','0','0','0','*','*','*',
- '*','*','*','0','*','*','*','0','*','0','*','*','*',
- '*','0','0','0','*','0','0','0','*','0','*','*','*',
- '*','0','*','0','0','0','*','*','*','0','*','*','*',
- '*','*','*','*','*','*','*','*','*','*','*','*','*'};
- int x = 9; int *ptrx = &x;
- int y = 11; int *ptry = &y; //ДАННЫЕ РОБОТА!!!
- char d ='u'; char *ptrd = &d;
- a[y][x]='1'; //НАЧАЛЬНОЕ ПОЛОЖЕНИЕ РОБОТА (ТИПА РОБОТ ЭТО ЕДИНИЧКА)
- while (a[y][x] != '!') {
- while (d == 'u' && a[y-1][x] == '0' && a[y][x+1] == '*') { //ТУТ ПРОВЕРЯЕТСЯ УСЛОВИЯ ПРАВОЙ РУКИ В ЗАВИСИМОСТИ ОТ
- go(&x, &y, &d); //НАПРАВЛЕНИЯ ВЗГЛЯДА РОБОТА, И КАК ТОЛЬКО ВСТРЕЧАЕТСЯ
- a[x][y]='1'; //ПРЕПЯДСТВИЕ (НАПРИМЕР), ТО В ГЛАВНОМ ЦИКЛЕ СКИПАЮТСЯ
- a[x][y+1]='0'; //ВСЕ ВЛОЖНЫЕ ЦИКЛЫ, А РОБОТ ПОВОРАЧИВАЕТСЯ, А ПРИ
- } //СЛЕДУЮЩЕЙ ЭТАРАЦИИ ГЛАВНОГО ЦИКЛА ПОД НОВОЕ НАПРАВЛЕ
- while (d == 'l' && a[y][x-1] == '0' && a[y-1][x] == '*') { //НИЕ ВЗГЛЯДА ПОДБИРАЕТСЯ НОВЫЙ ВЛОЖНЫЙ ЦИКЛ, И ТАК, ПОКА
- go(&x, &y, &d); //НЕ НАЙДЕТСЯ ВЫХОД, т.е ГЛАВНОЕ УСЛОВИЕ ГЛАВНОГО ЦИКЛА
- a[x][y]='1';
- a[x+1][y]='0';
- }
- while (d == 'r' && a[y][x+1] == '0' && a[y+1][x] == '*') {
- go(&x, &y, &d);
- a[x][y]='1';
- a[x-1][y]='0';
- }
- while (d == 'd' && a[y+1][x] == '0' && a[y][x-1] == '*') {
- go(&x, &y, &d);
- a[x][y]='1';
- a[x][y-1]='0';
- }
- turnRight(&d);
- }
- for (int i = 0; i < 13; i++) {
- for (int j = 0; j < 13; j++) { //ОБРИСОВКА МАССИВА!!!
- cout << a[i][j];
- }
- cout <<""<<endl;
- }
- }//КОНЕЦ ПРОГРАММЫ!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement