22019, 1/1101 ȸ¿ø°¡ÀÔ  ·Î±×ÀΠ 
   kjh00114
   c¾ð¾î¸¦ ÀÌ¿ëÇÑ È­Åõ°ÔÀÓ (¼¸´Ù)

http://www.hackerschool.org/HS_Boards/zboard.php?id=Free_Board&no=13055 [º¹»ç]


#include <stdio.h>  
#include <stdlib.h>  
#include <time.h>  
#include <conio.h>  
#include <string.h>  
  
void Register(char*, int*);  
void DisplayFrame(char*, int, int,int, int, int, int, int*, int*, int);  
void Shuffle(int*);  
void SetOrder(int**, int*, int*, int);  
void CompareTable(int*, int*);  
bool betting(int*, int*,int*);  
  
  
enum {PLAYER, COMPUTER};  
  
void main()  
{  
    // User information.  
    char name[20];  
    int age;  
  
    // Game information.  
    char askContinue;  
    int cntGame = 0;  
    int bettingAmount;  
    int firstGetter = PLAYER;   // 0 - player, 1 - computer.  
    int shuffledCards[20];  
    int* order[2];  
  
    // Com. information.  
    int comMoney;  
    int comBetting = 0;  
    int comCards[2] = {0};  
    int comResult;  
    char comResultName[20];  
  
    // Player information.  
    int playerMoney;  
    int playerBetting = 0;  
    int playerCards[2] = {0};  
    int playerResult;  
    char playerResultName[20];  
  
    // Game setting.  
    int defaultMoney = 1000;  
  
    playerMoney = comMoney = defaultMoney;  
    srand(time(NULL));  
  
    // User Register.  
    Register(name, &age);      
  
    while(1)  
    {      
        // Initialize.  
        cntGame++;  
        bettingAmount = 0;  
  
        comCards[0] = 0;  
        comCards[1] = 0;  
        playerCards[0] = 0;  
        playerCards[1] = 0;  
  
        // Shuffle all card.  
        Shuffle(shuffledCards);    
  
        // Decide first turn.  
        SetOrder(order, playerCards, comCards, firstGetter);  
  
        // Show default information.  
        DisplayFrame(name, age, cntGame, firstGetter, bettingAmount, comMoney, playerMoney, comCards, playerCards, 0);  
  
        // Loop for dealing and betting.  
        bool die = false;  
        for(int i=0; i<4; i++)  
        {  
            // Dealing.  
            *(order[i%2]+i/2) = shuffledCards[i];  
  
            if(i%2==1)  
            {                  
                printf("Ä«µå¸¦ ¹ÞÀ¸½Ã·Á¸é ¾Æ¹«Å°³ª ´©¸£¼¼¿ä.\n");  
                getch();  
  
                // Show dealing information.  
                DisplayFrame(name, age, cntGame, firstGetter, bettingAmount, comMoney, playerMoney, comCards, playerCards, 0);  
  
                if(!betting(&comMoney, &playerMoney, &bettingAmount))  
                {  
                    die = true;  
                    break;  
                }                  
            }  
        }  
  
        if(die)  
        {  
            printf("ComputerÀÇ ½Â¸®ÀÔ´Ï´Ù.%d %d\n", comResult, playerResult);  
            comMoney += bettingAmount*2;  
            firstGetter = COMPUTER; // Set first getter to computer.  
  
            continue;  
        }  
  
        // Show final stats.          
        DisplayFrame(name, age, cntGame, firstGetter, bettingAmount, comMoney, playerMoney, comCards, playerCards, 1);  
  
        printf("½ÂÆÐ¸¦ È®ÀÎÇϽ÷Á¸é ¾Æ¹«Å°³ª ´­·¯ÁÖ¼¼¿ä.\n");  
        getch();  
  
        // Show result.  
        DisplayFrame(name, age, cntGame, firstGetter, bettingAmount, comMoney, playerMoney, comCards, playerCards, 1);  
  
        // Compare to point table and get the point.  
        CompareTable(comCards, &comResult);  
        CompareTable(playerCards, &playerResult);  
  
        // Decide winner.  
        if(comResult>playerResult)  
        {  
            printf("ComputerÀÇ ½Â¸®ÀÔ´Ï´Ù.%d %d\n", comResult, playerResult);  
            comMoney += bettingAmount*2;  
            firstGetter = COMPUTER; // Set first getter to computer.  
              
        }  
        else if(comResult<playerResult)  
        {  
            printf("PlayerÀÇ ½Â¸®ÀÔ´Ï´Ù.%d %d\n", comResult, playerResult);  
            playerMoney += bettingAmount*2;  
            firstGetter = PLAYER;   // Set first getter to player.  
        }  
        else  
        {  
            printf("¹«½ÂºÎÀÔ´Ï´Ù.%d %d\n", comResult, playerResult);  
            playerMoney += bettingAmount;  
            comMoney += bettingAmount;  
        }  
  
        // Notify Ending of the game.  
        if(comMoney<=0)  
        {  
            printf("Computer°¡ °ÅÁö°¡ µÇ¾î ´õ ÀÌ»ó °ÔÀÓÀ» ÇÒ ¼ö°¡ ¾ø½À´Ï´Ù. ´Ù½Ã ½ÇÇàÇØ ÁÖ¼¼¿ä.\n");  
            break;  
        }  
  
        if(playerMoney<=0)  
        {  
            printf("Player°¡ °ÅÁö°¡ µÇ¾î ´õ ÀÌ»ó °ÔÀÓÀ» ÇÒ ¼ö°¡ ¾ø½À´Ï´Ù. ´Ù½Ã ½ÇÇàÇØ ÁÖ¼¼¿ä.\n");  
            break;  
        }  
  
        // Ask continuation.  
        fflush(stdin);  
        printf("°è¼ÓÇϽðڽÀ´Ï±î?(y/n): ");  
        scanf("%c", &askContinue);  
  
        if(askContinue=='n')  
            break;        
    }  
}  
  
void Register(char* name, int* age)  
{  
    printf("¼¸´ÙÀÔ´Ï´Ù. ¾î¼­¿À¼¼¿ä.\n");  
    printf("À̸§À» ÀÔ·ÂÇØÁÖ¼¼¿ä: ");  
    scanf("%s", name);  
    printf("³ªÀ̸¦ ÀÔ·ÂÇØÁÖ¼¼¿ä: ");  
    scanf("%d", age);  
}  
  
void DisplayFrame(char* name, int age, int cntGame, int firstGetter, int bettingAmount, int comMoney, int playerMoney, int* comCards, int* playerCards, int open)  
{  
    char strFirst[10];    
  
    if(firstGetter==PLAYER)  
        strcpy(strFirst, "Player");  
    else if(firstGetter==COMPUTER)  
        strcpy(strFirst, "Computer");  
  
    system("cls");  
    printf("                                                         À̸§: %s ³ªÀÌ: %d ¼¼\n", name, age);  
    printf(" [ %d ] ¹øÂ° °ÔÀÓ (¼±): %s, ¹èÆÃ±Ý¾×: %d¿ø, Computer: %d ¿ø, Player %d ¿ø\n", cntGame, strFirst, bettingAmount*2, comMoney, playerMoney);  
  
    if(comCards[0]!=0 && comCards[1]==0)  
    {  
        printf("%15s %15s\n", "Computer Ä«µå", "Player Ä«µå");  
        printf("#######              #######\n");  
        printf("#     #              #     #\n");  
  
        if(open==1)  
            printf("# %3d #              # %3d #\n", comCards[0], playerCards[0]);  
        else  
            printf("#  *  #              # %3d #\n", playerCards[0]);  
  
        printf("#     #              #     #\n");  
        printf("#######              #######\n");  
    }else if(comCards[0]!=0 && comCards[1]!=0)  
    {  
        printf("%15s %15s\n", "Computer Ä«µå", "Player Ä«µå");  
        printf("####### #######      ####### #######\n");  
        printf("#     # #     #      #     # #     #\n");  
  
        if(open==1)  
            printf("# %3d # # %3d #      # %3d # # %3d #\n", comCards[0], comCards[1], playerCards[0], playerCards[1]);  
        else  
            printf("#  *  # #  *  #      # %3d # # %3d #\n", playerCards[0], playerCards[1]);  
  
        printf("#     # #     #      #     # #     #\n");  
        printf("####### #######      ####### #######\n");  
    }  
}  
  
void Shuffle(int* shuffledCards)  
{  
    printf("Ä«µå¸¦ ¼¯½À´Ï´Ù...\n");      
    bool swCards[20] = {0};  
  
    int i=0;  
    int r;  
  
    while(i<20)  
    {  
        r = rand()%20;  
          
        if(swCards[r] == false)  
        {  
            swCards[r] = true;  
            shuffledCards[i] = r>9 ? r-10+1: r+1;  
            i++;  
        }  
    }  
}  
  
void SetOrder(int* order[], int* playerCards, int* comCards, int player)  
{  
    if(player==0)  
    {  
        order[0] = playerCards;  
        order[1] = comCards;  
    }else if(player==1)  
    {  
        order[0] = comCards;  
        order[1] = playerCards;  
    }      
}  
  
void CompareTable(int* cards, int* result)  
{  
    int table[][3] = {  
        {3, 8, 26},  
        {8, 3, 26},  
  
        {10, 10, 25},  
        {9, 9, 24},  
        {8, 8, 23},  
        {7, 7, 22},    
        {6, 6, 21},  
        {5, 5, 20},  
        {4, 4, 19},  
        {3, 3, 18},  
        {2, 2, 17},  
        {1, 1, 16},  
  
        {1, 2, 15},  
        {2, 1, 15},            
        {1, 4, 14},  
        {4, 1, 14},        
        {1, 9, 13},  
        {9, 1, 13},  
        {1, 10, 12},  
        {10, 1, 12},  
        {4, 10, 11},  
        {10, 4, 11},          
        {4, 6, 10},  
        {6, 4, 10}  
    };  
  
    int plag = 0;  
      
    for(int j=0; j<22; j++)  
    {              
        if(cards[0]==table[j][0] && cards[1]==table[j][1])  
        {  
            *result = table[j][2];            
            plag = 1;  
            break;  
        }          
    }  
  
    if(plag==0)    
        *result = (cards[0]+cards[1])%10;  
          
          
}  
  
bool betting(int* comMoney, int* playerMoney, int* bettingAmount)  
{  
    int bet;  
  
    printf("¹èÆÃ ±Ý¾×À» ÀÔ·ÂÇϼ¼¿ä(-1:Die, 0~%d): ", *playerMoney);  
    scanf("%d", &bet);  
  
    // For die.  
    if(bet==-1)  
        return false;      
  
    // For all-in.  
    if(bet>*playerMoney)  
        bet = *playerMoney;  
    else if(bet>*comMoney)  
        bet = *comMoney;  
  
    // Betting.  
    *bettingAmount += bet;                
  
    *comMoney -= bet;  
    *playerMoney -= bet;  
  
    return true;  
}  

  Hit : 11927     Date : 2009/06/28 04:23



    
syh4209 ¿À·ù 118°³.... 2009/06/29  
thdtjq22 ¤»¤» Àú´Â À߸¸µÇ´Âµ¥ 2009/06/30  
crashgun Çѹø ÄÄÆÄÀÏ ÇØ¼­ ÇØº¸°í ½Í³×¿©.. ¤»¤» 2009/07/02  
yjkk80 ÄÄÆÄÀÏ ¿À·ù 59°³ ¶ß´Âµ¥¿ä 2009/07/09  
Slayer-1 Àúµµ ¿À·ù°¡ ¼´Âµ¥..¤»¤» 36°³ ¿ö´× 3°³ ¤»¤» 2009/07/09  
     [°øÁö]ÇØÄ¿½ºÄð ÀÌ¿ë¼öÄ¢ 2021/04/11 ¼öÁ¤ÆÇ [54] ÇѽÂÀç 01/05 11634
22018   À¸¾Ó!!![1]     ÇØÅ·ÀßÇϰí½Í´Ù
02/05 59
22017   A¤¿...     ÇØÅ·ÀßÇϰí½Í´Ù
01/27 94
22016   ¿À·£¸¸~     DarkSlayer
12/11 291
22015   ÇØÄ¿½ºÄð ¿¾³¯ BGM[1]     wkfhddl4041
11/07 426
22014   È÷À×...     ÇØÅ·ÀßÇϰí½Í´Ù
11/02 343
22013   ¹ÙµÏ°ú Àå±â     ÇØÅ·ÀßÇϰí½Í´Ù
10/30 378
22012   ³ª´Â ¾ðÁ¦ ¾ÖÀÎÀÌ »ý±â³ª¿è...     ÇØÅ·ÀßÇϰí½Í´Ù
10/27 436
22011   Àü±¹ 1À§     ÇØÅ·ÀßÇϰí½Í´Ù
10/27 388
22010   ´ã¹è ¤»¤»[1]     ÇØÅ·ÀßÇϰí½Í´Ù
10/27 391
22009   ¸ÅÆ®¸¯½ºÀÇ ÆÄ¶õ¾àÀ» ¾Æ½Ê´Ï±î..?     ÇØÅ·ÀßÇϰí½Í´Ù
10/27 372
22008   ¤·¤·[1]     ÇØÅ·ÀßÇϰí½Í´Ù
10/20 365
22007   ¿ÉÄ¡ ÇÙ°¨Áö ÇÁ·Î±×·¥Á» ¸¸µé¾îÁÖ¼¼¿ä[1]     powerima
10/15 368
22006   ÇØÅ·ÆÀ¿ø ¸ðÁý[1]     koromoon
08/27 893
22005   °°ÀÌ ÇØÅ· ÆÀ ÀÌ·ç½ÇºÐ??     hacs98
08/26 579
22004   ¾Æ........ ¤Ð¤Ð     ÇØÅ·ÀßÇϰí½Í´Ù
08/04 748
22003   ±Í¼ö(Сâ¢) µû¶óÇϱâ(?)     ÇØÅ·ÀßÇϰí½Í´Ù
07/28 727
22002   ½º½º·Î ¸ñ¼ûÀ» Á®¹ö¸°´Ù´Â °ÍÀº     ÇØÅ·ÀßÇϰí½Í´Ù
07/27 762
22001   ¹ÌÄ£µí     ÇØÅ·ÀßÇϰí½Í´Ù
07/02 808
22000   »ç¹«½Ç     ÇØÅ·ÀßÇϰí½Í´Ù
07/02 746
1 [2][3][4][5][6][7][8][9][10]..[1101]

Copyright 1999-2026 Zeroboard / skin by Hackerschool.org / Secure Patch by Hackerschool.org