Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <iostream>
- #include<vector>;
- #define BLACK 1
- #define RED 255
- using namespace std;
- void display(byte board[7][6]) {
- cout << " 1 | 2 | 3 | 4 | 5 | 6 | 7 |";
- for (int i = 0; i < 6; i++) {
- cout << "\n____________________________\n ";
- for (int j = 0; j < 7; j++) {
- if (!board[j][i]) { cout << " "; }
- else if (board[j][i] == BLACK) { cout << "B"; }
- else { cout << "R";}
- cout << " | ";
- }
- }
- cout << '\n';
- }
- byte checkwinner(byte board[7][6]) {
- for (int i = 0; i < 6; i++) {
- for (int j = 0; j < 7; j++) {
- if (board[j][i]) {
- if (j + 3 < 7) {//checks left to right
- if ((board[j][i] + board[j + 1][i] + board[j + 2][i] + board[j + 3][i]) / 4 == BLACK) {
- return BLACK;
- }
- else if ((board[j][i] + board[j + 1][i] + board[j + 2][i] + board[j + 3][i]) / 4 == RED) {
- return RED;
- }
- }
- if (i + 3 < 6) {//check from top to bottom
- if ((board[j][i] + board[j][i+1] + board[j][i+2] + board[j][i+3]) / 4 == BLACK) {
- return BLACK;
- }
- else if ((board[j][i] + board[j][i + 1] + board[j][i + 2] + board[j][i + 3]) / 4 == RED) {
- return RED;
- }
- }
- if (j + 3 < 7 && i + 3 < 6) { //diag down and right
- if ((board[j][i] + board[j+1][i + 1] + board[j+2][i + 2] + board[j+3][i + 3]) / 4 == BLACK) {
- return BLACK;
- }
- else if ((board[j][i] + board[j+1][i + 1] + board[j+2][i + 2] + board[j+3][i + 3]) / 4 == RED) {
- return RED;
- }
- }
- if (j - 3 > -1 && i + 3 < 6) {
- if ((board[j][i] + board[j - 1][i + 1] + board[j - 2][i + 2] + board[j - 3][i + 3]) / 4 == BLACK) {
- return BLACK;
- }
- else if ((board[j][i] + board[j - 1][i + 1] + board[j - 2][i + 2] + board[j - 3][i + 3]) / 4 == RED) {
- return RED;
- }
- }
- }
- }
- }
- return 0;
- }
- bool full(int move,byte board[7][6]) {
- if (move > 0 && move < 8) {
- return !board[move - 1][0];
- }
- return false;
- }
- void moveLogic(int move, byte player,byte board[7][6]) {
- for (int i = 5; i > -1; i--) {
- if (!board[move - 1][i]) {
- board[move - 1][i] = player;
- break;
- }
- }
- }
- int main()
- {
- byte board[7][6]{ 0 };
- bool flip = true;
- //player 1 is always black 2 = red;
- do {
- display(board);
- int move = 0;
- while (!full(move,board)) {
- cout << " player " << (flip ? 1 : 2) << " please select a move ....\n";
- scanf_s("%d", &move);
- }
- moveLogic(move, flip ? BLACK : RED, board);
- flip = !flip;
- } while (!checkwinner(board));
- display(board);
- cout << "player " << (checkwinner(board) == RED ? "RED " : "BLACK ") << "WINS!!!!!!!!!!";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement