create a tic tac toe socket programming in c
\\\ using windows socket \\\\\\\
PROGRAM:
#include <iostream>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#include<windows.h>
using namespace std;
int player = 0;
int board[4][4] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void gameboard();
void getmove();
void result();
string check(int a);
int check(string a);
char choice;
int score1 = 0, score2 = 0;
int p1,p2;
string letter="a";
void gather_all();
void point(int n);
int row, col;
int a=-1;
int main();
void result()
{
int i,j,c=0;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(board[i][j]!=0)
{
c++;
}
}
}
if(c==16)
{
cout<<endl<<" GAME OVER";
if(score1>score2)
{
cout<<endl<<"PLAYER 1 WON";
}
else if(score1==score2)
{
cout<<endl<<"MATCH DRAW";
}
else
{
cout<<endl<<"PLAYER 2 WON";
}
Sleep(1000);
exit(0);
}
}
string check(int x)
{
string b;
switch(x)
{
case 0:
b=" ";
break;
case 1:
b=" S";
break;
case 2:
b=" O";
break;
case 3:
b="-S";
break;
case 4:
b="-O";
break;
case 10:
b=" S";
break;
case 20:
b=" O";
break;
case 30:
b="-S";
break;
case 40:
b="-O";
break;
}
return b;
}
int check(string x)
{
int b;
if(x==" ")
{
b=0;
}
else if(x=="S")
{
b=1;
}
else if(x=="O")
{
b=2;
}
else if(x=="-S")
{
b=3;
}
else
{
b=4;
}
return b;
}
void gameboard()
{
system("cls");
cout << "player1: " <<score1<<"\t"<<
"player2: "<<score2<< endl;
cout<<"+---+---+---+---+"<<endl;
for(int i=0;i<4;i++){
cout<<"|";
for(int j=0;j<4;j++)
cout<<check(board[i][j])<<" |";
cout<<endl<<"+---+---+---+---+"<<endl;
}
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
cout<<"\t"<<board[i][j];
}
cout<<endl;
}
}
void getmove()
{
int row, col,s;
if(player<=0)
{
cout<<"player 1 enter the block number:";
cin>>a;
if(!isdigit(a))
{
if(board[(a-1)/4][(a-1)%4]==0)
{
cout<<"Enter S or O(USE CAPITALS ONLY!): ";
cin>>letter;
if("S"==letter||"O"==letter)
{
row =
(a-1)/4;
col =
(a-1)%4;
board[row][col]
=check(letter);
player++;
}
}
else
{
cout<<a<<" Block number is already filled.";
Sleep(1000);
}
}
else
{
cout<<"Wrong input";
exit(0);
}
}
point(1);
gameboard();
result();
if(player > 0 )
{
cout<<"player 2 enter the
block number:";
cin>>a;
if(!isdigit(a))
{
if(board[(a-1)/4][(a-1)%4]==0)
{
cout<<"Enter -S or -O(USE CAPITALS ONLY!): ";
cin>>letter;
if("-S"==letter||"-O"==letter)
{
row =
(a-1)/4;
col =
(a-1)%4;
board[row][col]
= check(letter);
player--;
}
else
{
cout<<"SMALL ONLY!!!!. ALSO USE s OR o\n\n";
}
}
else
{
cout<<a<<" Block number is already filled.";
Sleep(1000);
}
}
else
{
cout<<"Wrong input";
exit(0);
}
point(0);
gameboard();
result();
}
}
void point(int n)
{
int i,j;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
if(board[i][j]==0||board[i][j]==2||board[i][j]==4)
{
continue;
}
else
if(board[i][j]==1||board[i][j]==3||(board[i][j]/10)==1||(board[i][j]/10)==3)
{
if(((board[i][j+1]==2||board[i][j+1]==4)&&(board[i][j+2]==1||board[i][j+2]==3))||(((board[i][j+1]/10)>0)&&(board[i][j+2]==1||board[i][j+2]==3))||((board[i][j+1]==2||board[i][j+1]==4)&&((board[i][j+2]/10)>0)))
{
if(n==1)
{
score1++;
}
else
{
score2++;
}
board[i][j]=(board[i][j]/10==0)?(board[i][j]*10):(board[i][j]);
board[i][j+1]=(board[i][j+1]/10==0)?(board[i][j+1]*10):(board[i][j+1]);
board[i][j+2]=(board[i][j+2]/10==0)?(board[i][j+2]*10):(board[i][j+2]);
}
else
if((board[i+1][j]==2||board[i+1][j]==4)&&(board[i+2][j]==1||board[i+2][j]==3)||(((board[i+1][j]/10)>0)&&(board[i+2][j]==1||board[i+2][j]==3))||((board[i+1][j]==2||board[i+1][j]==4)&&((board[i+2][j]/10)>0)))
{
if(n==1)
{
score1++;
}
else
{
score2++;
}
board[i][j]=(board[i][j]/10==0)?(board[i][j]*10):(board[i][j]);
board[i+1][j]=(board[i+1][j]/10==0)?(board[i+1][j]*10):(board[i+1][j]);
board[i+2][j]=(board[i+2][j]/10==0)?(board[i+2][j]*10):(board[i+2][j]);
}
else
if((board[i+1][j+1]==2||board[i+1][j+1]==4)&&(board[i+2][j+2]==1||board[i+2][j+2]==3)||(((board[i+1][j+1]/10)>0)&&(board[i+2][j+2]==1||board[i+2][j+2]==3))||((board[i+1][j+1]==2||board[i+1][j+1]==4)&&((board[i+2][j+2]/10)>0)))
{
if(n==1)
{
score1++;
}
else
{
score2++;
}
board[i][j]=(board[i][j]/10==0)?(board[i][j]*10):(board[i][j]);
board[i+1][j+1]=(board[i+1][j+1]/10==0)?(board[i+1][j+1]*10):(board[i+1][j+1]);
board[i+2][j+2]=(board[i+2][j+2]/10==0)?(board[i+2][j+2]*10):(board[i+2][j+2]);
}
}
}
}
for(i=2;i<4;i++)
{
for(j=0;j<2;j++)
{
if(board[i][j]==0||board[i][j]==2||board[i][j]==4)
{
continue;
}
else
if(board[i][j]==1||board[i][j]==3||(board[i][j]/10)==1||(board[i][j]/10)==3)
{
if(((board[i][j+1]==2||board[i][j+1]==4)&&(board[i][j+2]==1||board[i][j+2]==3))||(((board[i][j+1]/10)>0)&&(board[i][j+2]==1||board[i][j+2]==3))||((board[i][j+1]==2||board[i][j+1]==4)&&((board[i][j+2]/10)>0)))
{
if(n==1)
{
score1++;
}
else
{
score2++;
}
board[i][j]=(board[i][j]/10==0)?(board[i][j]*10):(board[i][j]);
board[i][j+1]=(board[i][j+1]/10==0)?(board[i][j+1]*10):(board[i][j+1]);
board[i][j+2]=(board[i][j+2]/10==0)?(board[i][j+2]*10):(board[i][j+2]);
}
else
if((board[i-1][j]==2||board[i-1][j]==4)&&(board[i-2][j]==1||board[i-2][j]==3)||(((board[i-1][j]/10)>0)&&(board[i-2][j]==1||board[i-2][j]==3))||((board[i-1][j]==2||board[i-1][j]==4)&&((board[i-2][j]/10)>0)))
{
if(n==1)
{
score1++;
}
else
{
score2++;
}
board[i][j]=(board[i][j]/10==0)?(board[i][j]*10):(board[i][j]);
board[i-1][j]=(board[i-1][j]/10==0)?(board[i-1][j]*10):(board[i-1][j]);
board[i-2][j]=(board[i-2][j]/10==0)?(board[i-2][j]*10):(board[i-2][j]);
}
else
if((board[i-1][j+1]==2||board[i-1][j+1]==4)&&(board[i-2][j+2]==1||board[i-2][j+2]==3)||(((board[i-1][j+1]/10)>0)&&(board[i-2][j+2]==1||board[i-2][j+2]==3))||((board[i-1][j+1]==2||board[i-1][j+1]==4)&&((board[i-2][j+2]/10)>0)))
{
if(n==1)
{
score1++;
}
else
{
score2++;
}
board[i][j]=(board[i][j]/10==0)?(board[i][j]*10):(board[i][j]);
board[i-1][j+1]=(board[i-1][j+1]/10==0)?(board[i-1][j+1]*10):(board[i-1][j+1]);
board[i-2][j+2]=(board[i-2][j+2]/10==0)?(board[i-2][j+2]*10):(board[i-2][j+2]);
}
}
}
}
for(i=0;i<2;i++)
{
for(j=2;j<4;j++)
{
if(board[i][j]==0||board[i][j]==2||board[i][j]==4)
{
continue;
}
else
if(board[i][j]==1||board[i][j]==3||(board[i][j]/10)==1||(board[i][j]/10)==3)
{
if(((board[i][j-1]==2||board[i][j-1]==4)&&(board[i][j-2]==1||board[i][j-2]==3))||(((board[i][j-1]/10)>0)&&(board[i][j-2]==1||board[i][j-2]==3))||((board[i][j-1]==2||board[i][j-1]==4)&&((board[i][j-2]/10)>0)))
{
if(n==1)
{
score1++;
}
else
{
score2++;
}
board[i][j]=(board[i][j]/10==0)?(board[i][j]*10):(board[i][j]);
board[i][j-1]=(board[i][j-1]/10==0)?(board[i][j-1]*10):(board[i][j-1]);
board[i][j-2]=(board[i][j-2]/10==0)?(board[i][j-2]*10):(board[i][j-2]);
}
else
if((board[i+1][j]==2||board[i+1][j]==4)&&(board[i+2][j]==1||board[i+2][j]==3)||(((board[i+1][j]/10)>0)&&(board[i+2][j]==1||board[i+2][j]==3))||((board[i+1][j]==2||board[i+1][j]==4)&&((board[i+2][j]/10)>0)))
{
if(n==1)
{
score1++;
}
else
{
score2++;
}
board[i][j]=(board[i][j]/10==0)?(board[i][j]*10):(board[i][j]);
board[i+1][j]=(board[i+1][j]/10==0)?(board[i+1][j]*10):(board[i+1][j]);
board[i+2][j]=(board[i+2][j]/10==0)?(board[i+2][j]*10):(board[i+2][j]);
}
else
if((board[i+1][j-1]==2||board[i+1][j-1]==4)&&(board[i+2][j-2]==1||board[i+2][j-2]==3)||(((board[i+1][j-1]/10)>0)&&(board[i+2][j-2]==1||board[i+2][j-2]==3))||((board[i+1][j-1]==2||board[i+1][j-1]==4)&&((board[i+2][j-2]/10)>0)))
{
if(n==1)
{
score1++;
}
else
{
score2++;
}
board[i][j]=(board[i][j]/10==0)?(board[i][j]*10):(board[i][j]);
board[i+1][j-1]=(board[i+1][j-1]/10==0)?(board[i+1][j-1]*10):(board[i+1][j-1]);
board[i+2][j-2]=(board[i+2][j-2]/10==0)?(board[i+2][j-2]*10):(board[i+2][j-2]);
}
}
}
}
for(i=2;i<4;i++)
{
for(j=2;j<4;j++)
{
if(board[i][j]==0||board[i][j]==2||board[i][j]==4)
{
continue;
}
else
if(board[i][j]==1||board[i][j]==3||(board[i][j]/10)==1||(board[i][j]/10)==3)
{
if(((board[i][j-1]==2||board[i][j-1]==4)&&(board[i][j-2]==1||board[i][j-2]==3))||(((board[i][j-1]/10)>0)&&(board[i][j-2]==1||board[i][j-2]==3))||((board[i][j-1]==2||board[i][j-1]==4)&&((board[i][j-2]/10)>0)))
{
if(n==1)
{
score1++;
}
else
{
score2++;
}
board[i][j]=(board[i][j]/10==0)?(board[i][j]*10):(board[i][j]);
board[i][j-1]=(board[i][j-1]/10==0)?(board[i][j-1]*10):(board[i][j-1]);
board[i][j-2]=(board[i][j-2]/10==0)?(board[i][j-2]*10):(board[i][j-2]);
}
else
if((board[i-1][j]==2||board[i-1][j]==4)&&(board[i-2][j]==1||board[i-2][j]==3)||(((board[i-1][j]/10)>0)&&(board[i-2][j]==1||board[i-2][j]==3))||((board[i-1][j]==2||board[i-1][j]==4)&&((board[i-2][j]/10)>0)))
{
if(n==1)
{
score1++;
}
else
{
score2++;
}
board[i][j]=(board[i][j]/10==0)?(board[i][j]*10):(board[i][j]);
board[i-1][j]=(board[i-1][j]/10==0)?(board[i-1][j]*10):(board[i-1][j]);
board[i-2][j]=(board[i-2][j]/10==0)?(board[i-2][j]*10):(board[i-2][j]);
}
else
if((board[i-1][j-1]==2||board[i-1][j-1]==4)&&(board[i-2][j-2]==1||board[i-2][j-2]==3)||(((board[i-1][j-1]/10)>0)&&(board[i-2][j-2]==1||board[i-2][j-2]==3))||((board[i+1][j+1]==2||board[i+1][j+1]==4)&&((board[i+2][j+2]/10)>0)))
{
if(n==1)
{
score1++;
}
else
{
score2++;
}
board[i][j]=(board[i][j]/10==0)?(board[i][j]*10):(board[i][j]);
board[i-1][j-1]=(board[i-1][j-1]/10==0)?(board[i-1][j-1]*10):(board[i-1][j-1]);
board[i-2][j-2]=(board[i-2][j-2]/10==0)?(board[i-2][j-2]*10):(board[i-2][j-2]);
}
}
}
}
}
void gather_all()
{
gameboard();
while(1)
{
getmove();
}
}
int main()
{
gather_all();
return 0;
}
create a tic tac toe socket programming in c \\\ using windows socket \\\\\\\
create a tic tac toe socket programming in c windows
(Tic-Tac-Toe) Create a class Tic-Tac-Toe that will enable you to write a program to play Tic-Tac-Toe. The class contains a private 3-by-3 two-dimensional array. Use an enumeration to represent the value in each cell of the array. The enumeration’s constants should be named X, O and EMPTY (for a position that does not contain an X or an O). The constructor should initialize the board elements to EMPTY. Allow two human players. Wherever the first player moves, place an X...
PYTHON Exercise 2. Tic-Tac-Toe In this exercise we are going to create a Tic-Tac-Toe game. 1. Create the data structure – Nine slots that can each contain an X, an O, or a blank. – To represent the board with a dictionary, you can assign each slot a string-value key. – String values in the key-value pair to represent what’s in each slot on the board: ■ 'X' ■ 'O' ■ ‘ ‘ 2. Create a function to print the...
1. Use Turtle Graphics to create a tic tac toe game in Python. Write a Python program that allows for one player vs computer to play tic tac toe game, without using turtle.turtle
Create a very basic tic tac toe game written in C code. This C code should be able to create a GBA file from using devkit to run in visual boy advance.
1. Use Turtle Graphics to create a tic tac toe grid in Python. Write a Python program that prints a tic tac toe grid. Use Turtle Graphics to create the graphic.
Create a batch file tic tac toe game written in C code. This code should be able to run through an emulator.
Tic tac toe game C++ programing using classes, objects, arays
(Game: play a tic-tac-toe game) In a game of tic-tac-toe, two players take turns marking an available cell in a grid with their respective tokens (either X or O). When one player has placed three tokens in a horizontal, vertical, or diagonal row on the grid, the game is over and that player has won. A draw (no winner) occurs when all the cells in the grid have been filled with tokens and neither player has achieved a win. Create...
Please write a tic tac toe game using c++ language and 1D arrays, thank you!