fojtasd

Untitled

Dec 19th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <random>
  3. #include <time.h>
  4.  
  5. #define n 8
  6.  
  7. using namespace std;
  8.  
  9. enum status {clear, danger, position};
  10.  
  11. struct queen
  12. {
  13.     unsigned int y; //řadky
  14.     unsigned int x; //sloupce
  15. };
  16.  
  17.  
  18. //int randomizer() { //
  19. // 
  20. //  int random_number;
  21. //  random_number = rand() % n;
  22. //
  23. //  return random_number;
  24. //}
  25.  
  26. int main()
  27. {
  28.     int pocet_dam = n;
  29.     unsigned int i = 0;
  30.  
  31.     //vytvoření a připravení šachovnice, všechna pole jsou neohrožená (status clear, 0).
  32.  
  33.     status board[n+1][n+1];
  34.  
  35.     int column = 0, row = 0;
  36.  
  37.     for (row = 0; row < n; row++)
  38.     {
  39.         board[row][column] = (status)0;
  40.  
  41.         for (column = 0; column < n; column++)
  42.         {
  43.             board[row][column] = (status)0;
  44.         }
  45.     }
  46.  
  47. //  cout << "-----------------------------------" << endl;
  48. //
  49. //  for (row = 0; row < n; row++)
  50. //  {
  51. //      cout << " | ";
  52. //
  53. //      for (column = 0; column < n; column++)
  54. //      {
  55. //          cout << board[row][column] << " | ";
  56. //      }
  57. //      cout << endl;
  58. //      cout << "-----------------------------------" << endl;
  59. //  }
  60. //  system("pause");
  61. //  return 0;
  62. //}
  63.  
  64.     // zobrazeni šachovnice
  65.  
  66.     /*cout << "-----------------------------------" << endl;
  67.  
  68.     for (row = 0; row < n; row++)
  69.     {
  70.         cout << " | ";
  71.  
  72.         for (column = 0; column < n; column++)
  73.         {
  74.             cout << board[row][column] << " | ";
  75.         }
  76.         cout << endl;
  77.         cout << "-----------------------------------" << endl;
  78.     }*/
  79.    
  80.     //generování náhodné výchozí pozice pro 1. dámu + nastaveni stavů šachovnice
  81.  
  82.     queen q = { q.y = 7, q.x = 0};
  83.    
  84.     board[q.y][q.x] = (status)2;
  85.  
  86.  
  87.  
  88.     cout << (q.y)+1 << " " << (q.x)+1 << endl;
  89.  
  90.    
  91.     for (i = 0; i < n; i++) //nastaveni stavu ohrožení pro sloupec dolů
  92.     {
  93.        
  94.         if (board[q.y + i][q.x] != board[q.y][q.x])
  95.         {
  96.                 board[q.y + i][q.x] = (status)1;
  97.         }
  98.         if (board[q.y + i][q.x] == board[n - 1][q.x])
  99.         {
  100.             break;
  101.         }
  102.     }
  103.  
  104.     for (i = 0; i < n; i++) //nastaveni stavu ohrožení pro sloupec nahoru
  105.     {
  106.        
  107.         if (board[q.y - i][q.x] != board[q.y][q.x])
  108.         {
  109.                 board[q.y - i][q.x] = (status)1;
  110.         }
  111.         if (board[q.y - i][q.x] == board[n - n][q.x])
  112.         {
  113.             break;
  114.         }
  115.     }
  116.  
  117.     for (i = 0; i < n; i++) // nastaveni stavu ohrožení pro řádek vpravo
  118.     {
  119.         if (board[q.y][q.x + i] != board[q.y][q.x])
  120.         {
  121.             board[q.y][q.x + i] = (status)1;
  122.         }
  123.         if (board[q.y][q.x + i] == board[q.y][n - 1])
  124.         {
  125.             break;
  126.         }
  127.     }
  128.  
  129.     for (i = 0; i < n; i++) // nastaveni stavu ohrožení pro řádek vlevo
  130.     {
  131.         if (board[q.y][q.x - i] != board[q.y][q.x])
  132.         {
  133.             board[q.y][q.x - i] = (status)1;
  134.         }
  135.         if (board[q.y][q.x - i] == board[q.y][n - n])
  136.         {
  137.             break;
  138.         }
  139.     }
  140.  
  141.     for (i = 0; i < n; i++) // nastaveni stavu ohrožení pro diagonálu vlevo nahoru
  142.     {
  143.         if (board[q.y - i][q.x - i] != board[q.y][q.x])
  144.         {
  145.             board[q.y - i][q.x - i] = (status)1;
  146.         }
  147.         if ((board[q.y - i][q.x - i] == board[q.y - i][n - n]) || (board[q.y - i][q.x - i] == board[n - n][q.x - i]))
  148.         {
  149.             for (int j = 0; j < n; j++) // nastaveni stavu ohrožení pro diagonálu vpravo dolů
  150.             {
  151.                 if (board[q.y + j][q.x + j] != board[q.y][q.x])
  152.                 {
  153.                     board[q.y + j][q.x + j] = (status)1;
  154.                 }
  155.                 if ((board[q.y + j][q.x + j] == board[q.y + j][n - 1]) || (board[q.y + j][q.x + j] == board[n - 1][q.x + j]))
  156.                 {
  157.                     break;
  158.                 }
  159.             }
  160.         }
  161.     }
  162.  
  163.  
  164.    
  165.    
  166.  
  167.     cout << "-----------------------------------" << endl;
  168.  
  169.     for (row = 0; row < n; row++)
  170.     {
  171.         cout << " | ";
  172.  
  173.         for (column = 0; column < n; column++)
  174.         {
  175.             cout << board[row][column] << " | ";
  176.         }
  177.         cout << endl;
  178.         cout << "-----------------------------------" << endl;
  179.     }
  180.    
  181.  
  182.  
  183.    
  184.  
  185.  
  186.    
  187.    
  188.  
  189.     system("pause");
  190.     return 0;
  191.    
  192. }
Advertisement
Add Comment
Please, Sign In to add comment