Tranvick

Untitled

Apr 16th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.67 KB | None | 0 0
  1. double Calc(int x, int y, int map[111][111], int n, int w) {
  2.     double res = 0;
  3.     int t1 = 5, t2;
  4.     if (n == 3) t1 = 3;
  5.     t2 = t1 - 1;
  6.     for (int j = y - t2; j <= y; ++j) {
  7.         if (j < 0 || j + t2 >= n) continue;
  8.         int c = 1;
  9.         for (int t = 0; t < t1; ++t) {
  10.             if (!map[x][j + t]) continue;
  11.             if (map[x][j + t] != w) {
  12.                 c = 0;
  13.                 break;
  14.             } else ++c;
  15.         }
  16.         if (c == 1) c = 0;
  17.         if (c) res += pow(3.0, c + .0);
  18.         if (c == t1)
  19.             if (w == 2) res += 100000;
  20.             else res += 1000;
  21.     }
  22.     for (int i = x - t2; i <= x; ++i) {
  23.         if (i < 0 || i + t2 >= n) continue;
  24.         int c = 1;
  25.         for (int t = 0; t < t1; ++t) {
  26.             if (!map[i + t][y]) continue;
  27.             if (map[i + t][y] != w) {
  28.                 c = 0;
  29.                 break;
  30.             } else ++c;
  31.         }
  32.         if (c == 1) c = 0;
  33.         if (c) res += pow(3.0, c + .0);
  34.         if (c == t1)
  35.             if (w == 2) res += 100000;
  36.             else res += 1000;
  37.     }
  38.     for (int i = x - t2, j = y - t2; i <= x; ++i, ++j) {
  39.         if (i < 0 || j < 0 || i + t2 >= n || j + t2 >= n) continue;
  40.         int c = 1;
  41.         for (int t = 0; t < t1; ++t) {
  42.             if (!map[i + t][j + t]) continue;
  43.             if (map[i + t][j + t] != w) {
  44.                 c = 0;
  45.                 break;
  46.             } else ++c;
  47.         }
  48.         if (c == 1) c = 0;
  49.         if (c) res += pow(3.0, c + .0);
  50.         if (c == t1)
  51.             if (w == 2) res += 100000;
  52.             else res += 1000;
  53.     }
  54.     for (int i = x + t2, j = y - t2; i >= x; --i, ++j) {
  55.         if (i >= n || j < 0 || i - t2 < 0 || j + t2 >= n) continue;
  56.         int c = 1;
  57.         for (int t = 0; t < t1; ++t) {
  58.             if (!map[i - t][j + t]) continue;
  59.             if (map[i - t][j + t] != w) {
  60.                 c = 0;
  61.                 break;
  62.             } else ++c;
  63.         }
  64.         if (c == 1) c = 0;
  65.         if (c) res += pow(3.0, c + .0);
  66.         if (c == t1)
  67.             if (w == 2) res += 100000;
  68.             else res += 1000;
  69.     }
  70.     return res;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment