Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- //char checkWin(char arr[3][3])
- //{
- // char same{' '};
- // char sameD{ arr[0][0] };
- // int cnt{ 0 };
- // int cntD{ 0 };
- // int x;
- // int y;
- //
- // for (x = 0; x < 3; ++x)
- // {
- // for (y = 0, cnt = 0, same = arr[y][x]; y < 3; ++y)
- // {
- // //std::cout << "Same = " << same << '\n';
- // if (arr[y][x] != same)
- // {
- // //std::cout << same << " # " << arr[y][x] << '\n';
- // //break;
- // cnt = 0;
- // }
- // else
- // {
- // ++cnt;
- // std::cout << " cnt = " << cnt << '\n';
- // }
- //
- // if (x == y and arr[y][x] != sameD)
- // {
- // std::cout << sameD << " M " << arr[y][x] << '\n';
- // //break;
- // cntD = 0;
- // }
- // if (x == y and arr[y][x] == sameD)
- // {
- // ++cntD;
- // std::cout << " cntD = " << cntD << '\n';
- // }
- // }
- // if (cnt == 3 and same != ' ') { return same; };
- // if (cntD == 3 and sameD != ' ') { return same; };
- // }
- //
- // sameD = arr[0][2];
- // cntD = 0;
- //
- // for (y = 0; y < 3; ++y)
- // {
- // for (x = 0, cnt = 0, same = arr[y][x]; x < 3; ++x)
- // {
- // //std::cout << "Same = " << same << '\n';
- // if (arr[y][x] != same)
- // {
- // //std::cout << same << " # " << arr[y][x] << '\n';
- // //break;
- // cnt = 0;
- // }
- // else
- // {
- // ++cnt;
- // std::cout << " cnt = " << cnt << '\n';
- // }
- // if (x + y == 2 and arr[y][x] != sameD)
- // {
- // std::cout << sameD << " R " << arr[y][x] << '\n';
- // //break;
- // cntD = 0;
- // }
- // if (x + y == 2 and arr[y][x] == sameD)
- // {
- // ++cntD;
- // std::cout << " cntD = " << cntD << '\n';
- // }
- // }
- // if (cnt == 3 and same != ' ') { return same; };
- // if (cntD == 3 and sameD != ' ') { return same; };
- // }
- //
- //}
- char checkWin(char arr[3][3])
- {
- char same{ ' ' };
- char sameD{ arr[0][0] };
- int cnt{ 0 };
- int cntD{ 0 };
- int x{ 0 };
- int y{ 0 };
- for (x = 0; x < 3; ++x)
- {
- for (y = 0, cnt = 0, same = arr[y][x]; y < 3; ++y)
- {
- (arr[y][x] != same) ? cnt = 0 : ++cnt;
- if (x == y)
- {
- (arr[y][x] != sameD) ? cntD = 0 : ++cntD;
- }
- }
- if (cnt == 3 and same != ' ') { return same; };
- if (cntD == 3 and sameD != ' ') { return same; };
- }
- sameD = arr[0][2];
- cntD = 0;
- for (y = 0; y < 3; ++y)
- {
- for (x = 0, cnt = 0, same = arr[y][x]; x < 3; ++x)
- {
- (arr[y][x] != same) ? cnt = 0 : ++cnt;
- if (x + y == 2)
- {
- (arr[y][x] != sameD) ? cntD = 0 : ++cntD;
- }
- }
- if (cnt == 3 and same != ' ') { return same; };
- if (cntD == 3 and sameD != ' ') { return sameD; };
- }
- return 'Z';
- }
- int main()
- {
- //char field[3][3]{ {'x','o',' '}, {'x','o',' '} ,{'x',' ','o'} };
- //char field[3][3]{ {' ','x',' '}, {'o','x',' '} ,{'x','x','o'} };
- //char field[3][3]{ {'x','o','x'}, {'o','o','x'} ,{'o',' ','x'} };
- //char field[3][3]{ {'x','x','x'}, {'o','o',' '}, {'o',' ','x'} };
- //char field[3][3]{ {'o','o',' '}, {'x','x','x'}, {'o',' ','x'} };
- //char field[3][3]{ {'o','o',' '}, {'o',' ','x'}, {'x','x','x'} };
- char field[3][3]{ {'x','o',' '}, {'o','x','x'}, {'o',' ','x'} };
- //char field[3][3]{ {'o','o','x'}, {' ','x','x'}, {'x','o',' '} };
- std::cout << checkWin(field) << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement