Advertisement
Guest User

Untitled

a guest
May 25th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.37 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. //struktura
  16. struct Grid
  17. {
  18.     char state;
  19.     int level = 0;
  20. };
  21.  
  22. struct Pos
  23. {
  24.     int x, y;
  25. };
  26.  
  27. int level;
  28.  
  29. int main()
  30. {
  31.     int numberMineSpots;
  32.     cin >> numberMineSpots; cin.ignore();
  33.     for (int i = 0; i < numberMineSpots; i++) {
  34.         int x;
  35.         int y;
  36.         cin >> x >> y; cin.ignore();
  37.     }
  38.  
  39.     // game loop
  40.     while (1) {
  41.        
  42.         int gold;
  43.         cin >> gold; cin.ignore();
  44.         int income;
  45.         cin >> income; cin.ignore();
  46.        
  47.         int opponentGold;
  48.         cin >> opponentGold; cin.ignore();
  49.         int opponentIncome;
  50.         cin >> opponentIncome; cin.ignore();
  51.        
  52.         vector<vector<Grid>> grid; //pakeiciau
  53.         for (int i = 0; i < 12; i++) {
  54.             string line;
  55.             cin >> line; cin.ignore();
  56.             grid.push_back({}); //pakeiciau
  57.             for(int j = 0; j < 12; j++)//pakeiciau
  58.             {
  59.                 grid[i].push_back({line[j], 0});//pakeiciau
  60.             }
  61.         }
  62.        
  63.         Pos enemyHQ;
  64.         int buildingCount;
  65.         cin >> buildingCount; cin.ignore();
  66.         for (int i = 0; i < buildingCount; i++) {
  67.             int owner;
  68.             int buildingType;
  69.             int x;
  70.             int y;
  71.             cin >> owner >> buildingType >> x >> y; cin.ignore();
  72.            
  73.             if(owner == 1 && buildingType == 0)
  74.             {
  75.                 enemyHQ.x = x;
  76.                 enemyHQ.y = y;
  77.             }
  78.         }
  79.        
  80.         vector<Unit> units;
  81.         vector<Unit> enUnits; //pakeiciau
  82.         int unitCount;
  83.         cin >> unitCount; cin.ignore();
  84.         for (int i = 0; i < unitCount; i++) {
  85.             int owner;
  86.             int unitId;
  87.             int level;
  88.             int x;
  89.             int y;
  90.             cin >> owner >> unitId >> level >> x >> y; cin.ignore();
  91.            
  92.             if(owner == 0)
  93.             {
  94.                 units.push_back({unitId, level, x, y});
  95.                
  96.             }
  97.             else
  98.             {
  99.                 enUnits.push_back({unitId, level, x, y}); //pakeiciau
  100.                 grid[y][x].level = level; //pakeiciau
  101.             }
  102.                
  103.         }
  104.  
  105.         cout << "WAIT";
  106.        
  107.         for(int i = 0; i < units.size(); i++)
  108.         {
  109.             cout << ";MOVE " << units[i].id << " " << enemyHQ.x << " " << enemyHQ.y;
  110.         }
  111.        
  112.         for(int i = 0; i < 12; i++)
  113.         {
  114.             for(int j = 0; j < 12; j++)
  115.             {
  116.                 if(grid[i][j] == 'O')
  117.                 {
  118.                     int tempX = j + 1;
  119.                     int tempY = i;
  120.                    
  121.                     if(tempX < 12 && (grid[tempY][tempX].state == '.' || grid[tempY][tempX] == 'x' || grid[tempY][tempX] == 'X' )  && gold >= 10 && level <= 1 )
  122.                     {
  123.                         cout << ";TRAIN 1 " << tempX << " " << tempY;
  124.                         grid[tempY][tempX] == 'O';
  125.                         gold -= 10 ;
  126.                        
  127.                     }
  128.                     else if(tempX < 12 && (grid[tempY][tempX] == '.' || grid[tempY][tempX] == 'x' || grid[tempY][tempX] == 'X' )  && gold >= 20 && level == 1 ) {
  129.                              cout << ";TRAIN 2 " << tempX << " " << tempY;
  130.                         grid[tempY][tempX] == 'O';
  131.                         gold -= 20 ;
  132.                             }
  133.                             else if(tempX < 12 && (grid[tempY][tempX] == '.' || grid[tempY][tempX] == 'x' || grid[tempY][tempX] == 'X' )  && gold >= 30 && level >= 2 ) {
  134.                              cout << ";TRAIN 3 " << tempX << " " << tempY;
  135.                         grid[tempY][tempX] == 'O';
  136.                         gold -= 30 ;
  137.                             }  
  138.                    
  139.                     tempX = j - 1;
  140.                     tempY = i;
  141.                    
  142.                     if(tempX >= 0 && (grid[tempY][tempX] == '.' || grid[tempY][tempX] == 'x' || grid[tempY][tempX] == 'X' ) && gold >= 10 && level <= 1)
  143.                     {
  144.                         cout << ";TRAIN 1 " << tempX << " " << tempY;
  145.                         grid[tempY][tempX] == 'O';
  146.                         gold -= 10 ;
  147.                     }
  148.                      else if(tempX >= 0 && (grid[tempY][tempX] == '.' || grid[tempY][tempX] == 'x' || grid[tempY][tempX] == 'X' )  && gold >= 20 && level == 1 ) {
  149.                              cout << ";TRAIN 2 " << tempX << " " << tempY;
  150.                         grid[tempY][tempX] == 'O';
  151.                         gold -= 20 ;
  152.                             }
  153.                             else if(tempX >= 0 && (grid[tempY][tempX] == '.' || grid[tempY][tempX] == 'x' || grid[tempY][tempX] == 'X' )  && gold >= 30 && level >= 2 ) {
  154.                              cout << ";TRAIN 3 " << tempX << " " << tempY;
  155.                         grid[tempY][tempX] == 'O';
  156.                         gold -= 30 ;
  157.                             }  
  158.                    
  159.                     tempX = j;
  160.                     tempY = i - 1;
  161.                    
  162.                     if(tempY >= 0 && (grid[tempY][tempX] == '.' || grid[tempY][tempX] == 'x' || grid[tempY][tempX] == 'X' ) && gold >= 10 && level <= 1)
  163.                     {
  164.                         cout << ";TRAIN 1 " << tempX << " " << tempY;
  165.                         grid[tempY][tempX] == 'O';
  166.                         gold -= 10 ;
  167.                     }
  168.                      else if(tempY >= 0 && (grid[tempY][tempX] == '.' || grid[tempY][tempX] == 'x' || grid[tempY][tempX] == 'X' )  && gold >= 20 && level == 1 ) {
  169.                              cout << ";TRAIN 2 " << tempX << " " << tempY;
  170.                         grid[tempY][tempX] == 'O';
  171.                         gold -= 20 ;
  172.                             }
  173.                             else if(tempY >= 0 && (grid[tempY][tempX] == '.' || grid[tempY][tempX] == 'x' || grid[tempY][tempX] == 'X' )  && gold >= 30 && level >= 2 ) {
  174.                              cout << ";TRAIN 3 " << tempX << " " << tempY;
  175.                         grid[tempY][tempX] == 'O';
  176.                         gold -= 30 ;
  177.                             }  
  178.                    
  179.                     tempX = j;
  180.                     tempY = i + 1;
  181.                    
  182.                     if(tempY < 12 && (grid[tempY][tempX] == '.' || grid[tempY][tempX] == 'x' || grid[tempY][tempX] == 'X' ) && gold >= 10 && level <= 1)
  183.                     {
  184.                         cout << ";TRAIN 1 " << tempX << " " << tempY;
  185.                         grid[tempY][tempX] == 'O';
  186.                         gold -= 10 ;
  187.                     }
  188.                     else if(tempY < 12 && (grid[tempY][tempX] == '.' || grid[tempY][tempX] == 'x' || grid[tempY][tempX] == 'X' )  && gold >= 20 && level == 1 ) {
  189.                              cout << ";TRAIN 2 " << tempX << " " << tempY;
  190.                         grid[tempY][tempX] == 'O';
  191.                         gold -= 20 ;
  192.                             }
  193.                             else if(tempY < 12 && (grid[tempY][tempX] == '.' || grid[tempY][tempX] == 'x' || grid[tempY][tempX] == 'X' )  && gold >= 30 && level >= 2) {
  194.                              cout << ";TRAIN 3 " << tempX << " " << tempY;
  195.                         grid[tempY][tempX] == 'O';
  196.                         gold -= 30 ;
  197.                             }  
  198.                 }
  199.             }
  200.         }
  201.        
  202.         cout << endl;
  203.     }
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement