Notice
Recent Posts
Recent Comments
Link
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Tags more
Archives
Today
Total
관리 메뉴

난 정말 최고야 멋있어

오목 만들기 본문

카테고리 없음

오목 만들기

n00bh4cker 2019. 12. 31. 23:58

 

#include <iostream>
#include <string>
#define WHITE 1
#define BLACK 2
int omokpan[15][15] = { 0, };

using namespace std;


__inline int Player(int& turn)
{
	return (2 - (turn % 2));
}

void printOmokpan()
{
	for (size_t i = 0; i < 15; i++)
	{
		for (size_t j = 0; j < 15; j++)
		{
			char mark = '+';
			switch (omokpan[i][j])
			{
			case WHITE:
				mark = 'O';
				break;
			case BLACK:
				mark = 'X';
				break;
			default:
				break;
			}
			cout << mark << " ";
		}
		cout << endl;
	}

}

bool doOmok(int flag, int y, int x)
{
	if (y > 15 || x > 15 || y < 1 || x < 1)
		return false;
	if (omokpan[y - 1][x - 1] != 0)
		return false;
	omokpan[y-1][x-1] = flag;
	return true;
}

int checkWin()
{
	for (size_t i = 0; i < 15; i++)
	{
		for (size_t j = 0; j < 15; j++)
		{
			if (omokpan[i][j] == 0 || (i<2 && j<2))
				continue;
			//check1 가로
			if (j > 1 && j < 13)
			{
				if (omokpan[i][j] == omokpan[i][j - 1] 
					&& omokpan[i][j] == omokpan[i][j - 2] 
					&& omokpan[i][j] == omokpan[i][j + 1] 
					&& omokpan[i][j] == omokpan[i][j + 2])
					return omokpan[i][j];
			}
			//check2 세로
			if (i > 1 && j < 13)
			{
				if (omokpan[i][j] == omokpan[i-1][j] 
					&& omokpan[i][j] == omokpan[i - 2][j] 
					&& omokpan[i][j] == omokpan[i + 1][j] 
					&& omokpan[i][j] == omokpan[i + 2][j])
					return omokpan[i][j];

			}
			if (i > 1 && j > 1 && i < 13 && j < 13)
			{
				//check3 상승대각
				if (omokpan[i][j] == omokpan[i - 1][j - 1] 
					&& omokpan[i][j] == omokpan[i - 2][j - 2] 
					&& omokpan[i][j] == omokpan[i + 1][j + 1] 
					&& omokpan[i][j] == omokpan[i + 2][j + 2])
					return omokpan[i][j];

				//check4 하강대각
				if (omokpan[i][j] == omokpan[i - 1][j + 1] 
					&& omokpan[i][j] == omokpan[i - 2][j + 2] 
					&& omokpan[i][j] == omokpan[i + 1][j - 1] 
					&& omokpan[i][j] == omokpan[i + 2][j - 2])
					return omokpan[i][j];
			}
		}
	}
	return 0;
}

int main()
{
	int turn=0;
	while (true)
	{
		system("cls");
		printOmokpan();
		int x, y;
	getInput:
		string sPlayer = (turn % 2 == WHITE) ? "White" : "Black";
		cout << "==============================" << endl;
		cout << sPlayer << "'s turn " << endl;
		cin >> y;
		cin >> x;

		auto result = doOmok(Player(turn), y , x );
		if (!result)
		{
			cout << "Wrong Value!!!!!" << endl
				<< "Please Enter Valid Value..." << endl;
			goto getInput;
		}

		turn++;
		if (checkWin())
		{
			cout << "Winner is " << sPlayer << endl;
			break;
		}
	}
	return 0;
}

 

오목판을 만들어 보았다..33같은건 안따지는 동네 오목룰