Problem p00037 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define X first
#define Y second
#define WIDTH 8
#define HEIGHT 8

using namespace std;

struct point {
  point(int x = 0, int y = 0, char dir = 'R') : x(x), y(y), dir(dir) {}
  int x;
  int y;
  char dir;
};

char moveMap(vector<string> &map, point &player) {
  switch (player.dir) {
  case 'R':
    if (player.y != 0 && map[player.y - 1][player.x + 1] == '1') {
      player.y -= 1;
      player.x += 1;
      player.dir = 'U';
    } else if (player.x != map[player.y].size() - 1 &&
               map[player.y][player.x + 1] == '1') {
      player.x += 1;
    } else if (player.y != 8 && map[player.y + 1][player.x + 1] == '1') {
      player.y += 1;
      player.x += 1;
      player.dir = 'D';
    } else
      player.dir = 'L';
    break;
  case 'L':
    if (player.y != 8 && map[player.y + 1][player.x] == '1') {
      player.y += 1;
      player.dir = 'D';
    } else if (player.x != 0 && map[player.y][player.x - 1] == '1') {
      player.x -= 1;
    } else if (player.y != 0 && map[player.y - 1][player.x] == '1') {
      player.y -= 1;
      player.dir = 'U';
    } else
      player.dir = 'R';
    break;
  case 'U':
    if (player.x != 0 && map[player.y - 1][player.x - 1] == '1') {
      player.y -= 1;
      player.x -= 1;
      player.dir = 'L';
    } else if (player.y != 1 && map[player.y - 2][player.x] == '1') {
      player.y -= 2;
    } else if (player.x != map[player.y].size() - 1 &&
               map[player.y - 1][player.x] == '1') {
      player.y -= 1;
      player.dir = 'R';
    } else
      player.dir = 'D';
    break;
  case 'D':
    if (player.x != map[player.y].size() - 1 &&
        map[player.y + 1][player.x] == '1') {
      player.y += 1;
      player.dir = 'R';
    } else if (player.y != 7 && map[player.y + 2][player.x] == '1') {
      player.y += 2;
    } else if (player.x != 0 && map[player.y + 1][player.x - 1] == '1') {
      player.y += 1;
      player.x -= 1;
      player.dir = 'L';
    } else
      player.dir = 'U';
    break;
  default:
    break;
  }
  return player.dir;
}

int main() {
  string tmp;
  while (cin >> tmp) {
    if (cin.eof())
      break;

    vector<string> map;
    map.push_back(tmp);
    for (int i = 1; i < 9; i++) {
      cin >> tmp;
      map.push_back(tmp);
    }

    point player(0, 0, 'R');
    string root;
    root.push_back('R');

    while (1) {
      root.push_back(moveMap(map, player));
      if (player.x == 0 && player.y == 0)
        break;
    }

    for (int i = 0; i < root.size(); i++) {
      cout << root[i];
    }
    cout << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <vector>

#define X first
#define Y second
#define WIDTH 8
#define HEIGHT 8

using namespace std;

struct point {
  point(int x = 0, int y = 0, char dir = 'R') : x(x), y(y), dir(dir) {}
  int x;
  int y;
  char dir;
};

char moveMap(vector<string> &map, point &player) {
  switch (player.dir) {
  case 'R':
    if (player.y != 0 && map[player.y - 1][player.x + 1] == '1') {
      player.y -= 1;
      player.x += 1;
      player.dir = 'U';
    } else if (player.x != map[player.y].size() - 1 &&
               map[player.y][player.x + 1] == '1') {
      player.x += 1;
    } else if (player.y != 8 && map[player.y + 1][player.x + 1] == '1') {
      player.y += 1;
      player.x += 1;
      player.dir = 'D';
    }
    break;
  case 'L':
    if (player.y != 8 && map[player.y + 1][player.x] == '1') {
      player.y += 1;
      player.dir = 'D';
    } else if (player.x != 0 && map[player.y][player.x - 1] == '1') {
      player.x -= 1;
    } else if (player.y != 0 && map[player.y - 1][player.x] == '1') {
      player.y -= 1;
      player.dir = 'U';
    }
    break;
  case 'U':
    if (player.x != 0 && map[player.y - 1][player.x - 1] == '1') {
      player.y -= 1;
      player.x -= 1;
      player.dir = 'L';
    } else if (player.y != 1 && map[player.y - 2][player.x] == '1') {
      player.y -= 2;
    } else if (player.x != map[player.y].size() - 1 &&
               map[player.y - 1][player.x] == '1') {
      player.y -= 1;
      player.dir = 'R';
    }
    break;
  case 'D':
    if (player.x != map[player.y].size() - 1 &&
        map[player.y + 1][player.x] == '1') {
      player.y += 1;
      player.dir = 'R';
    } else if (player.y != 7 && map[player.y + 2][player.x] == '1') {
      player.y += 2;
    } else if (player.x != 0 && map[player.y + 1][player.x - 1] == '1') {
      player.y += 1;
      player.x -= 1;
      player.dir = 'L';
    }
    break;
  default:
    break;
  }
  return player.dir;
}

int main() {
  string tmp;
  while (cin >> tmp) {
    if (cin.eof())
      break;

    vector<string> map;
    map.push_back(tmp);
    for (int i = 1; i < 9; i++) {
      cin >> tmp;
      map.push_back(tmp);
    }

    point player(0, 0, 'R');
    string root;
    root.push_back('R');

    while (1) {
      root.push_back(moveMap(map, player));
      if (player.x == 0 && player.y == 0)
        break;
    }

    for (int i = 0; i < root.size(); i++) {
      cout << root[i];
    }
    cout << endl;
  }
  return 0;
}