一个c++写的发牌程序

来源:网络整理 责任编辑:栏目编辑 发表时间:2013-07-01 16:53 点击:

 【简 介】  可以显示一、二、三、四家的牌,主要是为了训练我的牌感(记牌的能力),对有志于赌博或者桥牌事业的同志可能还有点用,编译为bd.exe,使用方法输入"bd -h"看帮助。

   可以显示一、二、三、四家的牌,主要是为了训练我的牌感(记牌的能力),对有志于赌博或者桥牌事业的同志可能还有点用,编译为bd.exe,使用方法输入"bd -h"看帮助。

  以下是源代码(处理命令行参数的代码参考了vim):

#include
#include
#include
#include
using namespace std;

#include
#include
#include

static char program_name[]="bd";
#define THE_VERSION "0.1"

namespace info{
enum { WEST=0,NORTH=1,EAST=2,SOUTH=3,};
};
static char* deno[]={"Spade","Heart","Diamond","Cotton",};
static char card_symbol[]="23456789TJQKA";

// p - pointer to argument
// idx - index in argument
// default value
static int
get_number_arg(char* p,int def)
{
if (isdigit(*p))
{
def = atoi(p);
}
return def;
}

static void
print_help()
{
cout<<"Usage: "<<<" [OPTION]..."<
cout<<"Bridge Dealer"<
cout<<"Example: "<<<" -p4"<
cout<
cout<<" -p number of players, value ranges from 1 to 4"<
cout<<" \""<<<"\" with NO option equals \""<<<" -p1\" "<
cout<<" -n number of deals, default \"1\""<
cout<<" -v,--version print version information and exit"<
cout<<" -h,--help display this help and exit"<
cout<
exit(0);
}

static void
print_version()
{
cout<<<" version "<<
exit(0);
}

static void
dump_one_hand(vector::iterator ori,int sps=0)
{
vector::iterator iter=ori;
for(int i=0;i
{
for(int j=0;j<<" ";
cout<<<": ";
for(;(iter!=ori+13) && (*iter)/13==i;iter++)
{
cout<<<" ";
}
cout<
}
}


static void
dump_two_hands(vector::iterator o1, vector::iterator o2,int sps=0)
{
vector::iterator iter1=o1;
vector::iterator iter2=o2;
int j;
int cnt;
for(int i=0;i
{
cout<<<": ";
cnt=2;
for(;(iter1!=o1+13) && (*iter1)/13==i;iter1++)
{
cout<<<" ";
cnt=cnt+2;
}

for(j=0;j<<" ";
cout<<<": ";
for(;(iter2!=o2+13) && (*iter2)/13==i;iter2++)
{
cout<<<" ";
}
cout<
}
}
//error message routines---------------begin
static char* bs_errors[]=
{
"Unknown option",
#define BS_UNKNOWN_OPTION 0
"Too many arguments",
#define BS_TOO_MANY_ARGS 1
"Argument missing after",
#define BS_ARG_MISSING 2
"Garbage after option",
#define BS_GARBAGE 3
"Too many extra commands",
#define BS_EXTRA_CMD 4
"Invalid argument for",
#define BS_INVALID_ARG 5
};
//error message routines---------------end

int
main(int argc, char** argv)
{
int argv_idx = 1; /* active option letter is argv[0][argv_idx] */
int players=1;
int number_of_deals=1;
bool want_argument=false;

while(argc>0)
{
if(argv[0][0]=='-')
{
char c=argv[0][argv_idx++];
switch(c)
{
case 0:
//do nothing
argv_idx=-1;
break;
case '-': // "--" don't take any more options
if(strcmp(argv[0]+argv_idx,"version")==0){
print_version();
}
else if(strcmp(argv[0]+argv_idx,"help")==0){
print_help();
}
argv_idx=-1;
break;
case 'h':
print_help();
break;
case 'v':
print_version();
break;
case 'p': // 1,2,3,4 players, default 1
if (argv[0][argv_idx]){ // "-p{tag}"
players=get_number_arg(argv[0]+argv_idx,1);
argv_idx=-1;
}
else{ // "-p {tag}"
want_argument=true;
}
break;
case 'n': //number of deals, default 1
if (argv[0][argv_idx]){ // "-n{tag}"
number_of_deals=get_number_arg(argv[0]+argv_idx,1);
if(number_of_deals<=0) number_of_deals=1;
argv_id

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • 浅析.NET下XML数据访问新机制
    • asp.net 面试+笔试题目第1/2页
    • C# 邮件地址是否合法的验证
    • C#高级编程:数据库连接[1]
    • asp.net 设置GridView的选中行的实现代码
    • 经典C++程序1
    • IIS 自动回收导致后台定时器失效的问题解决
    • ASP.NET&#160;GridView列表代码示例
    • 微软ASP.NET站点部署指南(3):使用Web.Config文件的Transforma
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1