Advertisement
Guest User

Bruno.cpp

a guest
Mar 23rd, 2021
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. #include "Bruno.h"
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. namespace {
  6.     vector<pair<int, int>> dirs = {{-1, -1}, {-1, 0}, {-1, 1}, {0, -1}, {0, 0}, {0, 1}, {1, -1}, {1, 0}, {1, 1}};
  7.    
  8.     int locate(int j, int ci) {
  9.         int py = ((j / 3) + (dirs[ci].first + 2)) % 3 - 1;
  10.         int px = ((j % 3) + (dirs[ci].second + 2)) % 3 - 1;
  11.         return 3*(py + 1) + (px + 1);
  12.  
  13.     }
  14. }
  15.  
  16. vector<int> Bruno(int k, vector<int> value) {
  17.     int ci = -1;
  18.     for (int i = 0; i < 9; ++i) {
  19.         if (value[i] == 1) ci = i;
  20.     }
  21.     int unused = value[locate(7, ci)] - 2;
  22.  
  23.     vector<int> res(k);
  24.     for (int j = 0; j < k; ++j) {
  25.         int py = ((j / 3) + (dirs[ci].first + 2)) % 3 - 1;
  26.         int px = ((j % 3) + (dirs[ci].second + 2)) % 3 - 1;
  27.         int code = value[locate(j, ci)];
  28.  
  29.         if (code >= 6 + unused) ++code;
  30.  
  31.         if (code == 2) res[j] = 3; // NORTH
  32.         else if (code == 3) res[j] = 2; // SOUTH
  33.         else if (code == 4) res[j] = 1; // WEST
  34.         else if (code == 5) res[j] = 0; // EAST
  35.         else {
  36.             int ty = py + dirs[code - 6].first;
  37.             int tx = px + dirs[code - 6].second;
  38.             if (ty < 0) res[j] = 3; // NORTH
  39.             else if (ty > 0) res[j] = 2; // SOUTH
  40.             else if (tx < 0) res[j] = 1; // WEST
  41.             else if (tx > 0) res[j] = 0; // EAST
  42.             else {
  43.                 res[j] = 4; // Done :)
  44.             }
  45.         }
  46.     }
  47.  
  48.     return res;
  49. }
  50.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement