Advertisement
heroys6

Chess/8_Queens

Oct 11th, 2015
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4.  
  5. #define Q "$"
  6. #define Fil "."
  7.  
  8. struct cell {
  9.     int x, y;
  10.     int imp;
  11.     cell() { x = -1; y = -1; imp = 0;}
  12. };
  13.  
  14. cell toDraw[8];
  15.  
  16. bool draw_now(int x, int y)
  17. {
  18.     for (int i = 0; i < 7; i++)
  19.         if (toDraw[i].x == x && toDraw[i].y == y) return true;
  20.     return false;
  21. }
  22.  
  23. void draw_board()
  24. {
  25.     int funcX = 0, funcY = 0;
  26.  
  27.     // Top board edge
  28.     cout << "\n\t";
  29.  
  30.     cout << (char)218;
  31.     for (int i = 0; i < 7; i++)
  32.         cout << (char)196 << (char)194;
  33.     cout << (char)196 << (char)191;
  34.  
  35.     cout << "\n\t";
  36.  
  37.     for (int i = 0; i < 7; i++) {
  38.         // Base of every string
  39.         cout << (char)179;
  40.         for (int i = 0; i < 7; i++) {
  41.             if (draw_now(funcX, funcY)) cout << Q;
  42.             else cout << Fil;
  43.             cout << (char)179;
  44.             funcX++;
  45.         }
  46.         if (draw_now(funcX, funcY)) cout << Q;
  47.             else cout << Fil;
  48.         cout << (char)179;
  49.         funcX = 0;
  50.  
  51.         cout << "\n\t";
  52.  
  53.         cout << (char)195;
  54.         for (int i = 0; i < 7; i++)
  55.             cout << (char)196 << (char)197;
  56.         cout << (char)196 << (char)180;
  57.  
  58.         cout << "\n\t";
  59.         funcY++;
  60.     }
  61.  
  62.     // Last string
  63.     cout << (char)179;
  64.     for (int i = 0; i < 7; i++) {
  65.         if (draw_now(funcX, funcY)) cout << Q;
  66.             else cout << Fil;
  67.         cout << (char)179;
  68.         funcX++;
  69.     }
  70.     if (draw_now(funcX, funcY)) cout << Q;
  71.         else cout << Fil;
  72.     cout << (char)179;
  73.  
  74.     cout << "\n\t";
  75.  
  76.     // Bottom board edge
  77.     cout << (char)192;
  78.     for (int i = 0; i < 7; i++)
  79.         cout << (char)196 << (char)193;
  80.     cout << (char)196 << (char)217;
  81.  
  82.     cout << "\n";
  83. }
  84.  
  85. int main()
  86. {
  87.     cell board[8][8];
  88.  
  89.     for (int i = 0; i < 8; i++)
  90.         for (int j = 0; j < 8; j++) {
  91.             board[i][j].x = i;
  92.             board[i][j].y = j;
  93.         }
  94.  
  95.     toDraw[2].x = 3;
  96.     toDraw[2].y = 4;
  97.  
  98.     toDraw[0].x = 1;
  99.     toDraw[0].y = 2;
  100.  
  101.     cout << "\nChess board. " << Q << " - Queen: ";
  102.  
  103.     draw_board();
  104.  
  105.     cout << "\n";
  106.     system("pause");
  107.     return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement