U E D R , A S I H C RSS

Omok/유상욱

~cpp 
include <iostream.h>
#include <conio.h>

int omok_array[19][19]={0,};
void omok_display();
int omok_check(int, int);
int main()
{
	int b_and_w=0;
	int question_x, question_y;
	cout << "오목을 시작하겠습니다. ";
	omok_display();
	while(1)
	{
		b_and_w++;
		if (b_and_w%2 == 1)
			cout << "백 돌의 좌표를 입력하시오(x y) ->";
		else
			cout << "흑 돌의 좌표를 입력하시오(x y) ->";
		cin >> question_y >> question_x;
		if ( omok_array[question_x][question_y] != 0)
		{
			cout << "다시 입력하시오 \n";
			b_and_w--;
			continue;
		}
		else
			omok_array[question_x][question_y] = b_and_w%2+1;
		omok_display();

		if (omok_check(question_x, question_y) == 2)
		{
			cout << "백 돌이 승리했습니다.\n";
		       break;
		}
		else if (omok_check(question_x, question_y) == 1)
		{
			cout << "흑 돌이 승리했습니다.\n";
			break;
		}
	}
//	getch();
	return 0;
}

void omok_display()
{
//	clrscr ();
	system("cls");
	for (int i = 0 ; i <= 18 ; i++)
	{
		for (int j = 0 ; j <= 18 ; j++)
			cout << omok_array[i][j];
		cout << " " << i;
		cout << "\n";
	}
}

int omok_check(int x, int y)
{
	int i,check_x=0,check_y=0,check_cl=0,check_cr=0,che=0,temp=omok_array[x][y];
	for (i = -5 ; i <= 5 ; i++)	// 가로
	{
		if ( omok_array[x-i][y] == temp)
		{
			check_x++;
			if ( check_x == 5)
				break;
		}
		else 
			check_x = 0;
	}
	if ( check_x == 5 )
	{
		if ( omok_array[x-(i+1)][y] != temp )
			return temp;
	}

	for (i = -5 ; i <= 5 ; i++)	// 세로
	{
		if ( omok_array[x][y-i] == temp)
		{
			check_y++;
			if ( check_y == 5)
				break;
		}
		else 
			check_x = 0;
	}
	if ( check_y == 5 )
	{
		if ( omok_array[x][y-(i+1)] != temp )
			return temp;
	}

	for (i = -5 ; i <= 5 ; i++)	// 왼쪽 대각선
	{
		if ( omok_array[x-i][y-i] == temp)
		{
			check_cl++;
			if ( check_cl == 5)
				break;
		}
		else 
			check_cl = 0;
	}
	if ( check_cl == 5 )
	{
		if ( omok_array[x-(i+1)][y-(i+1)] != temp )
			return temp;
	}

	for (i = -5 ; i <= 5 ; i++)	// 오른쪽 대각선
	{
		if ( omok_array[x-i][y+i] == temp)
		{
			check_cr++;
			if ( check_cr == 5)
				break;
		}
		else 
			check_cr = 0;
	}
	if ( check_cr == 5 )
	{
		if ( omok_array[x-(i+1)][y+(i+1)] != temp )
			return temp;
	}
	return 0;
}
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:53
Processing time 0.0119 sec