Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "stdio.h"
- #include "stdlib.h"
- #include "math.h"
- /*
- *
- * | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 |
- * 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
- *
- * 01 = 1
- *
- * ----------------------
- * | 1 | 2 | 3 | 4 |
- * | 5 | 6 | 7 | 8 |
- * | 9 | 10 | 11 | 12 |
- * | 13 | 14 | 15 | 16 |
- * ----------------------
- *
- * W:
- *
- * // 1 2 3 4 / 5 6 7 8 / 9 10 11 12 / 13 14 15 16/ = 00000000000000000000000011111111
- * // 1 5 9 13 / 2 6 10 14 / 3 7 11 15 / 4 8 12 16 / 00000011000000110000001100000011 00001100000011000000110000001100
- * // 1 6 11 16 / 4 7 10 13 //
- *
- *
- *
- *
- */
- int main() {
- char nul = '-';
- std::bitset<32> xo = 0;
- std::cout << std::bitset<32>(xo) << std::endl;
- //int* x = 0;
- int pole;
- bool win = false;
- std::bitset<32> x = 0;
- std::bitset<32> o = 0;
- std::bitset<32> tmpp;
- int count=1;
- int tmp = 0;
- //std::bitset<32> bset3(std::bitset<32>(std::string("1111000000000000"))));
- std::cout << "---------------------" << std::endl <<
- "| " << "01" << " | " << "02" << " | " << "03" << " | " << "04" << " | "<< std::endl <<
- "| " << "05" << " | " << "06" << " | " << "07" << " | " << "08" << " | "<< std::endl <<
- "| " << "09" << " | " << "10" << " | " << "11" << " | " << "12" << " | "<< std::endl <<
- "| " << "13" << " | " << "14" << " | " << "15" << " | " << "16" << " | "<< std::endl <<
- "---------------------" << std::endl;
- while (count < 17){
- for (int i = 1; i < 5; i++){
- 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)) {
- std::cout << " x WINS !";
- return 0;
- }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)){
- std::cout << " o WINS !";
- return 0;
- }
- 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)){
- std::cout << " x WINS !";
- return 0;
- } 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)){
- std::cout << " o WINS !";
- return 0;// 11000000001100000000110000000011
- }else if((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("11000000001100000000110000000011")))) == (std::bitset<32>(std::string("11000000001100000000110000000011")))){
- std::cout << " x WINS !";
- return 0;
- }else if ((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("11000000001100000000110000000011")))) == (std::bitset<32>(std::string("11000000001100000000110000000011")))){
- std::cout << " o WINS !";
- return 0;// 00000011000011000011000011000000
- }else if ((std::bitset<32>(x.to_ullong()) & (std::bitset<32>(std::string("11000000001100000000110000000011")))) == (std::bitset<32>(std::string("11000000001100000000110000000011")))){
- std::cout << " x WINS !";
- return 0;
- }else if ((std::bitset<32>(o.to_ullong()) & (std::bitset<32>(std::string("00000011000011000011000011000000")))) == (std::bitset<32>(std::string("00000011000011000011000011000000")))){
- std::cout << " o WINS !";
- return 0;// 00000011000011000011000011000000
- }
- }
- std::cout << "Podaj pole (1-16): ";
- std::cin >> pole;
- if (pole > 0 && pole < 17) {
- for (int j = 1; j < 17; j++) {
- if (pole == j){
- 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)) {
- if (count % 2 == 0) {
- x = (std::bitset<32>(x.to_ullong()) |
- (std::bitset<32>(std::string("00000000000000000000000000000011")) << (j - 1) * 2));
- xo = (std::bitset<32>(xo.to_ullong()) |
- (std::bitset<32>(std::string("00000000000000000000000000000011")) << (j - 1) * 2));
- } else {
- o = (std::bitset<32>(o.to_ullong()) |
- (std::bitset<32>(std::string("00000000000000000000000000000011")) << (j - 1) * 2));
- xo = (std::bitset<32>(xo.to_ullong()) |
- (std::bitset<32>(std::string("00000000000000000000000000000011")) << (j - 1) * 2));
- }
- count++;
- } else std::cout << "Pole zajęte!" << std::endl;
- }
- }
- }
- std::cout << "---------------------" << std::endl <<
- "| " << (((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"))
- << " | " << (((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"))
- << " | " << (((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"))
- << " | " << (((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"))
- << " | "<< std::endl <<
- "| " << (((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"))
- << " | " << (((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"))
- << " | " << (((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"))
- << " | " << (((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"))
- << " | "<< std::endl <<
- "| " << (((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"))
- << " | " << (((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"))
- << " | " << (((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"))
- << " | " << (((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"))
- << " | "<< std::endl <<
- "| " << (((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"))
- << " | " << (((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"))
- << " | " << (((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"))
- << " | " << (((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"))
- << " | "<< std::endl <<
- "---------------------" << std::endl;
- std::cout << " xo: " << xo << std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement