Advertisement
Guest User

xD

a guest
May 23rd, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.53 KB | None | 0 0
  1. #include <iostream>
  2. #include "stdio.h"
  3. #include "stdlib.h"
  4. #include "math.h"
  5.  
  6. /*
  7.  *
  8.  *  | 1  | 2  | 3  | 4  | 5  | 6  | 7  | 8  | 9  | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
  9.  *   00   00   00   00   00   00   00   00   00    00   00   00   00   00   00   00
  10.  *
  11.  *   01 = 1
  12.  *
  13.  *  ----------------------
  14.  *  | 1  | 2  | 3  | 4  |
  15.  *  | 5  | 6  | 7  | 8  |
  16.  *  | 9  | 10 | 11 | 12 |
  17.  *  | 13 | 14 | 15 | 16 |
  18.  *  ----------------------
  19.  *
  20.  * W:
  21.  *
  22.  *  // 1 2 3 4  / 5 6 7 8  /  9 10 11 12  /  13 14 15 16/   =   00000000000000000000000011111111
  23.  *  // 1 5 9 13 /  2 6 10 14 / 3 7 11 15 / 4 8 12 16 /  00000011000000110000001100000011   00001100000011000000110000001100
  24.  *  // 1 6 11 16 /  4 7 10 13 //
  25.  *
  26.  *
  27.  *
  28.  *
  29.  */
  30. int main() {
  31.     char nul = '-';
  32.     std::bitset<32> xo = 0;
  33.    std::cout << std::bitset<32>(xo) << std::endl;
  34.    //int* x = 0;
  35.    int pole;
  36.    bool win = false;
  37.    std::bitset<32> x = 0;
  38.    std::bitset<32> o = 0;
  39.     std::bitset<32> tmpp;
  40.    int count=1;
  41.     int tmp = 0;
  42.    //std::bitset<32> bset3(std::bitset<32>(std::string("1111000000000000"))));
  43.  
  44.         std::cout << "---------------------" << std::endl <<
  45.      "| " << "01" << " | " << "02" << " | " << "03" << " | " << "04" << " | "<< std::endl <<
  46.      "| "  << "05" << " | " << "06" << " | " << "07" << " | " << "08" << " | "<< std::endl <<
  47.      "| " << "09" << " | " << "10" << " | " << "11" << " | " << "12" << " | "<< std::endl <<
  48.      "| " << "13" << " | " << "14" << " | " << "15" << " | " << "16" << " | "<< std::endl <<
  49.                     "---------------------" << std::endl;
  50. while (count < 17){
  51. for (int i = 1; i < 5; i++){
  52.     if ((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000011111111")) << (i - 1) * 8)) == (std::bitset<32>(std::string("00000000000000000000000011111111")) << (i - 1) * 8))   {
  53.         std::cout << " x WINS !";
  54.         return 0;
  55.  
  56.     }else if ((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000011111111")) << (i - 1) * 8)) == (std::bitset<32>(std::string("00000000000000000000000011111111")) << (i - 1) * 8)){
  57.         std::cout << " o WINS !";
  58.         return 0;
  59.     }
  60.  
  61.     if((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("00000011000000110000001100000011")) << (i - 1) * 2)) == (std::bitset<32>(std::string("00000011000000110000001100000011")) << (i - 1) * 2)){
  62.  
  63.         std::cout << " x WINS !";
  64.     return 0;
  65.     } else if ((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000011000000110000001100000011")) << (i - 1) * 2)) == (std::bitset<32>(std::string("00000011000000110000001100000011")) << (i - 1) * 2)){
  66.         std::cout << " o WINS !";
  67.         return 0;// 11000000001100000000110000000011
  68.     }else if((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("11000000001100000000110000000011")))) == (std::bitset<32>(std::string("11000000001100000000110000000011")))){
  69.         std::cout << " x WINS !";
  70.         return 0;
  71.     }else if ((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("11000000001100000000110000000011")))) == (std::bitset<32>(std::string("11000000001100000000110000000011")))){
  72.         std::cout << " o WINS !";
  73.         return 0;// 00000011000011000011000011000000
  74.     }else if ((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("11000000001100000000110000000011")))) == (std::bitset<32>(std::string("11000000001100000000110000000011")))){
  75.         std::cout << " x WINS !";
  76.         return 0;
  77.     }else if ((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000011000011000011000011000000")))) == (std::bitset<32>(std::string("00000011000011000011000011000000")))){
  78.         std::cout << " o WINS !";
  79.         return 0;// 00000011000011000011000011000000
  80.     }
  81.  
  82.  
  83. }
  84.  
  85.  
  86.  
  87.  
  88.     std::cout << "Podaj pole (1-16):  ";
  89.     std::cin >> pole;
  90.  
  91.     if (pole > 0 && pole < 17) {
  92.  
  93.         for (int j = 1; j < 17; j++) {
  94.             if (pole == j){
  95.                 if (((std::bitset<32>(std::string("00000000000000000000000000000011")) << (j - 1) * 2) & std::bitset<32>(xo.to_ullong())) != (std::bitset<32>(std::string("00000000000000000000000000000011")) << (j - 1) * 2)) {
  96.             if (count % 2 == 0) {
  97.                     x = (std::bitset<32>(x.to_ullong()) |
  98.                          (std::bitset<32>(std::string("00000000000000000000000000000011")) << (j - 1) * 2));
  99.                     xo = (std::bitset<32>(xo.to_ullong()) |
  100.                           (std::bitset<32>(std::string("00000000000000000000000000000011")) << (j - 1) * 2));
  101.  
  102.                 } else {
  103.                     o = (std::bitset<32>(o.to_ullong()) |
  104.                          (std::bitset<32>(std::string("00000000000000000000000000000011")) << (j - 1) * 2));
  105.                     xo = (std::bitset<32>(xo.to_ullong()) |
  106.                           (std::bitset<32>(std::string("00000000000000000000000000000011")) << (j - 1) * 2));
  107.  
  108.                 }
  109.                     count++;
  110.             } else std::cout << "Pole zajęte!" << std::endl;
  111.         }
  112.         }
  113.  
  114.     }
  115.  
  116.     std::cout << "---------------------" << std::endl <<
  117.               "| " << (((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (1 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (1 - 1) * 2) ? " X" : (((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (1 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (1 - 1) * 2) ? " O" : "01"))
  118.               << " | " << (((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (2 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (2 - 1) * 2) ? " X" : (((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (2 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (2 - 1) * 2) ? " O" : "02"))
  119.             << " | " << (((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (3 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (3 - 1) * 2) ? " X" : (((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (3 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (3 - 1) * 2) ? " O" : "03"))
  120.             << " | " << (((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (4 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (4 - 1) * 2) ? " X" : (((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (4 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (4 - 1) * 2) ? " O" : "04"))
  121.             << " | "<< std::endl <<
  122.               "| "  << (((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (5 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (5 - 1) * 2) ? " X" : (((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (5 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (5 - 1) * 2) ? " O" : "05"))
  123.             << " | " << (((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (6 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (6 - 1) * 2) ? " X" : (((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (6 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (6 - 1) * 2) ? " O" : "06"))
  124.             << " | " << (((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (7 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (7 - 1) * 2) ? " X" : (((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (7 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (7 - 1) * 2) ? " O" : "07"))
  125.             << " | " << (((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (8 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (8 - 1) * 2) ? " X" : (((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (8 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (8 - 1) * 2) ? " O" : "08"))
  126.             << " | "<< std::endl <<
  127.               "| " << (((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (9 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (9 - 1) * 2) ? " X" : (((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (9 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (9 - 1) * 2) ? " O" : "09"))
  128.             << " | " << (((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (10 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (10 - 1) * 2) ? " X" : (((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (10 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (10 - 1) * 2) ? " O" : "10"))
  129.             << " | " << (((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (11 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (11 - 1) * 2) ? " X" : (((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (11 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (11 - 1) * 2) ? " O" : "11"))
  130.             << " | " << (((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (12 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (12 - 1) * 2) ? " X" : (((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (12 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (12 - 1) * 2) ? " O" : "12"))
  131.             << " | "<< std::endl <<
  132.               "| " << (((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (13 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (13 - 1) * 2) ? " X" : (((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (13 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (13 - 1) * 2) ? " O" : "13"))
  133.             << " | " << (((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (14 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (14 - 1) * 2) ? " X" : (((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (14 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (14 - 1) * 2) ? " O" : "14"))
  134.             << " | " << (((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (15 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (15 - 1) * 2) ? " X" : (((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (15 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (15 - 1) * 2) ? " O" : "15"))
  135.             << " | " << (((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (16 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (16 - 1) * 2) ? " X" : (((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000000000000000000000000000011")) << (16 - 1) * 2)) == (std::bitset<32>(std::string("00000000000000000000000000000011"))) << (16 - 1) * 2) ? " O" : "16"))
  136.             << " | "<< std::endl <<
  137.               "---------------------" << std::endl;
  138.  
  139.     std::cout << " xo: "  << xo << std::endl;
  140. }
  141.  
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement