#include <stdio.h>
void thinking(int *);
void decision(int *, int*, int *, int*);
int main(void)
{
int n, strike, ball, computer[4], gameuser[4];
printf("*----------------------------------------------*\n");
printf(" ¾ß±¸°ÔÀÓ \n");
printf("*----------------------------------------------*\n");
printf(" 1) ÄÄÇ»ÅÍ°¡ 4°³ÀÇ ÇÑÀÚ¸® ¼ö¸¦ »ý°¢ÇÕ´Ï´Ù.\n");
printf(" 2) »ç¿ëÀÚ°¡ 4°³ÀÇ ¼ýÀÚ¸¦ ÀÔ·ÂÇÕ´Ï´Ù. \n");
printf(" 3) ¼ýÀÚ°¡ °°°í À§Ä¡°¡ °°À¸¸é ½ºÆ®¶óÀÌÅ©ÀÔ´Ï´Ù.\n");
printf(" 4) ¼ýÀÚ°¡ °°À¸³ª À§Ä¡°¡ ´Ù¸£¸é º¼ÀÔ´Ï´Ù.\n");
printf(" *) ¼ýÀÚ´Â ¶ç¾î¼ ÀÔ·ÂÇϼ¼¿ä. (¿¹: 1 4 5 7) \n");
printf("*----------------------------------------------*\n");
srand(time(NULL));
while (1) {
printf("»õ °ÔÀÓÀÔ´Ï´Ù \n");
thinking(computer);
for (n = 1;; n++) {
printf("(%d)> ", n);
scanf("%d %d %d %d", &gameuser[0], &gameuser[1], &gameuser[2], &gameuser[3]);
strike = ball = 0;
decision(computer, gameuser, &strike, &ball);
if (strike == 4) {
printf("ÃàÇÏÇÕ´Ï´Ù. %d step ¸¸¿¡ ¸ÂÃß¾ú½À´Ï´Ù !!! \n", n);
break;
}
else
printf("\t\t(%d ½ºÆ®¶óÀÌÅ© %d º¼)\n", strike, ball);
}
}
}
int num_one(int comp[])
{
int i, count=0;
for (i = 0; i < 10; i++) {
if (comp[i] == 1) count++;
}
return count;
}
void thinking(int computer[])
{
int i, j, n, num;
int comp[10] = { 0 };
do {
num = rand() % 10;
comp[num] = 1;
n = num_one(comp);
if (n == 4) break;
} while (1);
for (i = 0, j = 0; i < 10; i++) {
if (comp[i] == 1)
computer[j++] = i;
}
for (i = 0, j = 0; i < 10; i++) {
int tmp;
j = rand() % 3 + 1;
tmp = computer[j];
computer[j] = computer[0];
computer[0] = tmp;
}
}
void decision(int computer[], int gameuser[], int *strike, int *ball) {
int i, j;
for (i = 0; i < 4; i++) {
if (gameuser[i] == computer[i]) (*strike)++;
else {
for (j = 0; j < 4; j++) {
if (gameuser[i] == computer[j]) (*ball)++;
}
}
}
}