Advertisement
Guest User

Untitled

a guest
May 24th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. struct Unit
  9. {
  10.     int id;
  11.     int level;
  12.     int x,y;
  13. };
  14.  
  15. struct Pos
  16. {
  17.     int x, y;
  18. };
  19.  
  20. int main()
  21. {
  22.     int numberMineSpots;
  23.     cin >> numberMineSpots; cin.ignore();
  24.     for (int i = 0; i < numberMineSpots; i++) {
  25.         int x;
  26.         int y;
  27.         cin >> x >> y; cin.ignore();
  28.     }
  29.  
  30.     // game loop
  31.     while (1) {
  32.        
  33.         int gold;
  34.         cin >> gold; cin.ignore();
  35.         int income;
  36.         cin >> income; cin.ignore();
  37.        
  38.         int opponentGold;
  39.         cin >> opponentGold; cin.ignore();
  40.         int opponentIncome;
  41.         cin >> opponentIncome; cin.ignore();
  42.        
  43.         vector<string> grid;
  44.         for (int i = 0; i < 12; i++) {
  45.             string line;
  46.             cin >> line; cin.ignore();
  47.             grid.push_back(line);
  48.         }
  49.        
  50.         Pos enemyHQ;
  51.         int buildingCount;
  52.         cin >> buildingCount; cin.ignore();
  53.         for (int i = 0; i < buildingCount; i++) {
  54.             int owner;
  55.             int buildingType;
  56.             int x;
  57.             int y;
  58.             cin >> owner >> buildingType >> x >> y; cin.ignore();
  59.            
  60.             if(owner == 1 && buildingType == 0)
  61.             {
  62.                 enemyHQ.x = x;
  63.                 enemyHQ.y = y;
  64.             }
  65.         }
  66.        
  67.         vector<Unit> units;
  68.         int unitCount;
  69.         cin >> unitCount; cin.ignore();
  70.         for (int i = 0; i < unitCount; i++) {
  71.             int owner;
  72.             int unitId;
  73.             int level;
  74.             int x;
  75.             int y;
  76.             cin >> owner >> unitId >> level >> x >> y; cin.ignore();
  77.            
  78.             if(owner == 0)
  79.             {
  80.                 units.push_back({unitId, level, x, y});
  81.             }
  82.         }
  83.  
  84.         cout << "WAIT";
  85.        
  86.         for(int i = 0; i < units.size(); i++)
  87.         {
  88.             cout << ";MOVE " << units[i].id << " " << enemyHQ.x << " " << enemyHQ.y;
  89.         }
  90.        
  91.         for(int i = 0; i < 12; i++)
  92.         {
  93.             for(int j = 0; j < 12; j++)
  94.             {
  95.                 if(grid[i][j] == 'O')
  96.                 {
  97.                     int tempX = j + 1;
  98.                     int tempY = i;
  99.                    
  100.                     if(tempX < 12 && grid[tempY][tempX] == '.' && gold >= 10)
  101.                     {
  102.                         cout << ";TRAIN 1 " << tempX << " " << tempY;
  103.                         grid[tempY][tempX] == 'O';
  104.                         gold -= 10 ;
  105.                     }
  106.                    
  107.                     tempX = j - 1;
  108.                     tempY = i;
  109.                    
  110.                     if(tempX >= 0 && grid[tempY][tempX] == '.' && gold >= 10)
  111.                     {
  112.                         cout << ";TRAIN 1 " << tempX << " " << tempY;
  113.                         grid[tempY][tempX] == 'O';
  114.                         gold -= 10 ;
  115.                     }
  116.                    
  117.                     tempX = j;
  118.                     tempY = i - 1;
  119.                    
  120.                     if(tempY >= 0 && grid[tempY][tempX] == '.' && gold >= 10)
  121.                     {
  122.                         cout << ";TRAIN 1 " << tempX << " " << tempY;
  123.                         grid[tempY][tempX] == 'O';
  124.                         gold -= 10 ;
  125.                     }
  126.                    
  127.                     tempX = j;
  128.                     tempY = i + 1;
  129.                    
  130.                     if(tempY < 12 && grid[tempY][tempX] == '.' && gold >= 10)
  131.                     {
  132.                         cout << ";TRAIN 1 " << tempX << " " << tempY;
  133.                         grid[tempY][tempX] == 'O';
  134.                         gold -= 10 ;
  135.                     }
  136.                 }
  137.             }
  138.         }
  139.        
  140.         cout << endl;
  141.     }
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement