Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <random>
- #include <time.h>
- #define n 8
- using namespace std;
- enum status {clear, danger, position};
- struct queen
- {
- unsigned int y; //řadky
- unsigned int x; //sloupce
- };
- //int randomizer() { //
- //
- // int random_number;
- // random_number = rand() % n;
- //
- // return random_number;
- //}
- int main()
- {
- int pocet_dam = n;
- unsigned int i = 0;
- //vytvoření a připravení šachovnice, všechna pole jsou neohrožená (status clear, 0).
- status board[n+1][n+1];
- int column = 0, row = 0;
- for (row = 0; row < n; row++)
- {
- board[row][column] = (status)0;
- for (column = 0; column < n; column++)
- {
- board[row][column] = (status)0;
- }
- }
- // cout << "-----------------------------------" << endl;
- //
- // for (row = 0; row < n; row++)
- // {
- // cout << " | ";
- //
- // for (column = 0; column < n; column++)
- // {
- // cout << board[row][column] << " | ";
- // }
- // cout << endl;
- // cout << "-----------------------------------" << endl;
- // }
- // system("pause");
- // return 0;
- //}
- // zobrazeni šachovnice
- /*cout << "-----------------------------------" << endl;
- for (row = 0; row < n; row++)
- {
- cout << " | ";
- for (column = 0; column < n; column++)
- {
- cout << board[row][column] << " | ";
- }
- cout << endl;
- cout << "-----------------------------------" << endl;
- }*/
- //generování náhodné výchozí pozice pro 1. dámu + nastaveni stavů šachovnice
- queen q = { q.y = 7, q.x = 0};
- board[q.y][q.x] = (status)2;
- cout << (q.y)+1 << " " << (q.x)+1 << endl;
- for (i = 0; i < n; i++) //nastaveni stavu ohrožení pro sloupec dolů
- {
- if (board[q.y + i][q.x] != board[q.y][q.x])
- {
- board[q.y + i][q.x] = (status)1;
- }
- if (board[q.y + i][q.x] == board[n - 1][q.x])
- {
- break;
- }
- }
- for (i = 0; i < n; i++) //nastaveni stavu ohrožení pro sloupec nahoru
- {
- if (board[q.y - i][q.x] != board[q.y][q.x])
- {
- board[q.y - i][q.x] = (status)1;
- }
- if (board[q.y - i][q.x] == board[n - n][q.x])
- {
- break;
- }
- }
- for (i = 0; i < n; i++) // nastaveni stavu ohrožení pro řádek vpravo
- {
- if (board[q.y][q.x + i] != board[q.y][q.x])
- {
- board[q.y][q.x + i] = (status)1;
- }
- if (board[q.y][q.x + i] == board[q.y][n - 1])
- {
- break;
- }
- }
- for (i = 0; i < n; i++) // nastaveni stavu ohrožení pro řádek vlevo
- {
- if (board[q.y][q.x - i] != board[q.y][q.x])
- {
- board[q.y][q.x - i] = (status)1;
- }
- if (board[q.y][q.x - i] == board[q.y][n - n])
- {
- break;
- }
- }
- for (i = 0; i < n; i++) // nastaveni stavu ohrožení pro diagonálu vlevo nahoru
- {
- if (board[q.y - i][q.x - i] != board[q.y][q.x])
- {
- board[q.y - i][q.x - i] = (status)1;
- }
- 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]))
- {
- for (int j = 0; j < n; j++) // nastaveni stavu ohrožení pro diagonálu vpravo dolů
- {
- if (board[q.y + j][q.x + j] != board[q.y][q.x])
- {
- board[q.y + j][q.x + j] = (status)1;
- }
- 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]))
- {
- break;
- }
- }
- }
- }
- cout << "-----------------------------------" << endl;
- for (row = 0; row < n; row++)
- {
- cout << " | ";
- for (column = 0; column < n; column++)
- {
- cout << board[row][column] << " | ";
- }
- cout << endl;
- cout << "-----------------------------------" << endl;
- }
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment