~cpp
#include <iostream.h>
#include <conio.h>
void board_display();
void put();
void check();
char board[19][19];
int key, x = 9, y = 9;
char turn = '@';
int winner = 0;
int main()
{
board_display();
gotoxy(x*3+1, y+1);
while(winner == 0)
{
gotoxy(x*3+1, y+1);
key = getch();
if (key == 0x20)
if (board[x][y] == '+')
{
put();
check();
if (winner != 0)
break;
}
if (key == 0x1b)
return 0;
if(key == 0x00)
{
key = getch();
if (key == 0x48)
if (y != 0)
y--;
if (key == 0x50)
if (y != 18)
y++;
if (key == 0x4b)
if (x != 0)
x--;
if (key == 0x4d)
if (x != 18)
x++;
continue;
}
}
gotoxy(1,20);
cout << "Winner is ";
if(winner == 1)
cout << "Black!n";
else if(winner == 2)
cout << "White!n";
getch();
return 0;
}
void board_display()
{
clrscr();
for (int i = 0 ; i < 19 ; i++)
{
for (int j = 0 ; j < 19 ; j++)
{
board[i][j] = '+';
cout << board[i][j] << " ";
}
cout << endl;
}
}
void put()
{
board[x][y] = turn;
cout << board[x][y];
}
void check()
{
int cx, cy, num;
num = 0;
cx = x, cy = y;
while (board[cx-1][cy] == turn)
cx--;
while (board[cx+1][cy] == turn)
{
cx++;
num++;
}
if (num < 4)
{
num = 0;
cx = x, cy = y;
}
while (board[cx][cy-1] == turn)
cy--;
while (board[cx][cy+1] == turn)
{
cy++;
num++;
}
if (num < 4)
{
num = 0;
cx=x, cy=y;
}
while (board[cx-1][cy-1] == turn)
{
cx--, cy--;
}
while (board[cx+1][cy+1] == turn)
{
cx++, cy++;
num++;
}
if (num < 4)
{
num = 0;
cx=x, cy=y;
}
while (board[cx+1][cy-1] == turn)
{
cx++;
cy--;
}
while (board[cx-1][cy+1] == turn)
{
cx--;
cy++;
num++;
}
if (turn == '@')
turn = 'O';
else
turn = '@';
if (num == 4)
{
if (turn == '@')
winner = 2;
if (turn == 'O')
winner = 1;
}
winner == 0;
}