Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.95 KB | None | 0 0
  1. #include <iostream>
  2. #include <conio.h>
  3.  
  4. using namespace std;
  5.  
  6. const int width = 8;
  7. const int height = 8;
  8.  
  9. struct Moves
  10. {
  11.     int dRow;
  12.     int dCol;
  13. };
  14.  
  15. struct Location
  16. {
  17.     int row;
  18.     int col;
  19. };
  20.  
  21. int ArrWeight[width][height] = { 0 };
  22. int Arr[width][height] = { 0 };
  23. void printArray(int mas[][width]);
  24. Moves moves[8] = { Moves{ 2,1 }, Moves{ 2,-1 }, Moves{ -2,1 }, Moves{ -2,-1 }, Moves{ 1,2 }, Moves{ 1,-2 }, Moves{ -1,2 }, Moves{ -1,-2 } };
  25. void sdfa();
  26. void makeMove(Location *pHorse);
  27. bool checkMove(Location *pHorse, int move);
  28. Location Add(Location pHorse, Location move);
  29.  
  30. int main()
  31. {  
  32.     Location horse{ 0,0 };
  33.     cout << horse.row << " " << horse.col << endl;
  34.    
  35.     //printArray(Arr);
  36.     cout << checkMove(&horse, 1) << endl;
  37.     cout << horse.row << " " << horse.col << endl;
  38.     sdfa();
  39.     printArray(ArrWeight);
  40.  
  41.  
  42.     _getch();
  43. }
  44.  
  45.  
  46.  
  47. void printArray(int mas[][width])
  48. {
  49.     for (int row = 0; row < width; row++)
  50.     {
  51.         for (int col = 0; col < height; col++)
  52.         {
  53.             cout << mas[row][col];
  54.         }
  55.         cout << "\n";
  56.     }
  57.     cout << "\n";
  58. }
  59.  
  60. void makeMove(Location *pHorse)
  61. {
  62.    
  63. }
  64. void sdfa()
  65. {
  66.     int weight = 0;
  67.     //int i = 0, j = 0;
  68.     for (int i = 0; i <= 7; i++)
  69.     {
  70.         for (int j = 0; j <= 7; j++)
  71.         {
  72.             Location *s = new Location{ i, j };
  73.             for (int k = 0; k <= 7; k++)
  74.             {
  75.                 if (checkMove(s, k) == true)
  76.                 {
  77.                     weight++;
  78.                 }
  79.             }
  80.             delete s;
  81.             ArrWeight[i][j] = weight;
  82.             weight = 0;
  83.         }
  84.     }
  85. }
  86.  
  87.  
  88. bool checkMove(Location *pHorse, int move)
  89. {
  90.     if (pHorse->col + moves[move].dCol < 8 && pHorse->col + moves[move].dCol >= 0 && pHorse->row + moves[move].dRow < 8 && pHorse->row + moves[move].dRow >= 0)
  91.     {
  92.         Location *temp = new Location{ moves[move].dCol, moves[move].dRow };
  93.         if (Arr[Add(*pHorse, *temp).col][Add(*pHorse, *temp).row] != 1)
  94.         {
  95.             return true;
  96.         }
  97.     }
  98.     return false;
  99. }
  100. Location Add(Location pHorse, Location move)
  101. {
  102.     Location temp ={ pHorse.col + move.col, pHorse.row + move.row };
  103.     return temp;
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement