Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- using namespace std;
- const int width = 8;
- const int height = 8;
- struct Moves
- {
- int dRow;
- int dCol;
- };
- struct Location
- {
- int row;
- int col;
- };
- int ArrWeight[width][height] = { 0 };
- int Arr[width][height] = { 0 };
- void printArray(int mas[][width]);
- 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 } };
- void sdfa();
- void makeMove(Location *pHorse);
- bool checkMove(Location *pHorse, int move);
- Location Add(Location pHorse, Location move);
- int main()
- {
- Location horse{ 0,0 };
- cout << horse.row << " " << horse.col << endl;
- //printArray(Arr);
- cout << checkMove(&horse, 1) << endl;
- cout << horse.row << " " << horse.col << endl;
- sdfa();
- printArray(ArrWeight);
- _getch();
- }
- void printArray(int mas[][width])
- {
- for (int row = 0; row < width; row++)
- {
- for (int col = 0; col < height; col++)
- {
- cout << mas[row][col];
- }
- cout << "\n";
- }
- cout << "\n";
- }
- void makeMove(Location *pHorse)
- {
- }
- void sdfa()
- {
- int weight = 0;
- //int i = 0, j = 0;
- for (int i = 0; i <= 7; i++)
- {
- for (int j = 0; j <= 7; j++)
- {
- Location *s = new Location{ i, j };
- for (int k = 0; k <= 7; k++)
- {
- if (checkMove(s, k) == true)
- {
- weight++;
- }
- }
- delete s;
- ArrWeight[i][j] = weight;
- weight = 0;
- }
- }
- }
- bool checkMove(Location *pHorse, int move)
- {
- 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)
- {
- Location *temp = new Location{ moves[move].dCol, moves[move].dRow };
- if (Arr[Add(*pHorse, *temp).col][Add(*pHorse, *temp).row] != 1)
- {
- return true;
- }
- }
- return false;
- }
- Location Add(Location pHorse, Location move)
- {
- Location temp ={ pHorse.col + move.col, pHorse.row + move.row };
- return temp;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement