hpnq

Проектик групповой

Dec 9th, 2024
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.54 KB | None | 0 0
  1. #include "bits/stdc++.h"
  2. #define pb push_back
  3. #define pr(x) for(auto i : x) {cout << i << " " ; } cout << "\n";
  4. #define loop(i, x, y) for(int i = x; i < y; i++)
  5. #define ll long long
  6.  
  7. using namespace std;
  8.  
  9.  
  10. class Board{
  11. private:
  12.     vector<vector<int>> a;
  13.  
  14. public:
  15.     Board(){
  16.         a.resize(3, vector<int> (3, 0));
  17.     }
  18.     void print(){
  19.         for(auto i : a){
  20.             for(auto j : i){
  21.                 cout << j;
  22.             }
  23.             cout << "\n";
  24.         }
  25.     }
  26.     bool go_check(int i, int j){
  27.         return (a[i][j] == 0 and i <= 2 and j <= 2);
  28.     }
  29.     // проверка выполнения условия победы
  30.     //или ничьей после сделанного хода;
  31.  
  32.     int res(){
  33.         // gor
  34.         for(auto i : a){
  35.             bool win = true;
  36.             for(int j = 0; j < a.size()-1; j++){
  37.                 if(i[j] != i[j+1] or i[j] == 0 or i[j+1] == 0){
  38.                     win = false;
  39.                 }
  40.             }
  41.             if(win){
  42.                 return i[0]; // победа по горизонтали
  43.             }
  44.         }
  45.         // vert
  46.  
  47.         for(int j = 0; j < a[0].size(); j++){
  48.             bool win = true;
  49.  
  50.             for(int i = 0; i < a.size() - 1; i++){
  51.                 if(a[i][j] != a[i+1][j] or a[i][j] == 0 or a[i+1][j] == 0 ){
  52.                     win = false;
  53.                 }
  54.             }
  55.             if(win){
  56.                 return a[0][j]; // победа по горизонтали
  57.             }
  58.         }
  59.         if(a[0][0] == a[1][1] and a[1][1] == a[2][2] and a[0][0] != 0){
  60.             return a[0][0];
  61.         }
  62.  
  63.         if(a[0][2] == a[1][1] and a[1][1] == a[2][0] and a[1][1] != 0){
  64.             return a[1][1];
  65.         }
  66.         bool nec = false;
  67.         for(int i = 0; i < a.size(); i++){
  68.             for(int j = 0; j < a[0].size(); j++){
  69.                 if(a[i][j] == 0){
  70.                     nec = true;
  71.                 }
  72.             }
  73.         }
  74.         if(!nec){
  75.             return 2;
  76.         }
  77.         return 0;
  78.  
  79.     }
  80. };
  81.  
  82.  
  83.  
  84. class ComputerPlayer: public Board{
  85. private:
  86.     bool hard;
  87. public:
  88.     ComputerPlayer(){
  89.         hard = false;
  90.     }
  91.  
  92.     void play(){
  93.         if(hard){
  94.             cout << "123";
  95.         }
  96.     }
  97. };
  98.  
  99. class Game: public ComputerPlayer{
  100. private:
  101.     bool hard;
  102.     string name1, name2;
  103.     char gamemod;
  104.     int fp;
  105. public:
  106.     Game(){
  107.         hard = false;
  108.         gamemod = 'p';
  109.         fp = 1; // fist player starts
  110.     }
  111.  
  112.     void start(){
  113.         if(hard){
  114.             cout << "123";
  115.         }
  116.     }
  117.     void endg(){
  118.  
  119.     }
  120.  
  121.     void check_state(){
  122.  
  123.     }
  124.  
  125.     void ch_gamemod(){
  126.         cout << "player vs computer (p/c)?\n";
  127.         int c;
  128.         cin >> c;
  129.         gamemod = c;
  130.     }
  131.  
  132.     void who_first(){
  133.         cout << "who first?(1/2) \n";
  134.         int x;
  135.         cin >> x;
  136.         if(x != 1 and x != 2){
  137.             cout << "error. Try again\n";
  138.             who_first();
  139.         }
  140.     }
  141.  
  142.     void chech_coords(){
  143.         cout << "enter 2 coords:\n";
  144.         int x, y;
  145.         cin >> x >> y;
  146.         x--, y--;
  147.         ComputerPlayer::Board::go_check(x, y);
  148.     }
  149. };
  150.  
  151.  
  152.  
  153.  
  154.  
  155. void solve(){
  156. //    vector<vector<int>> a(3, vector<int> (3, 0));
  157.     // 0  - non field
  158.     // 1  - x
  159.     // -1 - 0
  160.  
  161.     Board test;
  162.     test.print();
  163.  
  164.  
  165.  
  166.  
  167. }
  168. //vector<int> b()
  169. int main(){
  170. //    solve();
  171.  
  172.     int n = 1;
  173. //    cin >> n;
  174.     loop(i, 0, n){
  175. //        cout << i+1 << "---\n";
  176.         solve();
  177.     }
  178.     return 0;
  179.  
  180.  
  181.  
  182. }
Advertisement
Add Comment
Please, Sign In to add comment