Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Bruno.h"
- #include <bits/stdc++.h>
- using namespace std;
- namespace {
- vector<pair<int, int>> dirs = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 0}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};
- int locate(int j, int ci) {
- int py = ((j / 3) + (dirs[ci].first + 2)) % 3 - 1;
- int px = ((j % 3) + (dirs[ci].second + 2)) % 3 - 1;
- return 3*(py + 1) + (px + 1);
- }
- }
- vector<int> Bruno(int k, vector<int> value) {
- int ci = -1;
- for (int i = 0; i < 9; ++i) {
- if (value[i] == 1) ci = i;
- }
- int unused = value[locate(7, ci)] - 2;
- vector<int> res(k);
- for (int j = 0; j < k; ++j) {
- int py = ((j / 3) + (dirs[ci].first + 2)) % 3 - 1;
- int px = ((j % 3) + (dirs[ci].second + 2)) % 3 - 1;
- int code = value[locate(j, ci)];
- if (code >= 6 + unused) ++code;
- if (code == 2) res[j] = 3; // NORTH
- else if (code == 3) res[j] = 2; // SOUTH
- else if (code == 4) res[j] = 1; // WEST
- else if (code == 5) res[j] = 0; // EAST
- else {
- int ty = py + dirs[code - 6].first;
- int tx = px + dirs[code - 6].second;
- if (ty < 0) res[j] = 3; // NORTH
- else if (ty > 0) res[j] = 2; // SOUTH
- else if (tx < 0) res[j] = 1; // WEST
- else if (tx > 0) res[j] = 0; // EAST
- else {
- res[j] = 4; // Done :)
- }
- }
- }
- return res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement