标题:急求!桥牌发牌程序原码 c语言编写
只看楼主
lily_jing
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2007-12-8
 问题点数:0 回复次数:4 
急求!桥牌发牌程序原码 c语言编写
按照上下左右的方向输出四位牌手得到的牌,按照红桃,黑桃,方片,草叶四个顺序排列,并且所得到的牌按照数字从打到小排序!
谢谢各位高手!
搜索更多相关主题的帖子: 桥牌 c语言 发牌 编写 
2008-01-11 10:28
xianshizhe111
Rank: 1
等 级:新手上路
帖 子:1451
专家分:0
注 册:2007-12-8
得分:0 
暂时还没有!
2008-01-11 10:38
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
得分:0 
I think Microsoft's program for 'cards' has been released/disclosed to the public domain, you may google for it.

I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2008-01-11 11:24
cosdos
Rank: 9Rank: 9Rank: 9
来 自:ShangHai
等 级:蜘蛛侠
威 望:6
帖 子:2109
专家分:1385
注 册:2007-6-19
得分:0 


#include<stdio.h>
#include<stdlib.h>
#include<time.h>

#define MAX 54      // 54 张牌

void Sorting(int ar[], int n);  // 排序
void show(int ar[], int n);     // 显示手中牌


char * Decimal[13] = {"3", "4", "5", "6", "7", "8",
                      "9", "10", "J", "Q", "K", "A", "2"};
char * Fancy[5] = {"红桃", "方块", "黑桃", "梅花", "王  "};
char * Joker[2] = {"Moon", "Sun"};

int main(void)
{
    int i, n, j, temp;
   
    int Solitaire[MAX];        // 牌
   
    int Players_Gba[20];       // 玩家
    int Players_Nds[20];
    int Players_Psp[20];
    int   Gba,   Nds,   Psp;   // 玩家数组下标
   
   
    for(i = 0; i < MAX; i++) // 初始化牌
        Solitaire[i] = i;

    j = MAX;
    Gba = Nds = Psp = 0;
    for(i = 0; i < (MAX - 3); i++)    // 剩余3张做底牌
    {
        n = rand() % j;        // 随机从剩余牌中取牌

        switch(i % 3)   // 指定把牌发给谁,起到轮流发牌的作用
        {
            case 0:
                Players_Gba[Gba++] = Solitaire[n];  // 把第n 张牌发给 Gba
                break;
            case 1:
                Players_Nds[Nds++] = Solitaire[n];  // ........ Nds
                break;
            case 2:
                Players_Psp[Psp++] = Solitaire[n];  // ........ Psp
                break;
        }

        temp = Solitaire[n];     // 把发掉的排和剩余的最后一张牌调换
        Solitaire[n] = Solitaire[j - 1];
        Solitaire[j - 1] = temp;

        j--;                     // 牌的剩余数量 - 1 (牌已发掉)
    }


    Sorting(Players_Gba, Gba);      // 排序
    Sorting(Players_Nds, Nds);
    Sorting(Players_Psp, Psp);

    puts("\n================== 玩家1 ==================");   // 显示
    show(Players_Gba, Gba);
    puts("\n================== 玩家2 ==================");
    show(Players_Nds, Nds);
    puts("\n================== 玩家3 ==================");
    show(Players_Psp, Psp);

    putchar('\n');
    getchar();
    return 0;
}

//-----------------------------------------------


void Sorting(int ar[], int n)
{
    int i, j, temp;

    for(i = 0; i < n - 1; i++)
        for(j = i + 1; j < n; j++)
            if(ar[i] > ar[j])
            {
                temp = ar[i];
                ar[i] = ar[j];
                ar[j] = temp;
            }
}

void show(int ar[], int n)
{
    int i, j = -1, k = -2;
    for(i = 0; i < n; i++)
    {
        j = ar[i] / 13;

        if(j != k)
        {
            printf("\n%4s ", Fancy[j]);
            k = j;
        }

        if(j < 4)
            printf(" %-2s", Decimal[ar[i] % 13]);
        else
            printf(" %s ", Joker[ar[i] % 13]);
    }
    putchar('\n');
}


/******************* 牌值排序 **********************
void show(int ar[], int n)
{
    int i, j;
    putchar('\n');
    for(i = 0; i < n; i++)
    {
        if(ar[i] < 52)
            printf("  %4s%-2s  ", Fancy[ar[i] / 13], Decimal[ar[i] % 13]);
        else
            printf("  %-6s  ", Joker[ar[i] - 52]);

        if(i % 7 == 6)
            putchar('\n');
    }
}

void Sorting(int ar[], int n)
{
    int i, j, temp;

    for(i = 0; i < n - 1; i++)
        for(j = i + 1; j < n; j++)
            if((ar[i] < 52) && (ar[j] < 52))    // 如果2个都不是王
            {
                if((ar[i] % 13) > (ar[j] % 13))
                {
                    temp = ar[i];
                    ar[i] = ar[j];
                    ar[j] = temp;
                }
            }
            else if(ar[i] > ar[j])
            {
                temp = ar[i];
                ar[i] = ar[j];
                ar[j] = temp;
            }
}
*******************************************/


[[italic] 本帖最后由 cosdos 于 2008-1-17 01:45 编辑 [/italic]]

—>〉Sun〈<—
2008-01-17 01:43
cosdos
Rank: 9Rank: 9Rank: 9
来 自:ShangHai
等 级:蜘蛛侠
威 望:6
帖 子:2109
专家分:1385
注 册:2007-6-19
得分:0 
有时间我写个 4 个方向的。

—>〉Sun〈<—
2008-01-17 01:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-196987-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.060362 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved