当前位置:网站首页>C语言实现发牌功能基本方法
C语言实现发牌功能基本方法
2022-07-26 05:07:00 【an520_】
大家好!
今天主要和大家聊一聊,如何利用C语言实现自动发牌程序。
第一:问题描述
一副扑克有52张牌,打桥牌时应将牌分给4个人。请设计一个程序完成自动发牌的工作。要求:黑桃用S (Spaces)表示,红桃用H (Hearts)表示,方块用D (Diamonds)表示,梅花用C (Clubs)表示。
第二:问题分析
思路:
这题实现起来还是比较简单的,只需定义两个多维的字符数组,第一个用来存放扑克的编号,第二个用来存放4个玩家的手牌。
52张牌发给4个人,需要发13轮,每轮按玩家的编号顺序给他们发牌,发牌时,用随机函数生成要发牌的编号(随机函数的介绍可以参考我第61天的练习),如果该牌之前没被发放(已发放的牌用'\0'标记),则将牌的编号存放到玩家的手牌数组中,同时将该牌的编号赋值为'\0'。如果生成的随机数对应的牌已经被发过了,则继续生成新的随机数。当52张牌全部发放完毕,打印发牌的结果。
扑克数组char poker[4][13];中的4表示花色种类有四种,13表示每种有13张(13个编号),扑克牌的编号(名字)用字符表示,分别为:{'2', '3', '4', '5', '6', '7', '8', '9', '0', 'J', 'Q', 'K', 'A'}('0'表示10)
玩家的手牌数组是一个三维字符数组,char players[PLAYER_NUMBER][4][13] = {0}; (PLAYER_NUMBER是玩家数量,4表示牌的花色种类有4种,13为某种花色的牌最多13张)
初始化时,手牌数组的所有值设置为'\0',表示手上无牌。
第三:代码实现




第四:运行结果

总结:只有多练,在练的过程中,找到问题点逐个解决并总结,才能走的更远。
【学习交流群769843038】
【下方分享一些学习教程资料】:
【下方网盘免费资料包,需要的放心领取】:
嵌入式物联网 stm32 c/c++、QT Linux资料包【华清远见发放资料包】
http://makerschool.mikecrm.com/7ADq4jq

边栏推荐
- Add and modify the verification logic, and use -validation- to complete the group verification
- JVM第六讲:线上环境 FGC 频繁,如何解决?
- MySQL基础学习
- AXI协议(5):AXI协议的burst机制
- Excel VBA:按日期汇总计算输出结果(sumif)
- Five simple and practical daily development functions of chrome are explained in detail. Unlock quickly to improve your efficiency!
- [Luogu] p3919 [template] persistent segment tree 1 (persistent array)
- 【ACWing】1268. 简单题
- CountLaunch Demo的测试
- How to connect tdengine through idea database management tool?
猜你喜欢

Switch and router technology: dynamic routing protocol, rip routing protocol and OSPF routing protocol

嵌入式分享合集20

C语言函数

AQS唤醒线程的时候为什么从后向前遍历,我懂了

How many holes have you stepped on in BigDecimal?

Axi protocol (4): signals on the Axi channel

Simulation of future air pollution changes

Learn to map with nature medicine -- complex heat map

新导则下的防洪评价报告编制方法及洪水建模

Seata submits at details in two stages
随机推荐
Excel VBA:将多个工作表保存为新文件
npm操作指令
Five simple and practical daily development functions of chrome are explained in detail. Unlock quickly to improve your efficiency!
[pytorch] install torch 1.8.1 and check whether torch version and GPU are available
CMD操作命令
Google Emoji guessing game helps parents guide their children to surf the Internet safely
The elderly who claim alimony from other children after being supported by their widowed daughter-in-law should be supported
Annotation @autowired how to assemble automatically
图像非局部均值滤波的原理
Switch to router technology: OSPF single zone configuration, OSPF multi zone and end zone
阿里云工业视觉智能工程师ACP认证——备考
测试必备工具之Fiddler,你真的了解吗?
Redis解决库存超卖问题
35. 搜索插入位置
Ansible tutorial
Interprocess communication
SAP报表开发步骤
webassembly 01基本资料
Molecular skeleton transition tool -delinker introduction
奥特学园ROS笔记--6