C언어로 포커 만드는 중에 질문드립니다

gatsby6355의 이미지

포커의 족보 부분을 만들고 있는데, 어떤 값을 넣어도 리턴 값이 0, 즉 하이 카드 밖에 나오지 않습니다. 어떤 부분이 잘못된 것인지 알려주시면 감사하겠습니다.

#include <stdio.h>
 
typedef struct Card {
		char *shape;
		int num;
	}Card;	
Card Deck[52], User[7], Com[7], tmp[7], input[7];
 
int main()
{
	//아래 input값들은 제대로 작동하는지 알기 위해 임의로 값을 넣어본 부분입니다.
	input[0].num = 10;
	input[1].num = 3;
	input[2].num = 3;
	input[3].num = 3;
	input[4].num = 13;
	input[5].num = 12;
	input[6].num = 11;
	input[0].shape = '♠';
	input[1].shape = '♠';
	input[2].shape = '♣';
	input[3].shape = '♣';
	input[4].shape = '♠';
	input[5].shape = '♣';
	input[6].shape = '♠';
 
	int i, j, k, l, m;
	int temp;
	int scount = 0;
	int pcount = 0;
	int pscase;
	int diamond = 0;
	int heart = 0;
	int spade = 0;
	int clover = 0;
	int preturn = 0;
	for (i = 0; i < 7; i++)
	{
		for (int j = 0; j < 6; j++)
		{
			if (input[j].num> input[j + 1].num)//sort
			{
				temp = input[j].num;
				input[j].num = input[j + 1].num;
				input[j + 1].num = temp;
			}
		}
	}
	for (i = 0; i < 7; i++)
	{
		printf("%d ", input[i].num); //카드가 제대로 정렬되었는지 알기 위해 출력했습니다.
	}
	printf("\n");
	for (i = 0; i < 3; i++)//'straight's
	{
		for (j = 0; j < 6; j++)
		{
			if (input[j].num + 1 == input[j + 1].num)
				scount++;
		}
		if (scount >= 5)
		{
			scount = 0;
			pscase = 1;
			goto switcher;
		}
	}
 
	for (i = 0; i < 7; i++)//'flush'
	{
		if (input[i].shape == '♠')
			spade++;
		if (input[i].shape == '♣')
			clover++;
		if (input[i].shape == '♥')
			heart++;
		if (input[i].shape == '◆')
			diamond++;
	}
	if (diamond >= 5 || spade >= 5 || clover >= 5 || heart >= 5)
	{
		pscase = 2;
		goto switcher;
	}
 
	for (i = 0; i < 7; i++) //'pair's
	{
		if (input[i].num == input[i + 1].num)
			pcount++;
	}
	if (pcount >= 1)
	{
		pscase = 3;
		goto switcher;
	}
 
switcher:
	switch (pscase) //hand ranks
	{
	case 1: //'straight's
			for (i = 0; i < 3; i++)//royal straight flush
			{
				for (j = 0; j < 4; j++)
				{
					for (k = 0; k < 5; k++)
					{
						for (l = 0; l < 6; l++)
						{
							for (m = 0; m < 7; m++)
							{
								if ((input[i].num == 1) && (input[j].num == 10) && (input[k].num == 11) && (input[l].num = 12) && (input[m].num == 13) && (input[i].shape == input[j].shape == input[k].shape == input[l].shape == input[m].shape))
								{
									preturn = 12;
									goto end;
								}
							}
						}
					}
				}
			}
			for (i = 0; i < 7; i++)//back straight flush
			{
				for (j = 0; j < 7; j++)
				{
					for (k = 0; k < 7; k++)
					{
						for (l = 0; l < 7; l++)
						{
							for (m = 0; m < 7; m++)
							{
								if ((input[i].num == 1) && (input[j].num == 2) && (input[k].num == 3) && (input[l].num = 4) && (input[m].num == 5) && input[i].shape == input[j].shape == input[k].shape == input[l].shape == input[m].shape)
								{
									preturn = 11;
									goto end;
								}
							}
						}
					}
				}
			}
			for (i = 0; i < 3; i++)//straight flush
			{
				for (j = i; j < i + 4; j++)
				{
				if (input[j].num + 1 == input[j + 1].num)
					scount++;
				}
				if ((scount >= 5) && (input[i].shape == input[i+1].shape == input[i+2].shape == input[i+3].shape == input[i+4].shape))
					{
						scount = 0;
						preturn = 10;
						goto end;
					}
				scount = 0;
			}
 
			for (i = 0; i < 7; i++)//mountain
			{
				for (j = 0; j < 7; j++)
				{
					for (k = 0; k < 7; k++)
					{
						for (l = 0; l < 7; l++)
						{
							for (m = 0; m < 7; m++)
							{
								if ((input[i].num == 1) && (input[j].num == 10) && (input[k].num == 11) && (input[l].num = 12) && (input[m].num == 13))
								{
									preturn = 6;
									goto end;
								}
							}
						}
					}
				}
			}
			for (i = 0; i < 3; i++)//back straight
			{
				for (j = 0; j < 4; j++)
				{
					for (k = 0; k < 5; k++)
					{
						for (l = 0; l < 6; l++)
						{
							for (m = 0; m < 7; m++)
							{
								if ((input[i].num == 1) && (input[j].num == 2) && (input[k].num == 3) && (input[l].num = 4) && (input[m].num == 5))
								{
									preturn = 5;
									goto end;
								}
							}
						}
					}
				}
			}
			for (i = 0; i < 3; i++)//straight
			{
				for (j = i; j < i + 4; j++)
				{
					if (input[j].num + 1 == input[j + 1].num)
						scount++;
				}
				if (scount >= 5)
				{
					scount = 0;
					preturn = 4;
					goto end;
				}
				scount = 0;
			}
			break;
 
	case 2://flush
		preturn = 7;
		goto end;
		break;
	case 3://'pair's
		for (i = 0; i < 4; i++)//four card
		{
			if (input[i].num == input[i + 1].num == input[i + 2].num == input[i + 3].num)
			{
				preturn = 9;
				goto end;
			}
		}
		for (i = 0; i < 6; i++)//full house
		{
			for (j = 0; j < 5; j++)
			{
				if (input[i].num == input[i + 1].num && input[j].num == input[j + 1].num == input[j + 2].num && i != j)
				{
					preturn = 8;
					goto end;
				}
			}
		}
		for (i = 0; i < 5; i++)//triple
		{
			if (input[i].num == input[i + 1].num == input[i + 2].num)
				preturn = 3;
			goto end;
		}
		for (i = 0; i < 6; i++)//two pair
		{
			for (j = 0; j < 6; j++)
			{
				if (input[i].num == input[i + 1].num && input[j].num == input[j + 1].num && i != j)
				{
					preturn = 2;
					goto end;
				}
			}
		}
		preturn = 1; //one pair
		goto end;
	default:
		preturn = 0; //high
		goto end;
		break;
	}
end:
	scount = 0;
	pcount = 0;
	diamond = 0;
	heart = 0;
	spade = 0;
	clover = 0;
	printf("%d", preturn);
	return preturn;
}
라스코니의 이미지

shape 의 공간은 어디에서 할당받죠?
char shape[1]을 원하시는 거 아닌가요?

gatsby6355의 이미지

특수문자가 2바이트라 나중에 출력할때 문제가 나올까봐 포인터로 만들었습니다.

다른 코드에서 공용으로 쓰는거라 헤더에 넣어놔서 이 코드만 따로 떼놓을 때 전역변수로 만들어 놨는데 거기서부터 문제가 시작된 거였군요..

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.