当前位置:网站首页>【golang从入门到实践】扑克发牌游戏
【golang从入门到实践】扑克发牌游戏
2022-07-19 19:54:00 【会振刀的程序员】
功能介绍
扑克牌发牌实现
效果展示
编程思路
1、罗列所有的花色和牌面大小,交叉相乘 =52张牌;52 +大、小王 = 54 张牌
2、逐个给每个人发牌,直至17张。每次从总牌中随机挑选1张,发给玩家并从总牌中删除
3、三人各17张发完之后,从3人中随机挑选一个人为地主,并将最后3张牌发给他
源代码
package main
import (
"fmt"
"math/rand"
"time"
)
var color = []string{
"", "", "", ""}
var size = []string{
"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}
var total []string
var fapai = [][]string{
{
}, {
}, {
}}
func main() {
// 生成54张牌
for _, v := range color {
for _, v2 := range size {
total = append(total, v+v2)
}
}
total = append(total, "大王")
total = append(total, "小王")
for index, _ := range fapai {
for i := 0; i < 17; i++ {
rand.Seed(time.Now().Unix())
intt := rand.Intn(len(total))
fapai[index] = append(fapai[index], total[intt])
total = append(total[:intt], total[intt+1:]...)
}
}
boss := rand.Intn(2)
fapai[boss] = append(fapai[boss], total...)
for k, v := range fapai {
fmt.Println("玩家", k, "牌:", v, "长度", len(v))
}
}
边栏推荐
- 2022杭电多校联赛第一场 题解
- How to make a reliable delay queue with redis (classic collection version)
- Code source du système vidéo court, séquence de chargement des fichiers principaux dans le projet uni app
- 综述 | 图像去噪综合比较研究
- 枚举 联合
- ICML2022 | XAI for Transformers:通过保守传播更好的解释
- What is dbc2000? Dbc2000 database file details
- 数据库设计流程
- 01-创建项目仓库
- The R language uses the gghistogram function of ggpubr package to visualize the grouping box diagram, add the grouping mean value, customize the grouping color, add the axial whisker diagram (rug), ad
猜你喜欢
Link list of daily Niuke questions
Web3的企业如何用Token激励员工?
[development tutorial 3] open source Bluetooth heart rate waterproof sports Bracelet - development environment construction
YOLOv3-SPP-ultralytics 模型简述
对Coinbase中长期前景的冷静评估
NFT access tool premint was hacked, with a loss of more than 370000 US dollars
Skywalking全链路监控集群和动态部署
robotframework实战(三)衍生——以百度搜索功能为例编写测试用例
ECCV 2022 | 旷视提出半监督目标检测模型Dense Teacher,取得SOTA性能
ThreadLocal夺命11连问
随机推荐
R语言使用ggpubr包的gghistogram函数可视化分组箱图、添加分组均值、自定义分组色彩、添加轴须图(rug)、添加密度曲线、添加双y轴分别表示频率以及密度曲线的密度值
LVGL 8.2 Textarea
Given the preorder traversal and the inorder traversal order of a binary tree, find the postorder traversal of the tree
现在科技发展背后所呈现出来的是,元宇宙时代的来临
Code source du système vidéo court, séquence de chargement des fichiers principaux dans le projet uni app
Link list of daily Niuke questions
php 百度有钱花分期API
How to quickly get started with find and xargs commands
Alternative interpretation of the macro situation: the Federal Reserve may soon end the process of raising interest rates and return to quantitative easing?
DBC2000是什么?DBC2000数据库文件详解
深挖数据红利,英特尔与产业加速数字经济落地
Arrays. Sort() custom comparison function
MySQL basic learning day06
Embedded sharing collection 16
Communication overhead: a key factor limiting the size of rediscluster
Project knowledge points
项目知识点
SAP mm transaction code Migo mobile type 561 error after saving -document number was already assigned
NFT access tool premint was hacked, with a loss of more than 370000 US dollars
Redis high availability: you call this sentinel sentinel cluster principle