Advertisement
Guest User

Codingame

a guest
Apr 5th, 2020
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.18 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. const int mapSize = 15;
  9.  
  10. bool inMap(string grid[],int x, int y)
  11. {
  12.     return x >=0 && x < mapSize && y >=0 && y < mapSize && grid[x][y] == '.';
  13. }
  14. int main()
  15. {
  16.    
  17.     string grid[mapSize];
  18.    
  19.     int width;
  20.     int height;
  21.     int myId;
  22.     cin >> width >> height >> myId; cin.ignore();
  23.     for (int i = 0; i < height; i++) {
  24.         string line;
  25.         getline(cin, line);
  26.         cerr<<line<<endl;
  27.         grid[i] = line;
  28.     }
  29.    
  30.     int xp, yp;
  31.    
  32.     for(int y = 0; y < mapSize; y++)
  33.     {
  34.         for(int x = 0; x < mapSize; x++)
  35.         {
  36.             if(grid [y][x] == '.')
  37.             {
  38.                 xp = x;
  39.                 yp = y;
  40.             }
  41.         }
  42.     }
  43.    
  44.     cout <<xp<< " "<<yp << endl;
  45.  
  46.     // game loop
  47.     while (1) {
  48.         int x;
  49.         int y;
  50.         int myLife;
  51.         int oppLife;
  52.         int torpedoCooldown;
  53.         int sonarCooldown;
  54.         int silenceCooldown;
  55.         int mineCooldown;
  56.         cin >> x >> y >> myLife >> oppLife >> torpedoCooldown >> sonarCooldown >> silenceCooldown >> mineCooldown; cin.ignore();
  57.         string sonarResult;
  58.         cin >> sonarResult; cin.ignore();
  59.         string opponentOrders;
  60.         getline(cin, opponentOrders);
  61.  
  62.         grid[y][x] = '?';
  63.  
  64.         if(inMap(grid, x, y-1))
  65.         {
  66.             cout << "MOVE N TORPEDO" << endl;
  67.         }
  68.         else if(inMap(grid, x+1, y))
  69.         {
  70.             cout << "MOVE E TORPEDO" << endl;
  71.         }
  72.         else if(inMap(grid, x, y+1))
  73.         {
  74.             cout << "MOVE S TORPEDO" << endl;
  75.         }
  76.         else if(inMap(grid, x-1, y))
  77.         {
  78.             cout << "MOVE w TORPEDO" << endl;
  79.         }
  80.         else
  81.         {
  82.             cout << "SURFACE" << endl;
  83.             for(int j = 4; j < 11; j++)
  84.             {
  85.                 for(int i = 4; i < 11; i++)
  86.                 {
  87.                    if(grid[j][i] == '?')
  88.                    {
  89.                        grid[j][i] = '.'
  90.                    }
  91.                 }
  92.             }    
  93.             grid[j][i] = '?'    
  94.             }
  95.         }
  96.     }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement